Commit 31db0dbd authored by Dan Carpenter's avatar Dan Carpenter Committed by David S. Miller

net: hso: check for allocation failure in hso_create_bulk_serial_device()

In current kernels, small allocations never actually fail so this
patch shouldn't affect runtime.

Originally this error handling code written with the idea that if
the "serial->tiocmget" allocation failed, then we would continue
operating instead of bailing out early.  But in later years we added
an unchecked dereference on the next line.

	serial->tiocmget->serial_state_notification = kzalloc();
        ^^^^^^^^^^^^^^^^^^

Since these allocations are never going fail in real life, this is
mostly a philosophical debate, but I think bailing out early is the
correct behavior that the user would want.  And generally it's safer to
bail as soon an error happens.

Fixes: af0de130 ("usb: hso: obey DMA rules in tiocmget")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b7df21cf
...@@ -2618,13 +2618,13 @@ static struct hso_device *hso_create_bulk_serial_device( ...@@ -2618,13 +2618,13 @@ static struct hso_device *hso_create_bulk_serial_device(
num_urbs = 2; num_urbs = 2;
serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget), serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget),
GFP_KERNEL); GFP_KERNEL);
if (!serial->tiocmget)
goto exit;
serial->tiocmget->serial_state_notification serial->tiocmget->serial_state_notification
= kzalloc(sizeof(struct hso_serial_state_notification), = kzalloc(sizeof(struct hso_serial_state_notification),
GFP_KERNEL); GFP_KERNEL);
/* it isn't going to break our heart if serial->tiocmget if (!serial->tiocmget->serial_state_notification)
* allocation fails don't bother checking this. goto exit;
*/
if (serial->tiocmget && serial->tiocmget->serial_state_notification) {
tiocmget = serial->tiocmget; tiocmget = serial->tiocmget;
tiocmget->endp = hso_get_ep(interface, tiocmget->endp = hso_get_ep(interface,
USB_ENDPOINT_XFER_INT, USB_ENDPOINT_XFER_INT,
...@@ -2641,7 +2641,6 @@ static struct hso_device *hso_create_bulk_serial_device( ...@@ -2641,7 +2641,6 @@ static struct hso_device *hso_create_bulk_serial_device(
} else } else
hso_free_tiomget(serial); hso_free_tiomget(serial);
} }
}
else else
num_urbs = 1; num_urbs = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment