aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/class.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r--drivers/base/class.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c
index d164c32a97ad..ce23dc8c18c5 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;
@@ -671,6 +669,7 @@ void class_device_destroy(struct class *cls, dev_t devt)
671int class_device_rename(struct class_device *class_dev, char *new_name) 669int class_device_rename(struct class_device *class_dev, char *new_name)
672{ 670{
673 int error = 0; 671 int error = 0;
672 char *old_class_name = NULL, *new_class_name = NULL;
674 673
675 class_dev = class_device_get(class_dev); 674 class_dev = class_device_get(class_dev);
676 if (!class_dev) 675 if (!class_dev)
@@ -679,12 +678,24 @@ int class_device_rename(struct class_device *class_dev, char *new_name)
679 pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id, 678 pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
680 new_name); 679 new_name);
681 680
681 if (class_dev->dev)
682 old_class_name = make_class_name(class_dev);
683
682 strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN); 684 strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
683 685
684 error = kobject_rename(&class_dev->kobj, new_name); 686 error = kobject_rename(&class_dev->kobj, new_name);
685 687
688 if (class_dev->dev) {
689 new_class_name = make_class_name(class_dev);
690 sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj,
691 new_class_name);
692 sysfs_remove_link(&class_dev->dev->kobj, old_class_name);
693 }
686 class_device_put(class_dev); 694 class_device_put(class_dev);
687 695
696 kfree(old_class_name);
697 kfree(new_class_name);
698
688 return error; 699 return error;
689} 700}
690 701