From: Uwe Hermann Date: Fri, 31 May 2013 13:28:43 +0000 (+0200) Subject: alsa: Use std_dev_clear(). X-Git-Tag: libsigrok-0.2.1~78 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c43cf4d40e2b73d992c73c340a887888f05595e0;p=libsigrok.git alsa: Use std_dev_clear(). --- diff --git a/hardware/alsa/api.c b/hardware/alsa/api.c index 69a78ad2..aeac8713 100644 --- a/hardware/alsa/api.c +++ b/hardware/alsa/api.c @@ -36,17 +36,19 @@ static const int32_t hwcaps[] = { SR_PRIV struct sr_dev_driver alsa_driver_info; static struct sr_dev_driver *di = &alsa_driver_info; -static int clear_instances(void) +static void clear_helper(void *priv) { - struct drv_context *drvc; + struct dev_context *devc; - if (!(drvc = di->priv)) - return SR_OK; + devc = priv; - g_slist_free_full(drvc->instances, (GDestroyNotify)alsa_dev_inst_clear); - drvc->instances = NULL; + snd_pcm_hw_params_free(devc->hw_params); + g_free((void *)devc->samplerates); +} - return SR_OK; +static int clear_instances(void) +{ + return std_dev_clear(di, clear_helper); } static int init(struct sr_context *sr_ctx) @@ -121,9 +123,7 @@ static int dev_close(struct sr_dev_inst *sdi) static int cleanup(void) { - clear_instances(); - - return SR_OK; + return clear_instances(); } static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) diff --git a/hardware/alsa/protocol.c b/hardware/alsa/protocol.c index 70a5e686..eea2f5bd 100644 --- a/hardware/alsa/protocol.c +++ b/hardware/alsa/protocol.c @@ -282,22 +282,6 @@ SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di) return devices; } -/* - * Helper to be used with g_slist_free_full(); for properly freeing an alsa - * dev instance. - */ -SR_PRIV void alsa_dev_inst_clear(struct sr_dev_inst *sdi) -{ - struct dev_context *devc; - - if (!(devc = sdi->priv)) - return; - - snd_pcm_hw_params_free(devc->hw_params); - g_free((void*)devc->samplerates); - sr_dev_inst_free(sdi); -} - /** * Set the samplerate of the ALSA device. * diff --git a/hardware/alsa/protocol.h b/hardware/alsa/protocol.h index 17578594..e844bc74 100644 --- a/hardware/alsa/protocol.h +++ b/hardware/alsa/protocol.h @@ -52,11 +52,8 @@ struct dev_context { }; SR_PRIV GSList *alsa_scan(GSList *options, struct sr_dev_driver *di); -SR_PRIV void alsa_dev_inst_clear(struct sr_dev_inst *sdi); - SR_PRIV int alsa_set_samplerate(const struct sr_dev_inst *sdi, uint64_t newrate); - SR_PRIV int alsa_receive_data(int fd, int revents, void *cb_data); #endif