Commit ec211cf2 authored by Jesse Barnes's avatar Jesse Barnes Committed by Greg Kroah-Hartman

[PATCH] USB: handle usb host allocation failures gracefully

It looks like a host (like ohci or whatever) could try to allocate a new
usb_device structure with usb_alloc_dev and get back a valid pointer even if
the allocation of its private data failed.  I first saw this in the 2.4
sources, but it looks like 2.6 has the same problem.  This patch attempts to
fix it by freeing dev if the ->allocate() routine fails, and then returns
NULL instead of a potentially dangerous dev pointer.
Signed-off-by: default avatarJesse Barnes <jbarnes@sgi.com>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 888df350
......@@ -775,7 +775,10 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port)
init_MUTEX(&dev->serialize);
if (dev->bus->op->allocate)
dev->bus->op->allocate(dev);
if (dev->bus->op->allocate(dev)) {
kfree(dev);
return NULL;
}
return dev;
}
......
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