Re: [PATCH] comedi_fops: Replace deprecated strict_strtoul with kstrtoul

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

 



On Tue, Nov 29, 2011 at 03:19:11PM +0100, Florian Schmaus wrote:
> As reported by checkpatch.pl strict_strtoul should be replaced with kstrtoul
> 

When we introduce the kstrtoXX functions, we introduced a number of
new functions like kstroint() that weren't available in the
strict_strtoXX functions so it's not a one to one change.  In other
words, you shouldn't just do a rename, you should think about each
one and decide the right way to do it with the new functions.

The new functions also have an -ERANGE return as well as the
original -EINVAL.  So you should preserve the return value instead
of just returning -EINVAL all the time.

OLD:
	if (strict_strtoul(buf, 10, &new_max_size_kb))
		return -EINVAL;
NEW:
	ret = kstrtoul(buf, 10, &new_max_size_kb);
	if (ret)
		return ret;

> Signed-off-by: Florian Schmaus <fschmaus@xxxxxxxxx>
> ---
>  drivers/staging/comedi/comedi_fops.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
> index 21d8c1c..a88a1e8 100644
> --- a/drivers/staging/comedi/comedi_fops.c
> +++ b/drivers/staging/comedi/comedi_fops.c
> @@ -2434,7 +2434,7 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
>  	struct comedi_subdevice *const read_subdevice =
>  	    comedi_get_read_subdevice(info);
>  
> -	if (strict_strtoul(buf, 10, &new_max_size_kb))
> +	if (kstrtoul(buf, 10, &new_max_size_kb))
>  		return -EINVAL;
>  	if (new_max_size_kb != (uint32_t) new_max_size_kb)
>  		return -EINVAL;

If you look at this, "new_max_size_kb" is unsigned long but it
checks to see that it can fit inside a u32.  So now that we have the
kstrtou32() function we could do that in one step:

diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 5e78c77..56024c8 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -2479,15 +2479,15 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
 					const char *buf, size_t count)
 {
 	struct comedi_device_file_info *info = dev_get_drvdata(dev);
-	unsigned long new_max_size_kb;
+	u32 new_max_size_kb;
 	uint64_t new_max_size;
 	struct comedi_subdevice *const read_subdevice =
 	    comedi_get_read_subdevice(info);
+	int ret;
 
-	if (strict_strtoul(buf, 10, &new_max_size_kb))
-		return -EINVAL;
-	if (new_max_size_kb != (uint32_t) new_max_size_kb)
-		return -EINVAL;
+	ret = kstrtou32(buf, 10, &new_max_size_kb);
+	if (ret)
+		return ret;
 	new_max_size = ((uint64_t) new_max_size_kb) * bytes_per_kibi;
 	if (new_max_size != (uint32_t) new_max_size)
 		return -EINVAL;

Something like that.  I haven't looked at all the rest.  It may be
that the patches get more complicated and need to be broken up into
small chunks and sent one by one.

regards,
dan carpenter

Attachment: signature.asc
Description: Digital signature

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux