USB: serial: mos7720: Fix error code in mos7720_write()
Subsystems (3)
PATCH 1/1 USB: serial: mos7720: Fix error code in mos7720_write()
This code should return -ENOMEM if the kmalloc() fails but instead it returns success.
---
The first error path is probably wrong as well?
drivers/usb/serial/mos7720.c
1077 /* try to find a free urb in the list */
1078 urb = NULL;
1079
1080 for (i = 0; i < NUM_URBS; ++i) {
1081 if (mos7720_port->write_urb_pool[i] &&
1082 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) {
1083 urb = mos7720_port->write_urb_pool[i]; 1084 dev_dbg(&port->dev, "URB:%d\n", i); 1085 break;
1086 }
1087 }
1088
1089 if (urb = NULL) {
1090 dev_dbg(&port->dev, "%s - no more free urbs\n", __func__);
1091 goto exit;
Should return -ENODEV?
1092 }
drivers/usb/serial/mos7720.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/serial/mos7720.c +3 -1
@@ -1094,8 +1094,10 @@ static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port,if (urb->transfer_buffer =NULL ) { urb->transfer_buffer =kmalloc (URB_TRANSFER_BUFFER_SIZE ,GFP_ATOMIC ); -if (!urb->transfer_buffer) +if (!urb->transfer_buffer) { + bytes_sent = -ENOMEM ; goto exit; + } } transfer_size =min (count,URB_TRANSFER_BUFFER_SIZE );
Signature · 1 line
2.29.2
Johan Hovold
maintainerQuoted 17 lines · Dan Carpenter
This code should return
-ENOMEMif thekmalloc()fails but instead it returns success.Signed-off-by Dan Carpenter <[email protected]>---
The first error path is probably wrong as well?
drivers/usb/serial/mos7720.c
1077 /* try to find a free urb in the list */
1078 urb = NULL;
1079
1080 for (i = 0; i <NUM_URBS; ++i) {
1081 if (mos7720_port->write_urb_pool[i] &&
1082 mos7720_port->write_urb_pool[i]->status !=-EINPROGRESS) {1083 urb = mos7720_port->write_urb_pool[i]; 1084 dev_dbg(&port->dev, "URB:%d\n", i); 1085 break;
Quoted 8 lines
1086 }
1087 }
1088
1089 if (urb = NULL) {
1090dev_dbg(&port->dev, "%s - no more free urbs\n", __func__);
1091 goto exit;Should return
-ENODEV?
No, this bit is correct (modulo the missing locking and reliance on the URB status). When there are no free URBs we want the tty layer to retry later.
Quoted 10 lines
1092 }
drivers/usb/serial/mos7720.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/serial/mos7720.c +0
-0
drivers/usb/serial/mos7720.c static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port, · line 1102
Quoted 10 lines
drivers/usb/serial/mos7720.c +3
-1@@ -1094,8 +1094,10 @@ static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port,if (urb->transfer_buffer =NULL ) { urb->transfer_buffer =kmalloc (URB_TRANSFER_BUFFER_SIZE ,GFP_ATOMIC ); -if (!urb->transfer_buffer) +if (!urb->transfer_buffer) { + bytes_sent = -ENOMEM ; goto exit; + } } transfer_size =min (count,URB_TRANSFER_BUFFER_SIZE );
Now applied, thanks.
Johan