Skip to contentSkip to conversation

net/9p/usbg: fix handling of the failed kzalloc() memory allocation

PATCH In review Mirsad Todorovac 2 participants 3 messages Nov 9, 2024 – Dec 11, 2024 9P file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/9p/usbg: fix handling of the failed kzalloc() memory allocation

On the linux-next, next-20241108 vanilla kernel, the coccinelle tool gave the following error report:

./net/9p/trans_usbg.c:912:5-11: ERROR: allocation function on line 911 returns NULL not ERR_PTR on failure

kzalloc() failure is fixed to handle the NULL return case on the memory exhaustion.

Fixes a3be076dc174d ("net/9p/usbg: Add new usb gadget function transport")
Cc Michael Grzeschik <[email protected]>
Cc Eric Van Hensbergen <[email protected]>
Cc Latchesar Ionkov <[email protected]>
Cc Dominique Martinet <[email protected]>
Cc Christian Schoenebeck <[email protected]>

---
v1:
initial version.

 net/9p/trans_usbg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/9p/trans_usbg.c +2 -2
index 975b76839dca..6b694f117aef 100644
@@ -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;
Signature · 1 line
2.43.0
#1 lore raw

Mirsad Todorovac wrote on Sat, Nov 09, 2024 at 10:18:41PM +0100:

Quoted 7 lines

On the linux-next, next-20241108 vanilla kernel, the coccinelle tool gave the following error report:

./net/9p/trans_usbg.c:912:5-11: ERROR: allocation function on line 911 returns NULL not ERR_PTR on failure

kzalloc() failure is fixed to handle the NULL return case on the memory exhaustion.

Thank you, I've taken this in 9p-next and will submit it to Linus next cycle

Signature · 1 line
Dominique
#2 lore raw

Hi,

Quoted 11 lines · Dominique Martinet

Mirsad Todorovac wrote on Sat, Nov 09, 2024 at 10:18:41PM +0100:

Quoted 7 lines

On the linux-next, next-20241108 vanilla kernel, the coccinelle tool gave the following error report:

./net/9p/trans_usbg.c:912:5-11: ERROR: allocation function on line 911 returns NULL not ERR_PTR on failure

kzalloc() failure is fixed to handle the NULL return case on the memory exhaustion.

Thank you, I've taken this in 9p-next and will submit it to Linus next cycle

Hi, Dominique,

Sorry for the late reply, but yes, it is perfectly OK for the patch to go with the next cycle.

I confirm I can see the commit in the torvalds tree, so this is a minor patch (+2/-2 lines), but a proof of concept that it can be done.

Best regards,
Mirsad Todorovac