From: Lars-Peter Clausen Date: Fri, 29 Apr 2016 11:36:05 +0000 (+0200) Subject: Introduce standard cleanup helper X-Git-Tag: libsigrok-0.5.0~466 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=700d6b64d578ce10e57f6a2289e37a5564eccf1c;p=libsigrok.git Introduce standard cleanup helper std_init() allocates a drv_context struct which needs to be freed by the driver in its cleanup struct. But the vast majority of drivers does never does this causing memory leaks. Instead of addressing the issue by manually adding code to free the struct to each driver introduce a new helper function std_cleanup() that takes care of this. In addition to freeing the drv_context struct std_cleanup() also invokes sr_dev_clear() which takes care of freeing all devices attached to the driver. Combining both operations in the same helper function allows to use std_cleanup() as the cleanup callback for all existing drivers, which reduces the amount of boiler-plate code quite a bit. All drivers are updated to use the new helper function. Signed-off-by: Lars-Peter Clausen --- diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 7ca471c3..d2a11cc7 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -166,11 +166,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -254,7 +249,7 @@ SR_PRIV struct sr_dev_driver agdmm_driver_info = { .longname = "Agilent U12xx series DMMs", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index 87f5ea49..27b4399a 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -126,11 +126,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -264,7 +259,7 @@ SR_PRIV struct sr_dev_driver appa_55ii_driver_info = { .longname = "APPA 55II", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c index 3686b348..960c2243 100644 --- a/src/hardware/arachnid-labs-re-load-pro/api.c +++ b/src/hardware/arachnid-labs-re-load-pro/api.c @@ -174,11 +174,6 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear(di, NULL); } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -385,7 +380,7 @@ SR_PRIV struct sr_dev_driver arachnid_labs_re_load_pro_driver_info = { .longname = "Arachnid Labs Re:load Pro", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 506b6f65..25b5cad3 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -188,11 +188,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -425,7 +420,7 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info = { .longname = "ASIX SIGMA/SIGMA2", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 734d78b9..ce0531c9 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -204,11 +204,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -507,7 +502,7 @@ SR_PRIV struct sr_dev_driver atten_pps3203_driver_info = { .longname = "Atten PPS3203T-3S", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan_3203, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index c886bfcc..23c75d84 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -170,13 +170,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - dev_clear(di); - - return SR_OK; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) @@ -422,7 +415,7 @@ SR_PRIV struct sr_dev_driver baylibre_acme_driver_info = { .longname = "BayLibre ACME (Another Cute Measurement Equipment)", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index e729d4e2..2285c193 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -200,11 +200,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -383,7 +378,7 @@ SR_PRIV struct sr_dev_driver beaglelogic_driver_info = { .longname = "BeagleLogic", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index ea7866bd..8b6f5ee3 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -172,11 +172,6 @@ static int dev_close(struct sr_dev_inst *sdi) return ret; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -284,7 +279,7 @@ SR_PRIV struct sr_dev_driver brymen_bm86x_driver_info = { .longname = "Brymen BM86X", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 1dcf205c..9868cdf1 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -136,11 +136,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -233,7 +228,7 @@ SR_PRIV struct sr_dev_driver brymen_bm857_driver_info = { .longname = "Brymen BM857", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 11f80045..59137d6d 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -141,11 +141,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -402,7 +397,7 @@ SR_PRIV struct sr_dev_driver cem_dt_885x_driver_info = { .longname = "CEM DT-885x", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index d4451cbe..0e63122a 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -144,11 +144,6 @@ static GSList *dev_list(int idx) return ((struct drv_context *)(center_devs[idx].di->context))->instances; } -static int cleanup(int idx) -{ - return dev_clear(idx); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -236,9 +231,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) #define HW_INIT(X) \ static int init_##X(struct sr_dev_driver *d, \ struct sr_context *sr_ctx) { (void)d; return init(sr_ctx, X); } -#define HW_CLEANUP(X) \ -static int cleanup_##X(const struct sr_dev_driver *d) { \ - (void)d; return cleanup(X); } #define HW_SCAN(X) \ static GSList *scan_##X(struct sr_dev_driver *d, GSList *options) { \ (void)d; return scan(options, X); } @@ -255,7 +247,6 @@ static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi \ /* Driver structs and API function wrappers */ #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ HW_INIT(ID_UPPER) \ -HW_CLEANUP(ID_UPPER) \ HW_SCAN(ID_UPPER) \ HW_DEV_LIST(ID_UPPER) \ HW_DEV_CLEAR(ID_UPPER) \ @@ -265,7 +256,7 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \ .longname = LONGNAME, \ .api_version = 1, \ .init = init_##ID_UPPER, \ - .cleanup = cleanup_##ID_UPPER, \ + .cleanup = std_cleanup, \ .scan = scan_##ID_UPPER, \ .dev_list = dev_list_##ID_UPPER, \ .dev_clear = dev_clear_##ID_UPPER, \ diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 040a9c4b..bd922d05 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -323,11 +323,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -588,7 +583,7 @@ SR_PRIV struct sr_dev_driver chronovu_la_driver_info = { .longname = "ChronoVu LA8/LA16", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index ca75d33e..4a0b61e5 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -101,11 +101,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -186,7 +181,7 @@ SR_PRIV struct sr_dev_driver colead_slm_driver_info = { .longname = "Colead SLM", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index 3fc2cb7d..0195f480 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -111,11 +111,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -203,7 +198,7 @@ SR_PRIV struct sr_dev_driver conrad_digi_35_cpu_driver_info = { .longname = "Conrad DIGI 35 CPU", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index e9cbd768..15a4c60d 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -394,11 +394,6 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear(di, clear_helper); } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -894,7 +889,7 @@ SR_PRIV struct sr_dev_driver demo_driver_info = { .longname = "Demo driver and pattern generator", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/deree-de5000/api.c b/src/hardware/deree-de5000/api.c index 8619ccfb..8c24eb18 100644 --- a/src/hardware/deree-de5000/api.c +++ b/src/hardware/deree-de5000/api.c @@ -54,11 +54,6 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear(di, es51919_serial_clean); } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; @@ -76,7 +71,7 @@ SR_PRIV struct sr_dev_driver deree_de5000_driver_info = { .longname = "DER EE DE-5000", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 765a26a9..dc55aa41 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -194,11 +194,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -289,7 +284,7 @@ SR_PRIV struct sr_dev_driver flukedmm_driver_info = { .longname = "Fluke 18x/28x series DMMs", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 14427985..547e25e4 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -348,15 +348,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - dev_clear(di); - - /* TODO: Free other driver resources, if any. */ - - return SR_OK; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -506,7 +497,7 @@ SR_PRIV struct sr_dev_driver ftdi_la_driver_info = { .longname = "FTDI LA", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 90d28507..fcc98fa9 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -509,21 +509,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - return SR_OK; - - ret = std_dev_clear(di, NULL); - - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -912,7 +897,7 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = { .longname = "fx2lafw (generic driver for FX2 based LAs)", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 28927fc5..b8f71c2f 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -374,11 +374,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -529,7 +524,7 @@ SR_PRIV struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = { .longname = "Gossen Metrawatt Metrahit 1x/2x, RS232 interface", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan_1x_2x_rs232, .dev_list = dev_list, .dev_clear = NULL, @@ -548,7 +543,7 @@ SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info = { .longname = "Gossen Metrawatt Metrahit 2x, BD232/SI232-II interface", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan_2x_bd232, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index e2d28f3f..2b93f10f 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -135,13 +135,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - dev_clear(di); - - return SR_OK; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -262,7 +255,7 @@ SR_PRIV struct sr_dev_driver gwinstek_gds_800_driver_info = { .longname = "GW Instek GDS-800 series", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index a9bcca8c..2ea5ca79 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -166,13 +166,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - dev_clear(di); - - return SR_OK; -} - static int check_channel_group(struct dev_context *devc, const struct sr_channel_group *cg) { @@ -790,7 +783,7 @@ SR_PRIV struct sr_dev_driver hameg_hmo_driver_info = { .longname = "Hameg HMO", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index bdc10af4..4d153834 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -328,11 +328,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -824,7 +819,7 @@ SR_PRIV struct sr_dev_driver hantek_6xxx_driver_info = { .longname = "Hantek 6xxx", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index b88a902b..10e51939 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -418,11 +418,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -1015,7 +1010,7 @@ SR_PRIV struct sr_dev_driver hantek_dso_driver_info = { .longname = "Hantek DSO", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index b152be92..19188e39 100644 --- a/src/hardware/hp-3457a/api.c +++ b/src/hardware/hp-3457a/api.c @@ -244,11 +244,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -462,7 +457,7 @@ SR_PRIV struct sr_dev_driver hp_3457a_driver_info = { .longname = "HP 3457A", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index fecd593c..55b9922b 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -311,18 +311,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - struct drv_context *drvc = di->context; - int ret; - - ret = dev_clear(di); - - g_free(drvc); - - return ret; -} - static int find_in_array(GVariant *data, const GVariantType *type, const void *arr, int n) { @@ -741,7 +729,7 @@ SR_PRIV struct sr_dev_driver hung_chang_dso_2100_driver_info = { .longname = "Hung-Chang DSO-2100", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index f7480db3..a9d3fcb7 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -281,11 +281,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -489,7 +484,7 @@ SR_PRIV struct sr_dev_driver ikalogic_scanalogic2_driver_info = { .longname = "IKALOGIC Scanalogic-2", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index ec649d41..2bdf28d9 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -261,11 +261,6 @@ static int dev_close(struct sr_dev_inst *sdi) return ret; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -398,7 +393,7 @@ SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info = { .longname = "IKALOGIC ScanaPLUS", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 1214fadb..d30f1604 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -227,21 +227,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - /* Can get called on an unused driver, doesn't matter. */ - return SR_OK; - - ret = std_dev_clear(di, NULL); - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -550,7 +535,7 @@ SR_PRIV struct sr_dev_driver kecheng_kc_330b_driver_info = { .longname = "Kecheng KC-330B", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/kern-scale/api.c b/src/hardware/kern-scale/api.c index 6a035158..3ab8857b 100644 --- a/src/hardware/kern-scale/api.c +++ b/src/hardware/kern-scale/api.c @@ -129,11 +129,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -225,7 +220,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) .longname = VENDOR " " MODEL, \ .api_version = 1, \ .init = init, \ - .cleanup = cleanup, \ + .cleanup = std_cleanup, \ .scan = scan, \ .dev_list = dev_list, \ .dev_clear = dev_clear, \ diff --git a/src/hardware/korad-kaxxxxp/api.c b/src/hardware/korad-kaxxxxp/api.c index 5aa5b217..f5c63f9f 100644 --- a/src/hardware/korad-kaxxxxp/api.c +++ b/src/hardware/korad-kaxxxxp/api.c @@ -188,12 +188,6 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear(di, NULL); } -static int cleanup(const struct sr_dev_driver *di) -{ - dev_clear(di); - return SR_OK; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -419,7 +413,7 @@ SR_PRIV struct sr_dev_driver korad_kaxxxxp_driver_info = { .longname = "Korad KAxxxxP", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index d2ed3033..62441720 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -144,21 +144,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - /* Can get called on an unused driver, doesn't matter. */ - return SR_OK; - - ret = std_dev_clear(di, NULL); - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -470,7 +455,7 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = { .longname = "Lascar EL-USB", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index b6eff9dd..06f9b503 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -380,20 +380,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - struct drv_context *drvc; - int ret; - - drvc = di->context; - - ret = dev_clear(di); - - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -541,7 +527,7 @@ SR_PRIV struct sr_dev_driver lecroy_logicstudio_driver_info = { .longname = "LeCroy LogicStudio", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index e0791acc..5107d309 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -264,11 +264,6 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(); -} - static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -470,7 +465,7 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = { .longname = "Link Instruments MSO-19", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index cc9ab74a..72091de4 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -210,11 +210,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -423,7 +418,7 @@ SR_PRIV struct sr_dev_driver manson_hcs_3xxx_driver_info = { .longname = "Manson HCS-3xxx", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index d275760a..d2212ca6 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -253,11 +253,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -496,7 +491,7 @@ SR_PRIV struct sr_dev_driver maynuo_m97_driver_info = { .longname = "maynuo M97/M98 series", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index b8e69465..07d2a8e1 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -150,11 +150,6 @@ static GSList *dev_list(int idx) return ((struct drv_context *)(mic_devs[idx].di->context))->instances; } -static int cleanup(int idx) -{ - return dev_clear(idx); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -244,9 +239,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) #define HW_INIT(X) \ static int init_##X(struct sr_dev_driver *di, struct sr_context *sr_ctx) { \ (void)di; return init(sr_ctx, X); } -#define HW_CLEANUP(X) \ -static int cleanup_##X(const struct sr_dev_driver *di) { \ - (void)di; return cleanup(X); } #define HW_SCAN(X) \ static GSList *scan_##X(struct sr_dev_driver *di, GSList *options) { \ (void)di; return scan(options, X); } @@ -267,7 +259,6 @@ static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi \ /* Driver structs and API function wrappers */ #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ HW_INIT(ID_UPPER) \ -HW_CLEANUP(ID_UPPER) \ HW_SCAN(ID_UPPER) \ HW_DEV_LIST(ID_UPPER) \ HW_DEV_CLEAR(ID_UPPER) \ @@ -278,7 +269,7 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \ .longname = LONGNAME, \ .api_version = 1, \ .init = init_##ID_UPPER, \ - .cleanup = cleanup_##ID_UPPER, \ + .cleanup = std_cleanup, \ .scan = scan_##ID_UPPER, \ .dev_list = dev_list_##ID_UPPER, \ .dev_clear = dev_clear_##ID_UPPER, \ diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 7f9c33f6..693f6e4a 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -538,11 +538,6 @@ static int dev_clear_lps301(const struct sr_dev_driver *di) return std_dev_clear(di, (std_dev_clear_callback)dev_clear_private); } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear_lps301(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -840,7 +835,7 @@ SR_PRIV struct sr_dev_driver motech_lps_301_driver_info = { .longname = "Motech LPS-301", .api_version = 1, .init = init_lps301, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan_lps301, .dev_list = dev_list_lps301, .dev_clear = dev_clear_lps301, diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index 8a93f790..67735d49 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -193,11 +193,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -290,7 +285,7 @@ SR_PRIV struct sr_dev_driver norma_dmm_driver_info = { .longname = "Norma DM9x0 DMMs", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, @@ -309,7 +304,7 @@ SR_PRIV struct sr_dev_driver siemens_b102x_driver_info = { .longname = "Siemens B102x DMMs", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index cb687568..c50509ba 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -215,11 +215,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -592,7 +587,7 @@ SR_PRIV struct sr_dev_driver ols_driver_info = { .longname = "Openbench Logic Sniffer", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index c9a14931..86ad7f9f 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -220,11 +220,6 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear(di, clear_helper); } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -722,7 +717,7 @@ SR_PRIV struct sr_dev_driver p_ols_driver_info = { .longname = "Pipistrello OLS", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 8c328277..d8ad1a06 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -459,11 +459,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int analog_frame_size(const struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; @@ -1072,7 +1067,7 @@ SR_PRIV struct sr_dev_driver rigol_ds_driver_info = { .longname = "Rigol DS", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index dbd85fb3..4450a22c 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -402,21 +402,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - /* Can get called on an unused driver, doesn't matter. */ - return SR_OK; - - ret = std_dev_clear(di, NULL); - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -817,7 +802,7 @@ SR_PRIV struct sr_dev_driver saleae_logic16_driver_info = { .longname = "Saleae Logic16", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 111d76b0..e2afad3b 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -247,11 +247,6 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear(di, clear_helper); } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -642,7 +637,7 @@ SR_PRIV struct sr_dev_driver scpi_pps_driver_info = { .longname = "SCPI PPS", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index f5058764..6b32f648 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -155,11 +155,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -253,7 +248,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) .longname = VENDOR " " MODEL, \ .api_version = 1, \ .init = init, \ - .cleanup = cleanup, \ + .cleanup = std_cleanup, \ .scan = scan, \ .dev_list = dev_list, \ .dev_clear = dev_clear, \ diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 8ee85a62..be7c9ee7 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -803,7 +803,7 @@ SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info = { .longname = "SysClk LWLA series", .api_version = 1, .init = init, - .cleanup = dev_clear, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 7af74b03..245f5501 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -138,11 +138,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -232,7 +227,7 @@ SR_PRIV struct sr_dev_driver teleinfo_driver_info = { .longname = "Teleinfo", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index c43c3c7e..fb3f8b64 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -230,20 +230,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - return SR_OK; - - ret = dev_clear(di); - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -518,7 +504,7 @@ SR_PRIV struct sr_dev_driver testo_driver_info = { .longname = "Testo", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index d6d6f1e7..1d067e39 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -111,11 +111,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -189,7 +184,7 @@ SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info = { .longname = "Tondaj SL-814", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index a77aebba..3eef3aa2 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -139,11 +139,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return dev_clear(di); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -221,7 +216,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) .longname = VENDOR " " MODEL, \ .api_version = 1, \ .init = init, \ - .cleanup = cleanup, \ + .cleanup = std_cleanup, \ .scan = scan, \ .dev_list = dev_list, \ .dev_clear = dev_clear, \ diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index fe752415..13c2a637 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -171,21 +171,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - /* Can get called on an unused driver, doesn't matter. */ - return SR_OK; - - ret = std_dev_clear(di, NULL); - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -349,7 +334,7 @@ SR_PRIV struct sr_dev_driver uni_t_ut32x_driver_info = { .longname = "UNI-T UT32x", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 1bc03442..023388f4 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -183,21 +183,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - /* Can get called on an unused driver, doesn't matter. */ - return SR_OK; - - ret = std_dev_clear(di, NULL); - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -426,7 +411,7 @@ SR_PRIV struct sr_dev_driver victor_dmm_driver_info = { .longname = "Victor DMMs", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 34801afe..25a292ad 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -176,13 +176,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - dev_clear(di); - - return SR_OK; -} - /** * Check which category a given channel group belongs to. * @@ -696,7 +689,7 @@ SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info = { .longname = "Yokogawa DL/DLM", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 22e949c9..f9f2ba79 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -373,11 +373,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -706,7 +701,7 @@ SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = { .longname = "ZEROPLUS Logic Cube LAP-C series", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = NULL, diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index af08f2ab..d859e934 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -849,6 +849,7 @@ typedef void (*std_dev_clear_callback)(void *priv); SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di, const char *prefix); +SR_PRIV int std_cleanup(const struct sr_dev_driver *di); #ifdef HAVE_LIBSERIALPORT SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi); SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi, diff --git a/src/std.c b/src/std.c index d741c809..b66ed8f0 100644 --- a/src/std.c +++ b/src/std.c @@ -63,6 +63,28 @@ SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di, return SR_OK; } +/** + * Standard driver cleanup() callback API helper + * + * @param di The driver instance to use. + * + * Frees all device instances by calling sr_dev_clear() and then releases any + * resources allocated by std_init(). + * + * @retval SR_OK Success + * @retval SR_ERR_ARG Invalid driver + * +*/ +SR_PRIV int std_cleanup(const struct sr_dev_driver *di) +{ + int ret; + + ret = sr_dev_clear(di); + g_free(di->context); + + return ret; +} + /** * Standard API helper for sending an SR_DF_HEADER packet. *