diff mbox series

[10/10] iio: imu: adis: assign value only if return code zero in read funcs

Message ID 20191101093505.9408-11-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: adis: cleanups and fixes | expand

Commit Message

Alexandru Ardelean Nov. 1, 2019, 9:35 a.m. UTC
The inline read functions in the ADIS library don't check the return value
of the `adis_read_reg()` function and assign the value of `tmp` regardless.

Fix this by checking if return value is zero and only then assigning the
value of `tmp`.

Fixes: 57a1228a06b7a ("iio:imu:adis: Add support for 32bit registers")
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 include/linux/iio/imu/adis.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Jonathan Cameron Nov. 3, 2019, 10:49 a.m. UTC | #1
On Fri, 1 Nov 2019 11:35:05 +0200
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> The inline read functions in the ADIS library don't check the return value
> of the `adis_read_reg()` function and assign the value of `tmp` regardless.
> 
> Fix this by checking if return value is zero and only then assigning the
> value of `tmp`.
> 
> Fixes: 57a1228a06b7a ("iio:imu:adis: Add support for 32bit registers")
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Again, I added a note to say I don't think this is stable material.
As far as I know we don't have any actual bugs caused by this as we always
check the return value further up the stack.

Let me know if I've missed something.

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

> ---
>  include/linux/iio/imu/adis.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
> index 4c53815bb729..92aae14593bf 100644
> --- a/include/linux/iio/imu/adis.h
> +++ b/include/linux/iio/imu/adis.h
> @@ -129,7 +129,8 @@ static inline int adis_read_reg_16(struct adis *adis, unsigned int reg,
>  	int ret;
>  
>  	ret = adis_read_reg(adis, reg, &tmp, 2);
> -	*val = tmp;
> +	if (ret == 0)
> +		*val = tmp;
>  
>  	return ret;
>  }
> @@ -147,7 +148,8 @@ static inline int adis_read_reg_32(struct adis *adis, unsigned int reg,
>  	int ret;
>  
>  	ret = adis_read_reg(adis, reg, &tmp, 4);
> -	*val = tmp;
> +	if (ret == 0)
> +		*val = tmp;
>  
>  	return ret;
>  }
diff mbox series

Patch

diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
index 4c53815bb729..92aae14593bf 100644
--- a/include/linux/iio/imu/adis.h
+++ b/include/linux/iio/imu/adis.h
@@ -129,7 +129,8 @@  static inline int adis_read_reg_16(struct adis *adis, unsigned int reg,
 	int ret;
 
 	ret = adis_read_reg(adis, reg, &tmp, 2);
-	*val = tmp;
+	if (ret == 0)
+		*val = tmp;
 
 	return ret;
 }
@@ -147,7 +148,8 @@  static inline int adis_read_reg_32(struct adis *adis, unsigned int reg,
 	int ret;
 
 	ret = adis_read_reg(adis, reg, &tmp, 4);
-	*val = tmp;
+	if (ret == 0)
+		*val = tmp;
 
 	return ret;
 }