[PATCH 3.2 072/199] USB: serial: keyspan_pda: verify endpoints at probe

From: Ben Hutchings
Date: Fri Mar 10 2017 - 06:57:10 EST


3.2.87-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <johan@xxxxxxxxxx>

commit 5d9b0f859babe96175cd33d7162a9463a875ffde upstream.

Check for the expected endpoints in attach() and fail loudly if not
present.

Note that failing to do this appears to be benign since da280e348866
("USB: keyspan_pda: clean up write-urb busy handling") which prevents a
NULL-pointer dereference in write() by never marking a non-existent
write-urb as free.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
[bwh: Backported to 3.2: add this check to the existing
usb_serial_driver::attach implementation]
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
---
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -806,9 +806,15 @@ MODULE_FIRMWARE("keyspan_pda/xircom_pgs.

static int keyspan_pda_startup(struct usb_serial *serial)
{
-
+ unsigned char num_ports = serial->num_ports;
struct keyspan_pda_private *priv;

+ if (serial->num_bulk_out < num_ports ||
+ serial->num_interrupt_in < num_ports) {
+ dev_err(&serial->interface->dev, "missing endpoints\n");
+ return -ENODEV;
+ }
+
/* allocate the private data structures for all ports. Well, for all
one ports. */