Commit 9636b683 authored by Elina Pasheva's avatar Elina Pasheva Committed by Greg Kroah-Hartman

USB: serial: sierra driver sierra_calc_num_ports() fix

- Removed potential kernel oops from sierra_calc_num_ports() function.
  Calling this function twice would likely have caused an oops because
  the function releases allocated memory after the first call.
- Modified sierra_probe() function to reflect the changes in
  sierra_calc_num_ports().
Signed-off-by: default avatarElina Pasheva <epasheva@sierrawireless.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent c76a23da
...@@ -83,18 +83,22 @@ static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable) ...@@ -83,18 +83,22 @@ static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable)
static int sierra_calc_num_ports(struct usb_serial *serial) static int sierra_calc_num_ports(struct usb_serial *serial)
{ {
int result; int num_ports = 0;
int *num_ports = usb_get_serial_data(serial); u8 ifnum, numendpoints;
dev_dbg(&serial->dev->dev, "%s\n", __func__);
result = *num_ports; dev_dbg(&serial->dev->dev, "%s\n", __func__);
if (result) { ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
kfree(num_ports); numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints;
usb_set_serial_data(serial, NULL);
}
return result; /* Dummy interface present on some SKUs should be ignored */
if (ifnum == 0x99)
num_ports = 0;
else if (numendpoints <= 3)
num_ports = 1;
else
num_ports = (numendpoints-1)/2;
return num_ports;
} }
static int is_blacklisted(const u8 ifnum, static int is_blacklisted(const u8 ifnum,
...@@ -140,23 +144,12 @@ static int sierra_probe(struct usb_serial *serial, ...@@ -140,23 +144,12 @@ static int sierra_probe(struct usb_serial *serial,
{ {
int result = 0; int result = 0;
struct usb_device *udev; struct usb_device *udev;
int *num_ports;
u8 ifnum; u8 ifnum;
u8 numendpoints;
dev_dbg(&serial->dev->dev, "%s\n", __func__);
num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL);
if (!num_ports)
return -ENOMEM;
ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints;
udev = serial->dev; udev = serial->dev;
dev_dbg(&udev->dev, "%s\n", __func__);
/* Figure out the interface number from the serial structure */
ifnum = sierra_calc_interface(serial); ifnum = sierra_calc_interface(serial);
/* /*
* If this interface supports more than 1 alternate * If this interface supports more than 1 alternate
* select the 2nd one * select the 2nd one
...@@ -168,20 +161,6 @@ static int sierra_probe(struct usb_serial *serial, ...@@ -168,20 +161,6 @@ static int sierra_probe(struct usb_serial *serial,
usb_set_interface(udev, ifnum, 1); usb_set_interface(udev, ifnum, 1);
} }
/* Dummy interface present on some SKUs should be ignored */
if (ifnum == 0x99)
*num_ports = 0;
else if (numendpoints <= 3)
*num_ports = 1;
else
*num_ports = (numendpoints-1)/2;
/*
* save off our num_ports info so that we can use it in the
* calc_num_ports callback
*/
usb_set_serial_data(serial, (void *)num_ports);
/* ifnum could have changed - by calling usb_set_interface */ /* ifnum could have changed - by calling usb_set_interface */
ifnum = sierra_calc_interface(serial); ifnum = sierra_calc_interface(serial);
......
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