Skip to content

Commit 631025b

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: USB: don't use reset-resume if drivers don't support it USB: isp1760: Assign resource fields before adding hcd isight_firmware: Avoid crash on loading invalid firmware USB: fix build bug in USB_ISIGHTFW
2 parents aaef4d6 + 5340ba8 commit 631025b

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

drivers/usb/core/hub.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,48 @@ static void hub_stop(struct usb_hub *hub)
644644

645645
#ifdef CONFIG_PM
646646

647+
/* Try to identify which devices need USB-PERSIST handling */
648+
static int persistent_device(struct usb_device *udev)
649+
{
650+
int i;
651+
int retval;
652+
struct usb_host_config *actconfig;
653+
654+
/* Explicitly not marked persistent? */
655+
if (!udev->persist_enabled)
656+
return 0;
657+
658+
/* No active config? */
659+
actconfig = udev->actconfig;
660+
if (!actconfig)
661+
return 0;
662+
663+
/* FIXME! We should check whether it's open here or not! */
664+
665+
/*
666+
* Check that all the interface drivers have a
667+
* 'reset_resume' entrypoint
668+
*/
669+
retval = 0;
670+
for (i = 0; i < actconfig->desc.bNumInterfaces; i++) {
671+
struct usb_interface *intf;
672+
struct usb_driver *driver;
673+
674+
intf = actconfig->interface[i];
675+
if (!intf->dev.driver)
676+
continue;
677+
driver = to_usb_driver(intf->dev.driver);
678+
if (!driver->reset_resume)
679+
return 0;
680+
/*
681+
* We have at least one driver, and that one
682+
* has a reset_resume method.
683+
*/
684+
retval = 1;
685+
}
686+
return retval;
687+
}
688+
647689
static void hub_restart(struct usb_hub *hub, int type)
648690
{
649691
struct usb_device *hdev = hub->hdev;
@@ -689,8 +731,8 @@ static void hub_restart(struct usb_hub *hub, int type)
689731
* turn off the various status changes to prevent
690732
* khubd from disconnecting it later.
691733
*/
692-
if (udev->persist_enabled && status == 0 &&
693-
!(portstatus & USB_PORT_STAT_ENABLE)) {
734+
if (status == 0 && !(portstatus & USB_PORT_STAT_ENABLE) &&
735+
persistent_device(udev)) {
694736
if (portchange & USB_PORT_STAT_C_ENABLE)
695737
clear_port_feature(hub->hdev, port1,
696738
USB_PORT_FEAT_C_ENABLE);

drivers/usb/host/isp1760-hcd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,14 +2207,14 @@ struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq,
22072207
goto err_put;
22082208
}
22092209

2210-
ret = usb_add_hcd(hcd, irq, irqflags);
2211-
if (ret)
2212-
goto err_unmap;
2213-
22142210
hcd->irq = irq;
22152211
hcd->rsrc_start = res_start;
22162212
hcd->rsrc_len = res_len;
22172213

2214+
ret = usb_add_hcd(hcd, irq, irqflags);
2215+
if (ret)
2216+
goto err_unmap;
2217+
22182218
return hcd;
22192219

22202220
err_unmap:

drivers/usb/misc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ config USB_TEST
272272
config USB_ISIGHTFW
273273
tristate "iSight firmware loading support"
274274
depends on USB
275+
select FW_LOADER
275276
help
276277
This driver loads firmware for USB Apple iSight cameras, allowing
277278
them to be driven by the USB video class driver available at

drivers/usb/misc/isight_firmware.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ static int isight_firmware_load(struct usb_interface *intf,
3939
struct usb_device *dev = interface_to_usbdev(intf);
4040
int llen, len, req, ret = 0;
4141
const struct firmware *firmware;
42-
unsigned char *buf;
42+
unsigned char *buf = kmalloc(50, GFP_KERNEL);
4343
unsigned char data[4];
44-
char *ptr;
44+
u8 *ptr;
45+
46+
if (!buf)
47+
return -ENOMEM;
4548

4649
if (request_firmware(&firmware, "isight.fw", &dev->dev) != 0) {
4750
printk(KERN_ERR "Unable to load isight firmware\n");
@@ -59,7 +62,7 @@ static int isight_firmware_load(struct usb_interface *intf,
5962
goto out;
6063
}
6164

62-
while (1) {
65+
while (ptr+4 <= firmware->data+firmware->size) {
6366
memcpy(data, ptr, 4);
6467
len = (data[0] << 8 | data[1]);
6568
req = (data[2] << 8 | data[3]);
@@ -71,10 +74,14 @@ static int isight_firmware_load(struct usb_interface *intf,
7174
continue;
7275

7376
for (; len > 0; req += 50) {
74-
llen = len > 50 ? 50 : len;
77+
llen = min(len, 50);
7578
len -= llen;
76-
77-
buf = kmalloc(llen, GFP_KERNEL);
79+
if (ptr+llen > firmware->data+firmware->size) {
80+
printk(KERN_ERR
81+
"Malformed isight firmware");
82+
ret = -ENODEV;
83+
goto out;
84+
}
7885
memcpy(buf, ptr, llen);
7986

8087
ptr += llen;
@@ -89,16 +96,18 @@ static int isight_firmware_load(struct usb_interface *intf,
8996
goto out;
9097
}
9198

92-
kfree(buf);
9399
}
94100
}
101+
95102
if (usb_control_msg
96103
(dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, "\0", 1,
97104
300) != 1) {
98105
printk(KERN_ERR "isight firmware loading completion failed\n");
99106
ret = -ENODEV;
100107
}
108+
101109
out:
110+
kfree(buf);
102111
release_firmware(firmware);
103112
return ret;
104113
}

0 commit comments

Comments
 (0)