Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get()
@ 2024-04-04  7:31 Dan Carpenter
  2024-04-05  7:14 ` Subhajit Ghosh
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2024-04-04  7:31 UTC (permalink / raw)
  To: Subhajit Ghosh
  Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio, linux-kernel,
	kernel-janitors

The > comparison needs to be >= to prevent an out of bounds access.

Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/iio/light/apds9306.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
index 4d8490602cd7..49fa6b7d5170 100644
--- a/drivers/iio/light/apds9306.c
+++ b/drivers/iio/light/apds9306.c
@@ -635,7 +635,7 @@ static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val,
 	if (ret)
 		return ret;
 
-	if (repeat_rate_idx > ARRAY_SIZE(apds9306_repeat_rate_freq))
+	if (repeat_rate_idx >= ARRAY_SIZE(apds9306_repeat_rate_freq))
 		return -EINVAL;
 
 	*val = apds9306_repeat_rate_freq[repeat_rate_idx][0];
-- 
2.43.0


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

* Re: [PATCH] iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get()
  2024-04-04  7:31 [PATCH] iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get() Dan Carpenter
@ 2024-04-05  7:14 ` Subhajit Ghosh
  2024-04-06 15:42   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Subhajit Ghosh @ 2024-04-05  7:14 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio, linux-kernel,
	kernel-janitors

On 4/4/24 18:01, Dan Carpenter wrote:
> The > comparison needs to be >= to prevent an out of bounds access.
> 
> Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>   drivers/iio/light/apds9306.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
> index 4d8490602cd7..49fa6b7d5170 100644
> --- a/drivers/iio/light/apds9306.c
> +++ b/drivers/iio/light/apds9306.c
> @@ -635,7 +635,7 @@ static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val,
>   	if (ret)
>   		return ret;
>   
> -	if (repeat_rate_idx > ARRAY_SIZE(apds9306_repeat_rate_freq))
> +	if (repeat_rate_idx >= ARRAY_SIZE(apds9306_repeat_rate_freq))
>   		return -EINVAL;
Good find.

Reviewed-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>

Regards,
Subhajit Ghosh
>   
>   	*val = apds9306_repeat_rate_freq[repeat_rate_idx][0];


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

* Re: [PATCH] iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get()
  2024-04-05  7:14 ` Subhajit Ghosh
@ 2024-04-06 15:42   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2024-04-06 15:42 UTC (permalink / raw)
  To: Subhajit Ghosh
  Cc: Dan Carpenter, Lars-Peter Clausen, linux-iio, linux-kernel,
	kernel-janitors

On Fri, 5 Apr 2024 17:44:31 +1030
Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote:

> On 4/4/24 18:01, Dan Carpenter wrote:
> > The > comparison needs to be >= to prevent an out of bounds access.
> > 
> > Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> >   drivers/iio/light/apds9306.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
> > index 4d8490602cd7..49fa6b7d5170 100644
> > --- a/drivers/iio/light/apds9306.c
> > +++ b/drivers/iio/light/apds9306.c
> > @@ -635,7 +635,7 @@ static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val,
> >   	if (ret)
> >   		return ret;
> >   
> > -	if (repeat_rate_idx > ARRAY_SIZE(apds9306_repeat_rate_freq))
> > +	if (repeat_rate_idx >= ARRAY_SIZE(apds9306_repeat_rate_freq))
> >   		return -EINVAL;  
> Good find.
> 
> Reviewed-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
> 
Applied to the togreg branch of iio.git (where the fixes patch is currently)
and pushed out as testing initially because there is other stuff in there
I want 0-day to checkout before I make a mess of linux-next.

Thanks,

Jonathan

> Regards,
> Subhajit Ghosh
> >   
> >   	*val = apds9306_repeat_rate_freq[repeat_rate_idx][0];  
> 


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

end of thread, other threads:[~2024-04-06 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-04  7:31 [PATCH] iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get() Dan Carpenter
2024-04-05  7:14 ` Subhajit Ghosh
2024-04-06 15:42   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox