Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] iio: imu: adis: assign value only if return code zero in read funcs
@ 2019-10-30 11:55 Alexandru Ardelean
  2019-11-01  9:25 ` Ardelean, Alexandru
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2019-10-30 11:55 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: jic23, lars, Alexandru Ardelean

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(-)

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;
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: imu: adis: assign value only if return code zero in read funcs
  2019-10-30 11:55 [PATCH] iio: imu: adis: assign value only if return code zero in read funcs Alexandru Ardelean
@ 2019-11-01  9:25 ` Ardelean, Alexandru
  0 siblings, 0 replies; 2+ messages in thread
From: Ardelean, Alexandru @ 2019-11-01  9:25 UTC (permalink / raw)
  To: linux-kernel, linux-iio; +Cc: jic23, lars

On Wed, 2019-10-30 at 13:55 +0200, Alexandru Ardelean 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`.
> 

@Jonathan:
Please disregard this.
I will re-spin this as a series.
It turned out that the whole thing/changeset is much bigger than I
initially anticipated.

I think I found the reason why we (at ADI) weren't catching the ADIS
warnings/errors, before upstreaming.
It turns out, that we were only testing with ARM & ARM64 compilers, while
the compilers that were hitting us with warnings are x86_64. I do remember
[from past experiences] that different GCC compilers report different
[often valid] types of errors. But, if I don't need to work with too many
ARCHs, I do forget about this aspect.

In any case, I've updated our CI to also include a build-run with x86_64
for all ADI drivers.
And we may also extend this to cover the entire kernel [later].

Thanks
Alex


> 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(-)
> 
> 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;
>  }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-30 11:55 [PATCH] iio: imu: adis: assign value only if return code zero in read funcs Alexandru Ardelean
2019-11-01  9:25 ` Ardelean, Alexandru

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git