linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] iio: magnetometer: correct a harmless off by one check
@ 2015-05-27  8:20 Dan Carpenter
  2015-05-27  8:37 ` Daniel Baluta
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2015-05-27  8:20 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, Daniel Baluta,
	linux-iio, kernel-janitors

The line before limits i to 0-3 so the existing code works fine but the
check is still off by one and >= is intended instead of >.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c
index aa6e25d..c71392c 100644
--- a/drivers/iio/magnetometer/mmc35240.c
+++ b/drivers/iio/magnetometer/mmc35240.c
@@ -308,7 +308,7 @@ static int mmc35240_read_raw(struct iio_dev *indio_dev,
 			return ret;
 
 		i = (reg & MMC35240_CTRL1_BW_MASK) >> MMC35240_CTRL1_BW_SHIFT;
-		if (i < 0 || i > ARRAY_SIZE(mmc35240_samp_freq))
+		if (i < 0 || i >= ARRAY_SIZE(mmc35240_samp_freq))
 			return -EINVAL;
 
 		*val = mmc35240_samp_freq[i];

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

* Re: [patch] iio: magnetometer: correct a harmless off by one check
  2015-05-27  8:20 [patch] iio: magnetometer: correct a harmless off by one check Dan Carpenter
@ 2015-05-27  8:37 ` Daniel Baluta
  2015-06-01 15:56   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Baluta @ 2015-05-27  8:37 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, Daniel Baluta, linux-iio@vger.kernel.org,
	kernel-janitors

On Wed, May 27, 2015 at 11:20 AM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:
> The line before limits i to 0-3 so the existing code works fine but the
> check is still off by one and >= is intended instead of >.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Good catch.

Reviewed-by: Daniel Baluta <daniel.baluta@intel.com>

>
> diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c
> index aa6e25d..c71392c 100644
> --- a/drivers/iio/magnetometer/mmc35240.c
> +++ b/drivers/iio/magnetometer/mmc35240.c
> @@ -308,7 +308,7 @@ static int mmc35240_read_raw(struct iio_dev *indio_dev,
>                         return ret;
>
>                 i = (reg & MMC35240_CTRL1_BW_MASK) >> MMC35240_CTRL1_BW_SHIFT;
> -               if (i < 0 || i > ARRAY_SIZE(mmc35240_samp_freq))
> +               if (i < 0 || i >= ARRAY_SIZE(mmc35240_samp_freq))
>                         return -EINVAL;
>
>                 *val = mmc35240_samp_freq[i];
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [patch] iio: magnetometer: correct a harmless off by one check
  2015-05-27  8:37 ` Daniel Baluta
@ 2015-06-01 15:56   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2015-06-01 15:56 UTC (permalink / raw)
  To: Daniel Baluta, Dan Carpenter
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald,
	linux-iio@vger.kernel.org, kernel-janitors

On 27/05/15 09:37, Daniel Baluta wrote:
> On Wed, May 27, 2015 at 11:20 AM, Dan Carpenter
> <dan.carpenter@oracle.com> wrote:
>> The line before limits i to 0-3 so the existing code works fine but the
>> check is still off by one and >= is intended instead of >.
>>
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Good catch.
> 
> Reviewed-by: Daniel Baluta <daniel.baluta@intel.com>
Applied to the togreg branch of iio.git - initially pushed out as
testing when I have a network that does anything other than https.

J
> 
>>
>> diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c
>> index aa6e25d..c71392c 100644
>> --- a/drivers/iio/magnetometer/mmc35240.c
>> +++ b/drivers/iio/magnetometer/mmc35240.c
>> @@ -308,7 +308,7 @@ static int mmc35240_read_raw(struct iio_dev *indio_dev,
>>                         return ret;
>>
>>                 i = (reg & MMC35240_CTRL1_BW_MASK) >> MMC35240_CTRL1_BW_SHIFT;
>> -               if (i < 0 || i > ARRAY_SIZE(mmc35240_samp_freq))
>> +               if (i < 0 || i >= ARRAY_SIZE(mmc35240_samp_freq))
>>                         return -EINVAL;
>>
>>                 *val = mmc35240_samp_freq[i];
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


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

end of thread, other threads:[~2015-06-01 21:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-27  8:20 [patch] iio: magnetometer: correct a harmless off by one check Dan Carpenter
2015-05-27  8:37 ` Daniel Baluta
2015-06-01 15:56   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).