diff options
author | Jiri Slaby <jirislaby@gmail.com> | 2005-09-13 04:25:01 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-13 11:22:27 -0400 |
commit | 4aed0644d684428e811bb6944f032b460a3ab165 (patch) | |
tree | 4b69f949865fec1c42f7d90fb4d459483c38df5f | |
parent | 299cc3c166f7a11f6cc3b66aafbaf75c2aa0e0e2 (diff) |
[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>
-rw-r--r-- | drivers/base/attribute_container.c | 5 | ||||
-rw-r--r-- | drivers/base/class.c | 10 | ||||
-rw-r--r-- | drivers/base/firmware_class.c | 9 | ||||
-rw-r--r-- | drivers/base/map.c | 3 | ||||
-rw-r--r-- | drivers/base/platform.c | 3 |
5 files changed, 12 insertions, 18 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index 373e7b728fa7..6b2eb6f39b4d 100644 --- a/drivers/base/attribute_container.c +++ b/drivers/base/attribute_container.c | |||
@@ -152,12 +152,13 @@ attribute_container_add_device(struct device *dev, | |||
152 | 152 | ||
153 | if (!cont->match(cont, dev)) | 153 | if (!cont->match(cont, dev)) |
154 | continue; | 154 | continue; |
155 | ic = kmalloc(sizeof(struct internal_container), GFP_KERNEL); | 155 | |
156 | ic = kzalloc(sizeof(*ic), GFP_KERNEL); | ||
156 | if (!ic) { | 157 | if (!ic) { |
157 | dev_printk(KERN_ERR, dev, "failed to allocate class container\n"); | 158 | dev_printk(KERN_ERR, dev, "failed to allocate class container\n"); |
158 | continue; | 159 | continue; |
159 | } | 160 | } |
160 | memset(ic, 0, sizeof(struct internal_container)); | 161 | |
161 | ic->cont = cont; | 162 | ic->cont = cont; |
162 | class_device_initialize(&ic->classdev); | 163 | class_device_initialize(&ic->classdev); |
163 | ic->classdev.dev = get_device(dev); | 164 | ic->classdev.dev = get_device(dev); |
diff --git a/drivers/base/class.c b/drivers/base/class.c index d164c32a97ad..3b112e3542f8 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -189,12 +189,11 @@ struct class *class_create(struct module *owner, char *name) | |||
189 | struct class *cls; | 189 | struct class *cls; |
190 | int retval; | 190 | int retval; |
191 | 191 | ||
192 | cls = kmalloc(sizeof(struct class), GFP_KERNEL); | 192 | cls = kzalloc(sizeof(*cls), GFP_KERNEL); |
193 | if (!cls) { | 193 | if (!cls) { |
194 | retval = -ENOMEM; | 194 | retval = -ENOMEM; |
195 | goto error; | 195 | goto error; |
196 | } | 196 | } |
197 | memset(cls, 0x00, sizeof(struct class)); | ||
198 | 197 | ||
199 | cls->name = name; | 198 | cls->name = name; |
200 | cls->owner = owner; | 199 | cls->owner = owner; |
@@ -500,13 +499,13 @@ int class_device_add(struct class_device *class_dev) | |||
500 | /* add the needed attributes to this device */ | 499 | /* add the needed attributes to this device */ |
501 | if (MAJOR(class_dev->devt)) { | 500 | if (MAJOR(class_dev->devt)) { |
502 | struct class_device_attribute *attr; | 501 | struct class_device_attribute *attr; |
503 | attr = kmalloc(sizeof(*attr), GFP_KERNEL); | 502 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
504 | if (!attr) { | 503 | if (!attr) { |
505 | error = -ENOMEM; | 504 | error = -ENOMEM; |
506 | kobject_del(&class_dev->kobj); | 505 | kobject_del(&class_dev->kobj); |
507 | goto register_done; | 506 | goto register_done; |
508 | } | 507 | } |
509 | memset(attr, sizeof(*attr), 0x00); | 508 | |
510 | attr->attr.name = "dev"; | 509 | attr->attr.name = "dev"; |
511 | attr->attr.mode = S_IRUGO; | 510 | attr->attr.mode = S_IRUGO; |
512 | attr->attr.owner = parent->owner; | 511 | attr->attr.owner = parent->owner; |
@@ -577,12 +576,11 @@ struct class_device *class_device_create(struct class *cls, dev_t devt, | |||
577 | if (cls == NULL || IS_ERR(cls)) | 576 | if (cls == NULL || IS_ERR(cls)) |
578 | goto error; | 577 | goto error; |
579 | 578 | ||
580 | class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL); | 579 | class_dev = kzalloc(sizeof(*class_dev), GFP_KERNEL); |
581 | if (!class_dev) { | 580 | if (!class_dev) { |
582 | retval = -ENOMEM; | 581 | retval = -ENOMEM; |
583 | goto error; | 582 | goto error; |
584 | } | 583 | } |
585 | memset(class_dev, 0x00, sizeof(struct class_device)); | ||
586 | 584 | ||
587 | class_dev->devt = devt; | 585 | class_dev->devt = devt; |
588 | class_dev->dev = device; | 586 | class_dev->dev = device; |
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 5bfa2e9a7c26..4acb2c5733c3 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -301,9 +301,9 @@ fw_register_class_device(struct class_device **class_dev_p, | |||
301 | const char *fw_name, struct device *device) | 301 | const char *fw_name, struct device *device) |
302 | { | 302 | { |
303 | int retval; | 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 | GFP_KERNEL); | 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 | GFP_KERNEL); | 307 | GFP_KERNEL); |
308 | 308 | ||
309 | *class_dev_p = NULL; | 309 | *class_dev_p = NULL; |
@@ -313,8 +313,6 @@ fw_register_class_device(struct class_device **class_dev_p, | |||
313 | retval = -ENOMEM; | 313 | retval = -ENOMEM; |
314 | goto error_kfree; | 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 | init_completion(&fw_priv->completion); | 317 | init_completion(&fw_priv->completion); |
320 | fw_priv->attr_data = firmware_attr_data_tmpl; | 318 | fw_priv->attr_data = firmware_attr_data_tmpl; |
@@ -402,14 +400,13 @@ _request_firmware(const struct firmware **firmware_p, const char *name, | |||
402 | if (!firmware_p) | 400 | if (!firmware_p) |
403 | return -EINVAL; | 401 | return -EINVAL; |
404 | 402 | ||
405 | *firmware_p = firmware = kmalloc(sizeof (struct firmware), GFP_KERNEL); | 403 | *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); |
406 | if (!firmware) { | 404 | if (!firmware) { |
407 | printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", | 405 | printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", |
408 | __FUNCTION__); | 406 | __FUNCTION__); |
409 | retval = -ENOMEM; | 407 | retval = -ENOMEM; |
410 | goto out; | 408 | goto out; |
411 | } | 409 | } |
412 | memset(firmware, 0, sizeof (*firmware)); | ||
413 | 410 | ||
414 | retval = fw_setup_class_device(firmware, &class_dev, name, device, | 411 | retval = fw_setup_class_device(firmware, &class_dev, name, device, |
415 | hotplug); | 412 | hotplug); |
diff --git a/drivers/base/map.c b/drivers/base/map.c index 2f455d86793c..b449dae6f0d3 100644 --- a/drivers/base/map.c +++ b/drivers/base/map.c | |||
@@ -135,7 +135,7 @@ retry: | |||
135 | struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem) | 135 | struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem) |
136 | { | 136 | { |
137 | struct kobj_map *p = kmalloc(sizeof(struct kobj_map), GFP_KERNEL); | 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 | int i; | 139 | int i; |
140 | 140 | ||
141 | if ((p == NULL) || (base == NULL)) { | 141 | if ((p == NULL) || (base == NULL)) { |
@@ -144,7 +144,6 @@ struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct semaphore *sem) | |||
144 | return NULL; | 144 | return NULL; |
145 | } | 145 | } |
146 | 146 | ||
147 | memset(base, 0, sizeof(struct probe)); | ||
148 | base->dev = 1; | 147 | base->dev = 1; |
149 | base->range = ~0; | 148 | base->range = ~0; |
150 | base->get = base_probe; | 149 | base->get = base_probe; |
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 3a5f4c991797..361e204209eb 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -225,13 +225,12 @@ struct platform_device *platform_device_register_simple(char *name, unsigned int | |||
225 | struct platform_object *pobj; | 225 | struct platform_object *pobj; |
226 | int retval; | 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 | if (!pobj) { | 229 | if (!pobj) { |
230 | retval = -ENOMEM; | 230 | retval = -ENOMEM; |
231 | goto error; | 231 | goto error; |
232 | } | 232 | } |
233 | 233 | ||
234 | memset(pobj, 0, sizeof(*pobj)); | ||
235 | pobj->pdev.name = name; | 234 | pobj->pdev.name = name; |
236 | pobj->pdev.id = id; | 235 | pobj->pdev.id = id; |
237 | pobj->pdev.dev.release = platform_device_release_simple; | 236 | pobj->pdev.dev.release = platform_device_release_simple; |