diff options
author | Cristina Moraru <cristina.moraru09@gmail.com> | 2015-10-25 21:31:41 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-10-27 05:49:09 (GMT) |
commit | 31a99443a53aa65cdaaaaa3bcd5ed685eec87419 (patch) | |
tree | c2708fe49680cb1af84f2ad8b4e2870c71208873 /drivers/staging/iio | |
parent | 1c58f0eb9cd48c8b3426df1b073da796623c2b45 (diff) | |
download | linux-31a99443a53aa65cdaaaaa3bcd5ed685eec87419.tar.xz |
staging: iio: adis16060_core: Fix error handling
We need to check adis16060_spi_read return code to avoid feeding user
space with bogus data.
While, at it introduce out_unlock label in order to simplify locking
on error path.
Signed-off-by: Cristina Moraru <cristina.moraru09@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r-- | drivers/staging/iio/gyro/adis16060_core.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/staging/iio/gyro/adis16060_core.c b/drivers/staging/iio/gyro/adis16060_core.c index 80783e7..981b63f 100644 --- a/drivers/staging/iio/gyro/adis16060_core.c +++ b/drivers/staging/iio/gyro/adis16060_core.c @@ -89,11 +89,13 @@ static int adis16060_read_raw(struct iio_dev *indio_dev, /* Take the iio_dev status lock */ mutex_lock(&indio_dev->mlock); ret = adis16060_spi_write(indio_dev, chan->address); - if (ret < 0) { - mutex_unlock(&indio_dev->mlock); - return ret; - } + if (ret < 0) + goto out_unlock; + ret = adis16060_spi_read(indio_dev, &tval); + if (ret < 0) + goto out_unlock; + mutex_unlock(&indio_dev->mlock); *val = tval; return IIO_VAL_INT; @@ -108,6 +110,10 @@ static int adis16060_read_raw(struct iio_dev *indio_dev, } return -EINVAL; + +out_unlock: + mutex_unlock(&indio_dev->mlock); + return ret; } static const struct iio_info adis16060_info = { |