- struct sr_device_instance *sdi;
- struct alsa *alsa;
-
- if (!(sdi = sr_get_device_instance(device_instances, device_index)))
- return;
- alsa = sdi->priv;
- if (!alsa)
- return;
-
- if (alsa->hw_params)
- snd_pcm_hw_params_free(alsa->hw_params);
- if (alsa->capture_handle)
- snd_pcm_close(alsa->capture_handle);
+ struct sr_dev_inst *sdi;
+ struct context *ctx;
+
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
+ sr_err("alsa: %s: sdi was NULL", __func__);
+ return SR_ERR; /* TODO: SR_ERR_ARG? */
+ }
+
+ if (!(ctx = sdi->priv)) {
+ sr_err("alsa: %s: sdi->priv was NULL", __func__);
+ return SR_ERR; /* TODO: SR_ERR_ARG? */
+ }
+
+ // TODO: Return values of snd_*?
+ if (ctx->hw_params)
+ snd_pcm_hw_params_free(ctx->hw_params);
+ if (ctx->capture_handle)
+ snd_pcm_close(ctx->capture_handle);
+
+ return SR_OK;