[PATCH] usbcore: Use kzalloc instead of kmalloc/memset
This patch (as590) fixes up all the remaining places where usbcore can use kzalloc rather than kmalloc/memset. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
b724ae7796
commit
0a1ef3b5a7
@@ -188,10 +188,9 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = sizeof(struct usb_host_endpoint) * num_ep;
|
len = sizeof(struct usb_host_endpoint) * num_ep;
|
||||||
alt->endpoint = kmalloc(len, GFP_KERNEL);
|
alt->endpoint = kzalloc(len, GFP_KERNEL);
|
||||||
if (!alt->endpoint)
|
if (!alt->endpoint)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
memset(alt->endpoint, 0, len);
|
|
||||||
|
|
||||||
/* Parse all the endpoint descriptors */
|
/* Parse all the endpoint descriptors */
|
||||||
n = 0;
|
n = 0;
|
||||||
@@ -353,10 +352,9 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
|
len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
|
||||||
config->intf_cache[i] = intfc = kmalloc(len, GFP_KERNEL);
|
config->intf_cache[i] = intfc = kzalloc(len, GFP_KERNEL);
|
||||||
if (!intfc)
|
if (!intfc)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
memset(intfc, 0, len);
|
|
||||||
kref_init(&intfc->ref);
|
kref_init(&intfc->ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,16 +457,14 @@ int usb_get_configuration(struct usb_device *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
length = ncfg * sizeof(struct usb_host_config);
|
length = ncfg * sizeof(struct usb_host_config);
|
||||||
dev->config = kmalloc(length, GFP_KERNEL);
|
dev->config = kzalloc(length, GFP_KERNEL);
|
||||||
if (!dev->config)
|
if (!dev->config)
|
||||||
goto err2;
|
goto err2;
|
||||||
memset(dev->config, 0, length);
|
|
||||||
|
|
||||||
length = ncfg * sizeof(char *);
|
length = ncfg * sizeof(char *);
|
||||||
dev->rawdescriptors = kmalloc(length, GFP_KERNEL);
|
dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
|
||||||
if (!dev->rawdescriptors)
|
if (!dev->rawdescriptors)
|
||||||
goto err2;
|
goto err2;
|
||||||
memset(dev->rawdescriptors, 0, length);
|
|
||||||
|
|
||||||
buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
|
buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
|
@@ -210,10 +210,10 @@ err:
|
|||||||
static struct async *alloc_async(unsigned int numisoframes)
|
static struct async *alloc_async(unsigned int numisoframes)
|
||||||
{
|
{
|
||||||
unsigned int assize = sizeof(struct async) + numisoframes * sizeof(struct usb_iso_packet_descriptor);
|
unsigned int assize = sizeof(struct async) + numisoframes * sizeof(struct usb_iso_packet_descriptor);
|
||||||
struct async *as = kmalloc(assize, GFP_KERNEL);
|
struct async *as = kzalloc(assize, GFP_KERNEL);
|
||||||
|
|
||||||
if (!as)
|
if (!as)
|
||||||
return NULL;
|
return NULL;
|
||||||
memset(as, 0, assize);
|
|
||||||
as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL);
|
as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL);
|
||||||
if (!as->urb) {
|
if (!as->urb) {
|
||||||
kfree(as);
|
kfree(as);
|
||||||
|
@@ -744,10 +744,9 @@ struct usb_bus *usb_alloc_bus (struct usb_operations *op)
|
|||||||
{
|
{
|
||||||
struct usb_bus *bus;
|
struct usb_bus *bus;
|
||||||
|
|
||||||
bus = kmalloc (sizeof *bus, GFP_KERNEL);
|
bus = kzalloc (sizeof *bus, GFP_KERNEL);
|
||||||
if (!bus)
|
if (!bus)
|
||||||
return NULL;
|
return NULL;
|
||||||
memset(bus, 0, sizeof(struct usb_bus));
|
|
||||||
usb_bus_init (bus);
|
usb_bus_init (bus);
|
||||||
bus->op = op;
|
bus->op = op;
|
||||||
return bus;
|
return bus;
|
||||||
|
@@ -865,14 +865,12 @@ descriptor_error:
|
|||||||
/* We found a hub */
|
/* We found a hub */
|
||||||
dev_info (&intf->dev, "USB hub found\n");
|
dev_info (&intf->dev, "USB hub found\n");
|
||||||
|
|
||||||
hub = kmalloc(sizeof(*hub), GFP_KERNEL);
|
hub = kzalloc(sizeof(*hub), GFP_KERNEL);
|
||||||
if (!hub) {
|
if (!hub) {
|
||||||
dev_dbg (&intf->dev, "couldn't kmalloc hub struct\n");
|
dev_dbg (&intf->dev, "couldn't kmalloc hub struct\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(hub, 0, sizeof(*hub));
|
|
||||||
|
|
||||||
INIT_LIST_HEAD(&hub->event_list);
|
INIT_LIST_HEAD(&hub->event_list);
|
||||||
hub->intfdev = &intf->dev;
|
hub->intfdev = &intf->dev;
|
||||||
hub->hdev = hdev;
|
hub->hdev = hdev;
|
||||||
|
@@ -1350,7 +1350,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; n < nintf; ++n) {
|
for (; n < nintf; ++n) {
|
||||||
new_interfaces[n] = kmalloc(
|
new_interfaces[n] = kzalloc(
|
||||||
sizeof(struct usb_interface),
|
sizeof(struct usb_interface),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!new_interfaces[n]) {
|
if (!new_interfaces[n]) {
|
||||||
@@ -1391,7 +1391,6 @@ free_interfaces:
|
|||||||
struct usb_host_interface *alt;
|
struct usb_host_interface *alt;
|
||||||
|
|
||||||
cp->interface[i] = intf = new_interfaces[i];
|
cp->interface[i] = intf = new_interfaces[i];
|
||||||
memset(intf, 0, sizeof(*intf));
|
|
||||||
intfc = cp->intf_cache[i];
|
intfc = cp->intf_cache[i];
|
||||||
intf->altsetting = intfc->altsetting;
|
intf->altsetting = intfc->altsetting;
|
||||||
intf->num_altsetting = intfc->num_altsetting;
|
intf->num_altsetting = intfc->num_altsetting;
|
||||||
|
@@ -704,12 +704,10 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
|
|||||||
{
|
{
|
||||||
struct usb_device *dev;
|
struct usb_device *dev;
|
||||||
|
|
||||||
dev = kmalloc(sizeof(*dev), GFP_KERNEL);
|
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(dev, 0, sizeof(*dev));
|
|
||||||
|
|
||||||
bus = usb_bus_get(bus);
|
bus = usb_bus_get(bus);
|
||||||
if (!bus) {
|
if (!bus) {
|
||||||
kfree(dev);
|
kfree(dev);
|
||||||
|
Reference in New Issue
Block a user