diff mbox series

[-next] USB: gadget: f_fs: Use ERR_CAST instead of ERR_PTR(PTR_ERR(...))

Message ID 20210519023032.19812-1-yuehaibing@huawei.com
State New
Headers show
Series [-next] USB: gadget: f_fs: Use ERR_CAST instead of ERR_PTR(PTR_ERR(...)) | expand

Commit Message

Yue Haibing May 19, 2021, 2:30 a.m. UTC
A coccicheck run provided information like the following.

./drivers/usb/gadget/function/f_fs.c:3832:9-16:
 WARNING: ERR_CAST can be used with data

Use ERR_CAST to fix this.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Greg Kroah-Hartman May 21, 2021, 11:48 a.m. UTC | #1
On Wed, May 19, 2021 at 10:30:32AM +0800, YueHaibing wrote:
> A coccicheck run provided information like the following.

> 

> ./drivers/usb/gadget/function/f_fs.c:3832:9-16:

>  WARNING: ERR_CAST can be used with data

> 

> Use ERR_CAST to fix this.

> 

> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

> ---

>  drivers/usb/gadget/function/f_fs.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c

> index bf109191659a..61110ff52f49 100644

> --- a/drivers/usb/gadget/function/f_fs.c

> +++ b/drivers/usb/gadget/function/f_fs.c

> @@ -3829,7 +3829,7 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)

>  

>  	data = memdup_user(buf, len);

>  	if (IS_ERR(data))

> -		return ERR_PTR(PTR_ERR(data));

> +		return ERR_CAST(data);


This should just be:
		return PTR_ERR(data);
right?

No need for 2 casts to happen here.

thanks,

greg k-h
Yue Haibing May 23, 2021, 6:33 a.m. UTC | #2
On 2021/5/21 19:48, Greg KH wrote:
> On Wed, May 19, 2021 at 10:30:32AM +0800, YueHaibing wrote:

>> A coccicheck run provided information like the following.

>>

>> ./drivers/usb/gadget/function/f_fs.c:3832:9-16:

>>  WARNING: ERR_CAST can be used with data

>>

>> Use ERR_CAST to fix this.

>>

>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

>> ---

>>  drivers/usb/gadget/function/f_fs.c | 2 +-

>>  1 file changed, 1 insertion(+), 1 deletion(-)

>>

>> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c

>> index bf109191659a..61110ff52f49 100644

>> --- a/drivers/usb/gadget/function/f_fs.c

>> +++ b/drivers/usb/gadget/function/f_fs.c

>> @@ -3829,7 +3829,7 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)

>>  

>>  	data = memdup_user(buf, len);

>>  	if (IS_ERR(data))

>> -		return ERR_PTR(PTR_ERR(data));

>> +		return ERR_CAST(data);

> 

> This should just be:

> 		return PTR_ERR(data);

> right?


ffs_prepare_buffer() should return an ERR_PTR() encoded error code on failure,

maybe there just do:

		return data;

> 

> No need for 2 casts to happen here.

> 

> thanks,

> 

> greg k-h

> .

>
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index bf109191659a..61110ff52f49 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3829,7 +3829,7 @@  static char *ffs_prepare_buffer(const char __user *buf, size_t len)
 
 	data = memdup_user(buf, len);
 	if (IS_ERR(data))
-		return ERR_PTR(PTR_ERR(data));
+		return ERR_CAST(data);
 
 	pr_vdebug("Buffer from user space:\n");
 	ffs_dump_mem("", data, len);