hw_dev_close(): Move common checks to wrapper.
Check the relevant arguments for != NULL before calling the actual driver-specific function, so that the driver can safely assume those arguments are non-NULL. This removes the need to duplicate these checks in every driver.
This commit is contained in:
parent
0e94d524c1
commit
961009b0c4
|
@ -212,10 +212,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
devc = sdi->priv;
|
||||
|
||||
if (devc->serial && devc->serial->fd != -1) {
|
||||
serial_close(devc->serial);
|
||||
|
|
|
@ -103,8 +103,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
|
||||
devc = sdi->priv;
|
||||
|
||||
sr_dbg("Closing device.");
|
||||
|
||||
if (devc->capture_handle) {
|
||||
sr_dbg("Closing PCM device.");
|
||||
if ((ret = snd_pcm_close(devc->capture_handle)) < 0) {
|
||||
|
|
|
@ -752,10 +752,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("%s: sdi->priv was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
devc = sdi->priv;
|
||||
|
||||
/* TODO */
|
||||
if (sdi->status == SR_ST_ACTIVE)
|
||||
|
|
|
@ -196,10 +196,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
devc = sdi->priv;
|
||||
|
||||
if (devc->serial && devc->serial->fd != -1) {
|
||||
serial_close(devc->serial);
|
||||
|
|
|
@ -240,12 +240,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("%s: sdi->priv was NULL.", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_dbg("Closing device.");
|
||||
devc = sdi->priv;
|
||||
|
||||
if (sdi->status == SR_ST_ACTIVE) {
|
||||
sr_dbg("Status ACTIVE, closing device.");
|
||||
|
@ -256,7 +251,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
|
||||
sdi->status = SR_ST_INACTIVE;
|
||||
|
||||
sr_dbg("Freeing sample buffer.");
|
||||
g_free(devc->final_buf);
|
||||
|
||||
return SR_OK;
|
||||
|
|
|
@ -158,10 +158,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
devc = sdi->priv;
|
||||
|
||||
if (devc->serial && devc->serial->fd != -1) {
|
||||
serial_close(devc->serial);
|
||||
|
|
|
@ -246,10 +246,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
devc = sdi->priv;
|
||||
|
||||
if (devc->serial && devc->serial->fd != -1) {
|
||||
serial_close(devc->serial);
|
||||
|
|
|
@ -559,6 +559,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
struct dev_context *devc;
|
||||
|
||||
devc = sdi->priv;
|
||||
|
||||
if (devc->usb->devhdl == NULL)
|
||||
return SR_ERR;
|
||||
|
||||
|
|
|
@ -339,10 +339,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("sdi->priv was NULL.");
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
devc = sdi->priv;
|
||||
|
||||
if (devc->serial && devc->serial->fd != -1) {
|
||||
serial_close(devc->serial);
|
||||
|
|
|
@ -483,10 +483,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
if (!(devc = sdi->priv)) {
|
||||
sr_err("%s: sdi->priv was NULL", __func__);
|
||||
return SR_ERR;
|
||||
}
|
||||
devc = sdi->priv;
|
||||
|
||||
if (!devc->usb->devhdl)
|
||||
return SR_ERR;
|
||||
|
|
40
session.c
40
session.c
|
@ -107,10 +107,46 @@ SR_API int sr_session_destroy(void)
|
|||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a device instance.
|
||||
*
|
||||
* @param sdi The device instance to close. Must not be NULL. Also,
|
||||
* sdi->driver, sdi->driver->priv, and sdi->priv must not be NULL.
|
||||
*/
|
||||
static void sr_dev_close(struct sr_dev_inst *sdi)
|
||||
{
|
||||
if (sdi->driver && sdi->driver->dev_close)
|
||||
sdi->driver->dev_close(sdi);
|
||||
int ret;
|
||||
|
||||
if (!sdi) {
|
||||
sr_err("Invalid device instance, can't close device.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* In the drivers sdi->priv is a 'struct dev_context *devc'. */
|
||||
if (!sdi->priv) {
|
||||
/*
|
||||
* Should be sr_err() in theory, but the 'demo' driver has
|
||||
* NULL for sdi->priv, so we use sr_dbg() until that's fixed.
|
||||
*/
|
||||
sr_dbg("Invalid device context, can't close device.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sdi->driver) {
|
||||
sr_err("Invalid driver, can't close device.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sdi->driver->priv) {
|
||||
sr_err("Driver not initialized, can't close device.");
|
||||
return;
|
||||
}
|
||||
|
||||
sr_spew("Closing '%s' device instance %d.", sdi->driver->name,
|
||||
sdi->index);
|
||||
|
||||
if ((ret = sdi->driver->dev_close(sdi)) < 0)
|
||||
sr_err("Failed to close device instance: %d.", ret);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue