Skip to content

Commit

Permalink
staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_ca…
Browse files Browse the repository at this point in the history
…lib()

* Add a jump target so that a call of the function "mutex_unlock" is stored
  only twice in this function implementation.

* Replace two calls by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
Markus Elfring authored and Jonathan Cameron committed Dec 2, 2017
1 parent 71e083a commit aa6b707
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions drivers/staging/iio/cdc/ad7746.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,24 @@ static inline ssize_t ad7746_start_calib(struct device *dev,
mutex_lock(&chip->lock);
regval |= chip->config;
ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval);
if (ret < 0) {
mutex_unlock(&chip->lock);
return ret;
}
if (ret < 0)
goto unlock;

do {
msleep(20);
ret = i2c_smbus_read_byte_data(chip->client, AD7746_REG_CFG);
if (ret < 0) {
mutex_unlock(&chip->lock);
return ret;
}
if (ret < 0)
goto unlock;

} while ((ret == regval) && timeout--);

mutex_unlock(&chip->lock);

return len;

unlock:
mutex_unlock(&chip->lock);
return ret;
}

static ssize_t ad7746_start_offset_calib(struct device *dev,
Expand Down

0 comments on commit aa6b707

Please sign in to comment.