Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Fixes a bunch of memset bugs too.

Signed-off-by: Lion Vollnhals <webmaster@schiggl.de>
Signed-off-by: Jiri Slaby <xslaby@fi.muni.cz>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Jiri Slaby and committed by
Linus Torvalds
4aed0644 299cc3c1

+12 -18
+3 -2
drivers/base/attribute_container.c
··· 152 152 153 153 if (!cont->match(cont, dev)) 154 154 continue; 155 - ic = kmalloc(sizeof(struct internal_container), GFP_KERNEL); 155 + 156 + ic = kzalloc(sizeof(*ic), GFP_KERNEL); 156 157 if (!ic) { 157 158 dev_printk(KERN_ERR, dev, "failed to allocate class container\n"); 158 159 continue; 159 160 } 160 - memset(ic, 0, sizeof(struct internal_container)); 161 + 161 162 ic->cont = cont; 162 163 class_device_initialize(&ic->classdev); 163 164 ic->classdev.dev = get_device(dev);
+4 -6
drivers/base/class.c
··· 189 189 struct class *cls; 190 190 int retval; 191 191 192 - cls = kmalloc(sizeof(struct class), GFP_KERNEL); 192 + cls = kzalloc(sizeof(*cls), GFP_KERNEL); 193 193 if (!cls) { 194 194 retval = -ENOMEM; 195 195 goto error; 196 196 } 197 - memset(cls, 0x00, sizeof(struct class)); 198 197 199 198 cls->name = name; 200 199 cls->owner = owner; ··· 499 500 /* add the needed attributes to this device */ 500 501 if (MAJOR(class_dev->devt)) { 501 502 struct class_device_attribute *attr; 502 - attr = kmalloc(sizeof(*attr), GFP_KERNEL); 503 + attr = kzalloc(sizeof(*attr), GFP_KERNEL); 503 504 if (!attr) { 504 505 error = -ENOMEM; 505 506 kobject_del(&class_dev->kobj); 506 507 goto register_done; 507 508 } 508 - memset(attr, sizeof(*attr), 0x00); 509 + 509 510 attr->attr.name = "dev"; 510 511 attr->attr.mode = S_IRUGO; 511 512 attr->attr.owner = parent->owner; ··· 576 577 if (cls == NULL || IS_ERR(cls)) 577 578 goto error; 578 579 579 - class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL); 580 + class_dev = kzalloc(sizeof(*class_dev), GFP_KERNEL); 580 581 if (!class_dev) { 581 582 retval = -ENOMEM; 582 583 goto error; 583 584 } 584 - memset(class_dev, 0x00, sizeof(struct class_device)); 585 585 586 586 class_dev->devt = devt; 587 587 class_dev->dev = device;
+3 -6
drivers/base/firmware_class.c
··· 301 301 const char *fw_name, struct device *device) 302 302 { 303 303 int retval; 304 - struct firmware_priv *fw_priv = kmalloc(sizeof (struct firmware_priv), 304 + struct firmware_priv *fw_priv = kzalloc(sizeof(*fw_priv), 305 305 GFP_KERNEL); 306 - struct class_device *class_dev = kmalloc(sizeof (struct class_device), 306 + struct class_device *class_dev = kzalloc(sizeof(*class_dev), 307 307 GFP_KERNEL); 308 308 309 309 *class_dev_p = NULL; ··· 313 313 retval = -ENOMEM; 314 314 goto error_kfree; 315 315 } 316 - memset(fw_priv, 0, sizeof (*fw_priv)); 317 - memset(class_dev, 0, sizeof (*class_dev)); 318 316 319 317 init_completion(&fw_priv->completion); 320 318 fw_priv->attr_data = firmware_attr_data_tmpl; ··· 400 402 if (!firmware_p) 401 403 return -EINVAL; 402 404 403 - *firmware_p = firmware = kmalloc(sizeof (struct firmware), GFP_KERNEL); 405 + *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); 404 406 if (!firmware) { 405 407 printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", 406 408 __FUNCTION__); 407 409 retval = -ENOMEM; 408 410 goto out; 409 411 } 410 - memset(firmware, 0, sizeof (*firmware)); 411 412 412 413 retval = fw_setup_class_device(firmware, &class_dev, name, device, 413 414 hotplug);
+1 -2
drivers/base/map.c
··· 135 135 struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem) 136 136 { 137 137 struct kobj_map *p = kmalloc(sizeof(struct kobj_map), GFP_KERNEL); 138 - struct probe *base = kmalloc(sizeof(struct probe), GFP_KERNEL); 138 + struct probe *base = kzalloc(sizeof(*base), GFP_KERNEL); 139 139 int i; 140 140 141 141 if ((p == NULL) || (base == NULL)) { ··· 144 144 return NULL; 145 145 } 146 146 147 - memset(base, 0, sizeof(struct probe)); 148 147 base->dev = 1; 149 148 base->range = ~0; 150 149 base->get = base_probe;
+1 -2
drivers/base/platform.c
··· 225 225 struct platform_object *pobj; 226 226 int retval; 227 227 228 - pobj = kmalloc(sizeof(struct platform_object) + sizeof(struct resource) * num, GFP_KERNEL); 228 + pobj = kzalloc(sizeof(*pobj) + sizeof(struct resource) * num, GFP_KERNEL); 229 229 if (!pobj) { 230 230 retval = -ENOMEM; 231 231 goto error; 232 232 } 233 233 234 - memset(pobj, 0, sizeof(*pobj)); 235 234 pobj->pdev.name = name; 236 235 pobj->pdev.id = id; 237 236 pobj->pdev.dev.release = platform_device_release_simple;