提交 9636b683 编写于 作者: E Elina Pasheva 提交者: 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: NElina Pasheva <epasheva@sierrawireless.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 c76a23da
......@@ -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)
{
int result;
int *num_ports = usb_get_serial_data(serial);
dev_dbg(&serial->dev->dev, "%s\n", __func__);
int num_ports = 0;
u8 ifnum, numendpoints;
result = *num_ports;
dev_dbg(&serial->dev->dev, "%s\n", __func__);
if (result) {
kfree(num_ports);
usb_set_serial_data(serial, NULL);
}
ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints;
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,
......@@ -140,23 +144,12 @@ static int sierra_probe(struct usb_serial *serial,
{
int result = 0;
struct usb_device *udev;
int *num_ports;
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;
dev_dbg(&udev->dev, "%s\n", __func__);
/* Figure out the interface number from the serial structure */
ifnum = sierra_calc_interface(serial);
/*
* If this interface supports more than 1 alternate
* select the 2nd one
......@@ -168,20 +161,6 @@ static int sierra_probe(struct usb_serial *serial,
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 = sierra_calc_interface(serial);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册