diff mbox series

iio: magnetometer: yas530: Fix memchr_inv() misuse

Message ID 20220501195029.151852-1-linus.walleij@linaro.org (mailing list archive)
State Accepted
Headers show
Series iio: magnetometer: yas530: Fix memchr_inv() misuse | expand

Commit Message

Linus Walleij May 1, 2022, 7:50 p.m. UTC
The call to check if the calibration is all zeroes is doing
it wrong: memchr_inv() returns NULL if the the calibration
contains all zeroes, but the check is for != NULL.

Fix it up. It's probably not an urgent fix because the inner
check for BIT(7) in data[13] will save us. But fix it.

Fixes: de8860b1ed47 ("iio: magnetometer: Add driver for Yamaha YAS530")
Reported-by: Jakob Hauser <jahau@rocketmail.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/magnetometer/yamaha-yas530.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jonathan Cameron May 7, 2022, 2:35 p.m. UTC | #1
On Sun,  1 May 2022 21:50:29 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> The call to check if the calibration is all zeroes is doing
> it wrong: memchr_inv() returns NULL if the the calibration
> contains all zeroes, but the check is for != NULL.
> 
> Fix it up. It's probably not an urgent fix because the inner
> check for BIT(7) in data[13] will save us. But fix it.
> 
> Fixes: de8860b1ed47 ("iio: magnetometer: Add driver for Yamaha YAS530")
> Reported-by: Jakob Hauser <jahau@rocketmail.com>
> Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

> ---
>  drivers/iio/magnetometer/yamaha-yas530.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
> index 9ff7b0e56cf6..b2bc637150bf 100644
> --- a/drivers/iio/magnetometer/yamaha-yas530.c
> +++ b/drivers/iio/magnetometer/yamaha-yas530.c
> @@ -639,7 +639,7 @@ static int yas532_get_calibration_data(struct yas5xx *yas5xx)
>  	dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data);
>  
>  	/* Sanity check, is this all zeroes? */
> -	if (memchr_inv(data, 0x00, 13)) {
> +	if (memchr_inv(data, 0x00, 13) == NULL) {
>  		if (!(data[13] & BIT(7)))
>  			dev_warn(yas5xx->dev, "calibration is blank!\n");
>  	}
diff mbox series

Patch

diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
index 9ff7b0e56cf6..b2bc637150bf 100644
--- a/drivers/iio/magnetometer/yamaha-yas530.c
+++ b/drivers/iio/magnetometer/yamaha-yas530.c
@@ -639,7 +639,7 @@  static int yas532_get_calibration_data(struct yas5xx *yas5xx)
 	dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data);
 
 	/* Sanity check, is this all zeroes? */
-	if (memchr_inv(data, 0x00, 13)) {
+	if (memchr_inv(data, 0x00, 13) == NULL) {
 		if (!(data[13] & BIT(7)))
 			dev_warn(yas5xx->dev, "calibration is blank!\n");
 	}