Skip to content

Commit 7bb6405

Browse files
jhovoldgregkh
authored andcommitted
USB: serial: io_edgeport: fix descriptor error handling
commit 3c0e25d883d06a1fbd1ad35257e8abaa57befb37 upstream. Make sure to detect short control-message transfers and log an error when reading incomplete manufacturer and boot descriptors. Note that the default all-zero descriptors will now be used after a short transfer is detected instead of partially initialised ones. Fixes: 1da177e ("Linux-2.6.12-rc2") Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 574c8b2 commit 7bb6405

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

drivers/usb/serial/io_edgeport.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,8 +2109,7 @@ static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
21092109
* rom_read
21102110
* reads a number of bytes from the Edgeport device starting at the given
21112111
* address.
2112-
* If successful returns the number of bytes read, otherwise it returns
2113-
* a negative error number of the problem.
2112+
* Returns zero on success or a negative error number.
21142113
****************************************************************************/
21152114
static int rom_read(struct usb_serial *serial, __u16 extAddr,
21162115
__u16 addr, __u16 length, __u8 *data)
@@ -2135,12 +2134,17 @@ static int rom_read(struct usb_serial *serial, __u16 extAddr,
21352134
USB_REQUEST_ION_READ_ROM,
21362135
0xC0, addr, extAddr, transfer_buffer,
21372136
current_length, 300);
2138-
if (result < 0)
2137+
if (result < current_length) {
2138+
if (result >= 0)
2139+
result = -EIO;
21392140
break;
2141+
}
21402142
memcpy(data, transfer_buffer, current_length);
21412143
length -= current_length;
21422144
addr += current_length;
21432145
data += current_length;
2146+
2147+
result = 0;
21442148
}
21452149

21462150
kfree(transfer_buffer);
@@ -2597,9 +2601,10 @@ static void get_manufacturing_desc(struct edgeport_serial *edge_serial)
25972601
EDGE_MANUF_DESC_LEN,
25982602
(__u8 *)(&edge_serial->manuf_descriptor));
25992603

2600-
if (response < 1)
2601-
dev_err(dev, "error in getting manufacturer descriptor\n");
2602-
else {
2604+
if (response < 0) {
2605+
dev_err(dev, "error in getting manufacturer descriptor: %d\n",
2606+
response);
2607+
} else {
26032608
char string[30];
26042609
dev_dbg(dev, "**Manufacturer Descriptor\n");
26052610
dev_dbg(dev, " RomSize: %dK\n",
@@ -2656,9 +2661,10 @@ static void get_boot_desc(struct edgeport_serial *edge_serial)
26562661
EDGE_BOOT_DESC_LEN,
26572662
(__u8 *)(&edge_serial->boot_descriptor));
26582663

2659-
if (response < 1)
2660-
dev_err(dev, "error in getting boot descriptor\n");
2661-
else {
2664+
if (response < 0) {
2665+
dev_err(dev, "error in getting boot descriptor: %d\n",
2666+
response);
2667+
} else {
26622668
dev_dbg(dev, "**Boot Descriptor:\n");
26632669
dev_dbg(dev, " BootCodeLength: %d\n",
26642670
le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength));

0 commit comments

Comments
 (0)