Commit 4aed0644 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

[PATCH] drivers/base/*: use kzalloc instead of kmalloc+memset

Fixes a bunch of memset bugs too.
Signed-off-by: default avatarLion Vollnhals <webmaster@schiggl.de>
Signed-off-by: default avatarJiri Slaby <xslaby@fi.muni.cz>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 299cc3c1
...@@ -152,12 +152,13 @@ attribute_container_add_device(struct device *dev, ...@@ -152,12 +152,13 @@ attribute_container_add_device(struct device *dev,
if (!cont->match(cont, dev)) if (!cont->match(cont, dev))
continue; continue;
ic = kmalloc(sizeof(struct internal_container), GFP_KERNEL);
ic = kzalloc(sizeof(*ic), GFP_KERNEL);
if (!ic) { if (!ic) {
dev_printk(KERN_ERR, dev, "failed to allocate class container\n"); dev_printk(KERN_ERR, dev, "failed to allocate class container\n");
continue; continue;
} }
memset(ic, 0, sizeof(struct internal_container));
ic->cont = cont; ic->cont = cont;
class_device_initialize(&ic->classdev); class_device_initialize(&ic->classdev);
ic->classdev.dev = get_device(dev); ic->classdev.dev = get_device(dev);
......
...@@ -189,12 +189,11 @@ struct class *class_create(struct module *owner, char *name) ...@@ -189,12 +189,11 @@ struct class *class_create(struct module *owner, char *name)
struct class *cls; struct class *cls;
int retval; int retval;
cls = kmalloc(sizeof(struct class), GFP_KERNEL); cls = kzalloc(sizeof(*cls), GFP_KERNEL);
if (!cls) { if (!cls) {
retval = -ENOMEM; retval = -ENOMEM;
goto error; goto error;
} }
memset(cls, 0x00, sizeof(struct class));
cls->name = name; cls->name = name;
cls->owner = owner; cls->owner = owner;
...@@ -500,13 +499,13 @@ int class_device_add(struct class_device *class_dev) ...@@ -500,13 +499,13 @@ int class_device_add(struct class_device *class_dev)
/* add the needed attributes to this device */ /* add the needed attributes to this device */
if (MAJOR(class_dev->devt)) { if (MAJOR(class_dev->devt)) {
struct class_device_attribute *attr; struct class_device_attribute *attr;
attr = kmalloc(sizeof(*attr), GFP_KERNEL); attr = kzalloc(sizeof(*attr), GFP_KERNEL);
if (!attr) { if (!attr) {
error = -ENOMEM; error = -ENOMEM;
kobject_del(&class_dev->kobj); kobject_del(&class_dev->kobj);
goto register_done; goto register_done;
} }
memset(attr, sizeof(*attr), 0x00);
attr->attr.name = "dev"; attr->attr.name = "dev";
attr->attr.mode = S_IRUGO; attr->attr.mode = S_IRUGO;
attr->attr.owner = parent->owner; attr->attr.owner = parent->owner;
...@@ -577,12 +576,11 @@ struct class_device *class_device_create(struct class *cls, dev_t devt, ...@@ -577,12 +576,11 @@ struct class_device *class_device_create(struct class *cls, dev_t devt,
if (cls == NULL || IS_ERR(cls)) if (cls == NULL || IS_ERR(cls))
goto error; goto error;
class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL); class_dev = kzalloc(sizeof(*class_dev), GFP_KERNEL);
if (!class_dev) { if (!class_dev) {
retval = -ENOMEM; retval = -ENOMEM;
goto error; goto error;
} }
memset(class_dev, 0x00, sizeof(struct class_device));
class_dev->devt = devt; class_dev->devt = devt;
class_dev->dev = device; class_dev->dev = device;
......
...@@ -301,9 +301,9 @@ fw_register_class_device(struct class_device **class_dev_p, ...@@ -301,9 +301,9 @@ fw_register_class_device(struct class_device **class_dev_p,
const char *fw_name, struct device *device) const char *fw_name, struct device *device)
{ {
int retval; int retval;
struct firmware_priv *fw_priv = kmalloc(sizeof (struct firmware_priv), struct firmware_priv *fw_priv = kzalloc(sizeof(*fw_priv),
GFP_KERNEL); GFP_KERNEL);
struct class_device *class_dev = kmalloc(sizeof (struct class_device), struct class_device *class_dev = kzalloc(sizeof(*class_dev),
GFP_KERNEL); GFP_KERNEL);
*class_dev_p = NULL; *class_dev_p = NULL;
...@@ -313,8 +313,6 @@ fw_register_class_device(struct class_device **class_dev_p, ...@@ -313,8 +313,6 @@ fw_register_class_device(struct class_device **class_dev_p,
retval = -ENOMEM; retval = -ENOMEM;
goto error_kfree; goto error_kfree;
} }
memset(fw_priv, 0, sizeof (*fw_priv));
memset(class_dev, 0, sizeof (*class_dev));
init_completion(&fw_priv->completion); init_completion(&fw_priv->completion);
fw_priv->attr_data = firmware_attr_data_tmpl; fw_priv->attr_data = firmware_attr_data_tmpl;
...@@ -402,14 +400,13 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ...@@ -402,14 +400,13 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
if (!firmware_p) if (!firmware_p)
return -EINVAL; return -EINVAL;
*firmware_p = firmware = kmalloc(sizeof (struct firmware), GFP_KERNEL); *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
if (!firmware) { if (!firmware) {
printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n",
__FUNCTION__); __FUNCTION__);
retval = -ENOMEM; retval = -ENOMEM;
goto out; goto out;
} }
memset(firmware, 0, sizeof (*firmware));
retval = fw_setup_class_device(firmware, &class_dev, name, device, retval = fw_setup_class_device(firmware, &class_dev, name, device,
hotplug); hotplug);
......
...@@ -135,7 +135,7 @@ struct kobject *kobj_lookup(struct kobj_map *domain, dev_t dev, int *index) ...@@ -135,7 +135,7 @@ struct kobject *kobj_lookup(struct kobj_map *domain, dev_t dev, int *index)
struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem) struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem)
{ {
struct kobj_map *p = kmalloc(sizeof(struct kobj_map), GFP_KERNEL); struct kobj_map *p = kmalloc(sizeof(struct kobj_map), GFP_KERNEL);
struct probe *base = kmalloc(sizeof(struct probe), GFP_KERNEL); struct probe *base = kzalloc(sizeof(*base), GFP_KERNEL);
int i; int i;
if ((p == NULL) || (base == NULL)) { if ((p == NULL) || (base == NULL)) {
...@@ -144,7 +144,6 @@ struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem) ...@@ -144,7 +144,6 @@ struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem)
return NULL; return NULL;
} }
memset(base, 0, sizeof(struct probe));
base->dev = 1; base->dev = 1;
base->range = ~0; base->range = ~0;
base->get = base_probe; base->get = base_probe;
......
...@@ -225,13 +225,12 @@ struct platform_device *platform_device_register_simple(char *name, unsigned int ...@@ -225,13 +225,12 @@ struct platform_device *platform_device_register_simple(char *name, unsigned int
struct platform_object *pobj; struct platform_object *pobj;
int retval; int retval;
pobj = kmalloc(sizeof(struct platform_object) + sizeof(struct resource) * num, GFP_KERNEL); pobj = kzalloc(sizeof(*pobj) + sizeof(struct resource) * num, GFP_KERNEL);
if (!pobj) { if (!pobj) {
retval = -ENOMEM; retval = -ENOMEM;
goto error; goto error;
} }
memset(pobj, 0, sizeof(*pobj));
pobj->pdev.name = name; pobj->pdev.name = name;
pobj->pdev.id = id; pobj->pdev.id = id;
pobj->pdev.dev.release = platform_device_release_simple; pobj->pdev.dev.release = platform_device_release_simple;
......
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