Thread (6 messages) 6 messages, 3 authors, 2021-05-17

Re: [PATCH net] net: hso: check for allocation failure in hso_create_bulk_serial_device()

From: Dan Carpenter <hidden>
Date: 2021-05-12 13:13:11
Also in: kernel-janitors, linux-usb

On Wed, May 12, 2021 at 12:19:03PM +0200, Johan Hovold wrote:
On Wed, May 12, 2021 at 01:09:04PM +0300, Dan Carpenter wrote:
quoted
Add a couple checks for if these allocations fail.

Fixes: 542f54823614 ("tty: Modem functions for the HSO driver")
Signed-off-by: Dan Carpenter <redacted>
---
 drivers/net/usb/hso.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 3ef4b2841402..3b2a868d7a72 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -2618,9 +2618,13 @@ static struct hso_device *hso_create_bulk_serial_device(
 		num_urbs = 2;
 		serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget),
 					   GFP_KERNEL);
+		if (!serial->tiocmget)
+			goto exit;
Nice catch; the next assignment would go boom if this ever failed.

This appears to have been introduced by 

	af0de1303c4e ("usb: hso: obey DMA rules in tiocmget")
quoted
 		serial->tiocmget->serial_state_notification
 			= kzalloc(sizeof(struct hso_serial_state_notification),
 					   GFP_KERNEL);
+		if (!serial->tiocmget->serial_state_notification)
+			goto exit;
 		/* it isn't going to break our heart if serial->tiocmget
 		 *  allocation fails don't bother checking this.
 		 */
You should remove this comment and drop the conditional on the following
line as well now, though.
Ah, good catch.  I'll resend. Thanks!

regards,
dan carpenter
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help