linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] iio:gyro: adis16136: divide by zero in write_frequency()
@ 2012-11-27  7:24 Dan Carpenter
  2012-11-27 18:40 ` Lars-Peter Clausen
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2012-11-27  7:24 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Lars-Peter Clausen, linux-iio, kernel-janitors

It's slightly cleaner to use kstrtouint() because we pass unsigned ints
to adis16136_set_freq().  On 64 bit systems, if the user passed LONG_MIN
then it we would get past the test against zero but crash in
adis16136_set_freq() because we truncate the high bits away.

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

diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c
index 05486df..b4ee339 100644
--- a/drivers/iio/gyro/adis16136.c
+++ b/drivers/iio/gyro/adis16136.c
@@ -203,10 +203,10 @@ static ssize_t adis16136_write_frequency(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct adis16136 *adis16136 = iio_priv(indio_dev);
-	long val;
+	unsigned int val;
 	int ret;
 
-	ret = kstrtol(buf, 10, &val);
+	ret = kstrtouint(buf, 10, &val);
 	if (ret)
 		return ret;
 

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

* Re: [patch] iio:gyro: adis16136: divide by zero in write_frequency()
  2012-11-27  7:24 [patch] iio:gyro: adis16136: divide by zero in write_frequency() Dan Carpenter
@ 2012-11-27 18:40 ` Lars-Peter Clausen
  2012-11-30 13:13   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2012-11-27 18:40 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Jonathan Cameron, linux-iio, kernel-janitors

On 11/27/2012 08:24 AM, Dan Carpenter wrote:
> It's slightly cleaner to use kstrtouint() because we pass unsigned ints
> to adis16136_set_freq().  On 64 bit systems, if the user passed LONG_MIN
> then it we would get past the test against zero but crash in
> adis16136_set_freq() because we truncate the high bits away.
> 
> 

Thanks,

Acked-By: Lars-Peter Clausen <lars@metafoo.de>

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c
> index 05486df..b4ee339 100644
> --- a/drivers/iio/gyro/adis16136.c
> +++ b/drivers/iio/gyro/adis16136.c
> @@ -203,10 +203,10 @@ static ssize_t adis16136_write_frequency(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct adis16136 *adis16136 = iio_priv(indio_dev);
> -	long val;
> +	unsigned int val;
>  	int ret;
>  
> -	ret = kstrtol(buf, 10, &val);
> +	ret = kstrtouint(buf, 10, &val);
>  	if (ret)
>  		return ret;
>  
> --
> 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:gyro: adis16136: divide by zero in write_frequency()
  2012-11-27 18:40 ` Lars-Peter Clausen
@ 2012-11-30 13:13   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2012-11-30 13:13 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Dan Carpenter, Jonathan Cameron, linux-iio, kernel-janitors

On 11/27/2012 06:40 PM, Lars-Peter Clausen wrote:
> On 11/27/2012 08:24 AM, Dan Carpenter wrote:
>> It's slightly cleaner to use kstrtouint() because we pass unsigned ints
>> to adis16136_set_freq().  On 64 bit systems, if the user passed LONG_MIN
>> then it we would get past the test against zero but crash in
>> adis16136_set_freq() because we truncate the high bits away.
>>
>>
> 
> Thanks,
> 
> Acked-By: Lars-Peter Clausen <lars@metafoo.de>
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Added to togreg branch of

git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

>>
>> diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c
>> index 05486df..b4ee339 100644
>> --- a/drivers/iio/gyro/adis16136.c
>> +++ b/drivers/iio/gyro/adis16136.c
>> @@ -203,10 +203,10 @@ static ssize_t adis16136_write_frequency(struct device *dev,
>>  {
>>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>>  	struct adis16136 *adis16136 = iio_priv(indio_dev);
>> -	long val;
>> +	unsigned int val;
>>  	int ret;
>>  
>> -	ret = kstrtol(buf, 10, &val);
>> +	ret = kstrtouint(buf, 10, &val);
>>  	if (ret)
>>  		return ret;
>>  
>> --
>> 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:[~2012-11-30 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-27  7:24 [patch] iio:gyro: adis16136: divide by zero in write_frequency() Dan Carpenter
2012-11-27 18:40 ` Lars-Peter Clausen
2012-11-30 13:13   ` 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).