Commit 0282b7f2a874e72c18fcd5a112ccf67f71ba7f5c

Authored by Alan Stern
Committed by Greg Kroah-Hartman
1 parent e67d70f2f5

usb-serial: don't release unregistered minors

This patch (as1121) fixes a bug in the USB serial core.  When a device
is unregistered, the core will give back its minors -- even if the
device hasn't been assigned any!

The patch reserves the highest minor value (255) to mean that no minor
was assigned.  It also removes some dead code and does a small style
fixup.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 2 changed files with 5 additions and 5 deletions Side-by-side Diff

drivers/usb/serial/usb-serial.c
... ... @@ -122,9 +122,6 @@
122 122  
123 123 dbg("%s", __func__);
124 124  
125   - if (serial == NULL)
126   - return;
127   -
128 125 for (i = 0; i < serial->num_ports; ++i)
129 126 serial_table[serial->minor + i] = NULL;
130 127 }
... ... @@ -142,7 +139,8 @@
142 139 serial->type->shutdown(serial);
143 140  
144 141 /* return the minor range that this device had */
145   - return_serial(serial);
  142 + if (serial->minor != SERIAL_TTY_NO_MINOR)
  143 + return_serial(serial);
146 144  
147 145 for (i = 0; i < serial->num_ports; ++i)
148 146 serial->port[i]->port.count = 0;
... ... @@ -575,6 +573,7 @@
575 573 serial->interface = interface;
576 574 kref_init(&serial->kref);
577 575 mutex_init(&serial->disc_mutex);
  576 + serial->minor = SERIAL_TTY_NO_MINOR;
578 577  
579 578 return serial;
580 579 }
include/linux/usb/serial.h
... ... @@ -17,7 +17,8 @@
17 17 #include <linux/mutex.h>
18 18  
19 19 #define SERIAL_TTY_MAJOR 188 /* Nice legal number now */
20   -#define SERIAL_TTY_MINORS 255 /* loads of devices :) */
  20 +#define SERIAL_TTY_MINORS 254 /* loads of devices :) */
  21 +#define SERIAL_TTY_NO_MINOR 255 /* No minor was assigned */
21 22  
22 23 /* The maximum number of ports one device can grab at once */
23 24 #define MAX_NUM_PORTS 8