RE: [PATCH] iio: common: st_sensors: fix possible infinite loop in st_sensors_irq_thread

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jonathan, Lorenzo,

I am not able to test it right now, I can probably do this weekend.
My comments inline.


> -----Original Message-----
> From: Lorenzo Bianconi <lorenzo@xxxxxxxxxx>
> Sent: Sunday, November 15, 2020 6:38 AM
> To: jic23@xxxxxxxxxx
> Cc: lorenzo.bianconi@xxxxxxxxxx; linux-iio@xxxxxxxxxxxxxxx;
> linus.walleij@xxxxxxxxxx; Denis CIOCCA <denis.ciocca@xxxxxx>
> Subject: [PATCH] iio: common: st_sensors: fix possible infinite loop in
> st_sensors_irq_thread
> 
> Return a boolean value in st_sensors_new_samples_available routine in
> order to avoid an infinite loop in st_sensors_irq_thread if stat_drdy.addr is
> not defined or stat_drdy read fails
> 
> Fixes: 90efe05562921 ("iio: st_sensors: harden interrupt handling")
> Reported-by: Jonathan Cameron <jic23@xxxxxxxxxx>
> Signed-off-by: Lorenzo Bianconi <lorenzo@xxxxxxxxxx>
> ---
> This patch is just compile tested, I have not carried out any run test
> ---
>  .../common/st_sensors/st_sensors_trigger.c    | 20 ++++++++-----------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c
> b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> index 0507283bd4c1..3bee5c9255d4 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> @@ -23,35 +23,31 @@
>   * @sdata: Sensor data.
>   *
>   * returns:
> - * 0 - no new samples available
> - * 1 - new samples available
> - * negative - error or unknown
> + * false - no new samples available or read error
> + * true - new samples available
>   */
> -static int st_sensors_new_samples_available(struct iio_dev *indio_dev,
> -					    struct st_sensor_data *sdata)
> +static bool st_sensors_new_samples_available(struct iio_dev *indio_dev,
> +					     struct st_sensor_data *sdata)
>  {
>  	int ret, status;
> 
>  	/* How would I know if I can't check it? */
>  	if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr)
> -		return -EINVAL;
> +		return false;

To me this should return true. When a sensor does not specify the address (because there is no such register ie) the interrupt should be considered a valid interrupt.
In the original code from Linus indeed the if condition that is using this function is checking && -EINVAL that is considered true.

> 
>  	/* No scan mask, no interrupt */
>  	if (!indio_dev->active_scan_mask)
> -		return 0;
> +		return false;
> 
>  	ret = regmap_read(sdata->regmap,
>  			  sdata->sensor_settings->drdy_irq.stat_drdy.addr,
>  			  &status);
>  	if (ret < 0) {
>  		dev_err(sdata->dev, "error checking samples available\n");
> -		return ret;
> +		return false;

This part indeed is probably the one that before could cause problems because in case of failure -something returned it is considered true.


>  	}
> 
> -	if (status & sdata->sensor_settings->drdy_irq.stat_drdy.mask)
> -		return 1;
> -
> -	return 0;
> +	return !!(status & sdata->sensor_settings-
> >drdy_irq.stat_drdy.mask);
>  }
> 
>  /**
> --
> 2.26.2





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux