[PATCH] 9p/trans_usbg: Fix incorrect error check in usb9pfs_alloc_instance()

Yue Haibing posted 1 patch 1 month, 1 week ago
net/9p/trans_usbg.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] 9p/trans_usbg: Fix incorrect error check in usb9pfs_alloc_instance()
Posted by Yue Haibing 1 month, 1 week ago
kzalloc() should use NULL check not a IS_ERR() check.

Fixes: a3be076dc174 ("net/9p/usbg: Add new usb gadget function transport")
Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
---
 net/9p/trans_usbg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/9p/trans_usbg.c b/net/9p/trans_usbg.c
index 975b76839dca..6b694f117aef 100644
--- a/net/9p/trans_usbg.c
+++ b/net/9p/trans_usbg.c
@@ -909,9 +909,9 @@ static struct usb_function_instance *usb9pfs_alloc_instance(void)
 	usb9pfs_opts->buflen = DEFAULT_BUFLEN;
 
 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-	if (IS_ERR(dev)) {
+	if (!dev) {
 		kfree(usb9pfs_opts);
-		return ERR_CAST(dev);
+		return ERR_PTR(-ENOMEM);
 	}
 
 	usb9pfs_opts->dev = dev;
-- 
2.34.1
Re: [PATCH] 9p/trans_usbg: Fix incorrect error check in usb9pfs_alloc_instance()
Posted by Christian Schoenebeck 1 month, 1 week ago
On Saturday, October 19, 2024 11:23:02 AM CEST Yue Haibing wrote:
> kzalloc() should use NULL check not a IS_ERR() check.
> 
> Fixes: a3be076dc174 ("net/9p/usbg: Add new usb gadget function transport")
> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>

Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>

> ---
>  net/9p/trans_usbg.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/9p/trans_usbg.c b/net/9p/trans_usbg.c
> index 975b76839dca..6b694f117aef 100644
> --- a/net/9p/trans_usbg.c
> +++ b/net/9p/trans_usbg.c
> @@ -909,9 +909,9 @@ static struct usb_function_instance *usb9pfs_alloc_instance(void)
>  	usb9pfs_opts->buflen = DEFAULT_BUFLEN;
>  
>  	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> -	if (IS_ERR(dev)) {
> +	if (!dev) {
>  		kfree(usb9pfs_opts);
> -		return ERR_CAST(dev);
> +		return ERR_PTR(-ENOMEM);
>  	}
>  
>  	usb9pfs_opts->dev = dev;
>