[PATCH] net: usb: Make init_satus() return -ENOMEM if alloc failed

Zqiang posted 1 patch 2 months, 3 weeks ago
drivers/net/usb/usbnet.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] net: usb: Make init_satus() return -ENOMEM if alloc failed
Posted by Zqiang 2 months, 3 weeks ago
This commit make init_status() return -ENOMEM, if invoke
kmalloc() return failed.

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 drivers/net/usb/usbnet.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 921c05bc73e3..26fce452581c 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -254,6 +254,8 @@ static int init_status (struct usbnet *dev, struct usb_interface *intf)
 				"status ep%din, %d bytes period %d\n",
 				usb_pipeendpoint(pipe), maxp, period);
 		}
+	} else {
+		return -ENOMEM;
 	}
 	return 0;
 }
-- 
2.48.1
Re: [PATCH] net: usb: Make init_satus() return -ENOMEM if alloc failed
Posted by Simon Horman 2 months, 3 weeks ago
On Wed, Jul 16, 2025 at 08:15:23AM +0800, Zqiang wrote:
> This commit make init_status() return -ENOMEM, if invoke
> kmalloc() return failed.
> 
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>

Hi,

It seems to me that the code has been structured so that
this case is not treated as an error, and rather initialisation
that depends on it is skipped.

Are you sure this change is correct?
Re: [PATCH] net: usb: Make init_satus() return -ENOMEM if alloc failed
Posted by qiang.zhang@linux.dev 2 months, 3 weeks ago
> 
> On Wed, Jul 16, 2025 at 08:15:23AM +0800, Zqiang wrote:
> 
> > 
> > This commit make init_status() return -ENOMEM, if invoke
> > 
> >  kmalloc() return failed.
> > 
> >  
> > 
> >  Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> > 
> 
> Hi,
> 
> It seems to me that the code has been structured so that
> 
> this case is not treated as an error, and rather initialisation
> 
> that depends on it is skipped.

Yes, your point is also correct, but in theory,
if usb_alloc_urb() allocation fails, we should
also return a value of 0, should we keep the
two behaviors consistent?

> 
> Are you sure this change is correct?


For drivers that have a driver_info->status method, it is generally
needto allocate an interrupt urb and fill it to obtain some
status information, but if kmalloc() faild and return 0 in init_status(),
and some dirvers directly call usbnet_status_start(),
the WARN_ONCE(dev->interrupt == NULL) will be trigger.

Thanks
Zqiang


>
[PATCH] net: usb: Remove duplicate assignments for net->pcpu_stat_type
Posted by Zqiang 2 months, 3 weeks ago
This commit remove duplicate assignments for net->pcpu_stat_type
in usbnet_probe().

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 drivers/net/usb/usbnet.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 6a3cca104af9..921c05bc73e3 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1759,7 +1759,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
 	dev->hard_mtu = net->mtu + net->hard_header_len;
 	net->min_mtu = 0;
 	net->max_mtu = ETH_MAX_MTU;
-	net->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
 
 	net->netdev_ops = &usbnet_netdev_ops;
 	net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
-- 
2.48.1
Re: [PATCH] net: usb: Remove duplicate assignments for net->pcpu_stat_type
Posted by Jakub Kicinski 2 months, 3 weeks ago
On Wed, 16 Jul 2025 08:15:24 +0800 Zqiang wrote:
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>

Your email address seems to suggest the latin spelling of your name
should be Qiang Zhang. Please use that instead of Zqiang?
-- 
pw-bot: cr
Re: [PATCH] net: usb: Remove duplicate assignments for net->pcpu_stat_type
Posted by qiang.zhang@linux.dev 2 months, 3 weeks ago
> 
> On Wed, 16 Jul 2025 08:15:24 +0800 Zqiang wrote:
> 
> > 
> > Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> > 
> 
> Your email address seems to suggest the latin spelling of your name
> 
> should be Qiang Zhang. Please use that instead of Zqiang?

Thanks for replay, Zqiang has always been the name
I use in my life and in the community.

Thanks
Zqiang

> 
> -- 
> 
> pw-bot: cr
>
Re: [PATCH] net: usb: Remove duplicate assignments for net->pcpu_stat_type
Posted by Simon Horman 2 months, 3 weeks ago
On Wed, Jul 16, 2025 at 08:15:24AM +0800, Zqiang wrote:
> This commit remove duplicate assignments for net->pcpu_stat_type
> in usbnet_probe().
> 
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>

This one looks good, thanks.

Reviewed-by: Simon Horman <horms@kernel.org>