X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fedac%2Fedac_device_sysfs.c;h=53764577035f3f23d0e073991d368f99b8225479;hb=b2798bf0ec2cb5a17bfc1430c5ba6d971c436a03;hp=52769ae69bd2327785d716a86cb5d2be49d37687;hpb=1c3631ff1f805cb72644fcde02b7c58950f21cd5;p=linux-2.6 diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c index 52769ae69b..5376457703 100644 --- a/drivers/edac/edac_device_sysfs.c +++ b/drivers/edac/edac_device_sysfs.c @@ -200,7 +200,7 @@ static void edac_device_ctrl_master_release(struct kobject *kobj) { struct edac_device_ctl_info *edac_dev = to_edacdev(kobj); - debugf1("%s() control index=%d\n", __func__, edac_dev->dev_idx); + debugf4("%s() control index=%d\n", __func__, edac_dev->dev_idx); /* decrement the EDAC CORE module ref count */ module_put(edac_dev->owner); @@ -246,16 +246,6 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) /* Init the devices's kobject */ memset(&edac_dev->kobj, 0, sizeof(struct kobject)); - edac_dev->kobj.ktype = &ktype_device_ctrl; - - /* set this new device under the edac_class kobject */ - edac_dev->kobj.parent = &edac_class->kset.kobj; - - /* generate sysfs "..../edac/" */ - debugf1("%s() set name of kobject to: %s\n", __func__, edac_dev->name); - err = kobject_set_name(&edac_dev->kobj, "%s", edac_dev->name); - if (err) - goto err_out; /* Record which module 'owns' this control structure * and bump the ref count of the module @@ -268,18 +258,21 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) } /* register */ - err = kobject_register(&edac_dev->kobj); + err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl, + &edac_class->kset.kobj, + "%s", edac_dev->name); if (err) { debugf1("%s()Failed to register '.../edac/%s'\n", __func__, edac_dev->name); goto err_kobj_reg; } + kobject_uevent(&edac_dev->kobj, KOBJ_ADD); /* At this point, to 'free' the control struct, * edac_device_unregister_sysfs_main_kobj() must be used */ - debugf1("%s() Registered '.../edac/%s' kobject\n", + debugf4("%s() Registered '.../edac/%s' kobject\n", __func__, edac_dev->name); return 0; @@ -300,7 +293,7 @@ void edac_device_unregister_sysfs_main_kobj( struct edac_device_ctl_info *edac_dev) { debugf0("%s()\n", __func__); - debugf1("%s() name of kobject is: %s\n", + debugf4("%s() name of kobject is: %s\n", __func__, kobject_name(&edac_dev->kobj)); /* @@ -310,7 +303,7 @@ void edac_device_unregister_sysfs_main_kobj( * a) module_put() this module * b) 'kfree' the memory */ - kobject_unregister(&edac_dev->kobj); + kobject_put(&edac_dev->kobj); } /* edac_dev -> instance information */ @@ -416,22 +409,29 @@ static struct kobj_type ktype_instance_ctrl = { /* edac_dev -> instance -> block information */ +#define to_block(k) container_of(k, struct edac_device_block, kobj) +#define to_block_attr(a) \ + container_of(a, struct edac_dev_sysfs_block_attribute, attr) + /* * Set of low-level block attribute show functions */ -static ssize_t block_ue_count_show(struct edac_device_block *block, char *data) +static ssize_t block_ue_count_show(struct kobject *kobj, + struct attribute *attr, char *data) { + struct edac_device_block *block = to_block(kobj); + return sprintf(data, "%u\n", block->counters.ue_count); } -static ssize_t block_ce_count_show(struct edac_device_block *block, char *data) +static ssize_t block_ce_count_show(struct kobject *kobj, + struct attribute *attr, char *data) { + struct edac_device_block *block = to_block(kobj); + return sprintf(data, "%u\n", block->counters.ce_count); } -#define to_block(k) container_of(k, struct edac_device_block, kobj) -#define to_block_attr(a) container_of(a,struct block_attribute,attr) - /* DEVICE block kobject release() function */ static void edac_device_ctrl_block_release(struct kobject *kobj) { @@ -448,22 +448,16 @@ static void edac_device_ctrl_block_release(struct kobject *kobj) kobject_put(&block->instance->ctl->kobj); } -/* block specific attribute structure */ -struct block_attribute { - struct attribute attr; - ssize_t(*show) (struct edac_device_block *, char *); - ssize_t(*store) (struct edac_device_block *, const char *, size_t); -}; /* Function to 'show' fields from the edac_dev 'block' structure */ static ssize_t edac_dev_block_show(struct kobject *kobj, struct attribute *attr, char *buffer) { - struct edac_device_block *block = to_block(kobj); - struct block_attribute *block_attr = to_block_attr(attr); + struct edac_dev_sysfs_block_attribute *block_attr = + to_block_attr(attr); if (block_attr->show) - return block_attr->show(block, buffer); + return block_attr->show(kobj, attr, buffer); return -EIO; } @@ -472,11 +466,12 @@ static ssize_t edac_dev_block_store(struct kobject *kobj, struct attribute *attr, const char *buffer, size_t count) { - struct edac_device_block *block = to_block(kobj); - struct block_attribute *block_attr = to_block_attr(attr); + struct edac_dev_sysfs_block_attribute *block_attr; + + block_attr = to_block_attr(attr); if (block_attr->store) - return block_attr->store(block, buffer, count); + return block_attr->store(kobj, attr, buffer, count); return -EIO; } @@ -487,7 +482,7 @@ static struct sysfs_ops device_block_ops = { }; #define BLOCK_ATTR(_name,_mode,_show,_store) \ -static struct block_attribute attr_block_##_name = { \ +static struct edac_dev_sysfs_block_attribute attr_block_##_name = { \ .attr = {.name = __stringify(_name), .mode = _mode }, \ .show = _show, \ .store = _store, \ @@ -497,7 +492,7 @@ BLOCK_ATTR(ce_count, S_IRUGO, block_ce_count_show, NULL); BLOCK_ATTR(ue_count, S_IRUGO, block_ue_count_show, NULL); /* list of edac_dev 'block' attributes */ -static struct block_attribute *device_block_attr[] = { +static struct edac_dev_sysfs_block_attribute *device_block_attr[] = { &attr_block_ce_count, &attr_block_ue_count, NULL, @@ -524,18 +519,13 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, struct edac_dev_sysfs_block_attribute *sysfs_attrib; struct kobject *main_kobj; - debugf1("%s() Instance '%s' block '%s'\n", - __func__, instance->name, block->name); + debugf4("%s() Instance '%s' inst_p=%p block '%s' block_p=%p\n", + __func__, instance->name, instance, block->name, block); + debugf4("%s() block kobj=%p block kobj->parent=%p\n", + __func__, &block->kobj, &block->kobj.parent); /* init this block's kobject */ memset(&block->kobj, 0, sizeof(struct kobject)); - block->kobj.parent = &instance->kobj; - block->kobj.ktype = &ktype_block_ctrl; - block->instance = instance; - - err = kobject_set_name(&block->kobj, "%s", block->name); - if (err) - return err; /* bump the main kobject's reference count for this controller * and this instance is dependant on the main @@ -547,7 +537,9 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, } /* Add this block's kobject */ - err = kobject_register(&block->kobj); + err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl, + &instance->kobj, + "%s", block->name); if (err) { debugf1("%s() Failed to register instance '%s'\n", __func__, block->name); @@ -560,22 +552,29 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, * to the block kobject */ sysfs_attrib = block->block_attributes; - if (sysfs_attrib) { - for (i = 0; i < block->nr_attribs; i++) { + if (sysfs_attrib && block->nr_attribs) { + for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) { + + debugf4("%s() creating block attrib='%s' " + "attrib->%p to kobj=%p\n", + __func__, + sysfs_attrib->attr.name, + sysfs_attrib, &block->kobj); + + /* Create each block_attribute file */ err = sysfs_create_file(&block->kobj, - (struct attribute *) sysfs_attrib); + &sysfs_attrib->attr); if (err) goto err_on_attrib; - - sysfs_attrib++; } } + kobject_uevent(&block->kobj, KOBJ_ADD); return 0; /* Error unwind stack */ err_on_attrib: - kobject_unregister(&block->kobj); + kobject_put(&block->kobj); err_out: return err; @@ -595,7 +594,9 @@ static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev, */ sysfs_attrib = block->block_attributes; if (sysfs_attrib && block->nr_attribs) { - for (i = 0; i < block->nr_attribs; i++) { + for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) { + + /* remove each block_attrib file */ sysfs_remove_file(&block->kobj, (struct attribute *) sysfs_attrib); } @@ -604,7 +605,7 @@ static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev, /* unregister this block's kobject, SEE: * edac_device_ctrl_block_release() callback operation */ - kobject_unregister(&block->kobj); + kobject_put(&block->kobj); } /* instance ctor/dtor code */ @@ -626,15 +627,8 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, /* Init the instance's kobject */ memset(&instance->kobj, 0, sizeof(struct kobject)); - /* set this new device under the edac_device main kobject */ - instance->kobj.parent = &edac_dev->kobj; - instance->kobj.ktype = &ktype_instance_ctrl; instance->ctl = edac_dev; - err = kobject_set_name(&instance->kobj, "%s", instance->name); - if (err) - goto err_out; - /* bump the main kobject's reference count for this controller * and this instance is dependant on the main */ @@ -644,8 +638,9 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, goto err_out; } - /* Formally register this instance's kobject */ - err = kobject_register(&instance->kobj); + /* Formally register this instance's kobject under the edac_device */ + err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl, + &edac_dev->kobj, "%s", instance->name); if (err != 0) { debugf2("%s() Failed to register instance '%s'\n", __func__, instance->name); @@ -653,7 +648,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, goto err_out; } - debugf1("%s() now register '%d' blocks for instance %d\n", + debugf4("%s() now register '%d' blocks for instance %d\n", __func__, instance->nr_blocks, idx); /* register all blocks of this instance */ @@ -668,15 +663,16 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, goto err_release_instance_kobj; } } + kobject_uevent(&instance->kobj, KOBJ_ADD); - debugf1("%s() Registered instance %d '%s' kobject\n", + debugf4("%s() Registered instance %d '%s' kobject\n", __func__, idx, instance->name); return 0; /* error unwind stack */ err_release_instance_kobj: - kobject_unregister(&instance->kobj); + kobject_put(&instance->kobj); err_out: return err; @@ -701,7 +697,7 @@ static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev, /* unregister this instance's kobject, SEE: * edac_device_ctrl_instance_release() for callback operation */ - kobject_unregister(&instance->kobj); + kobject_put(&instance->kobj); } /* @@ -848,7 +844,7 @@ int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev) } - debugf0("%s() calling create-instances, idx=%d\n", + debugf4("%s() create-instances done, idx=%d\n", __func__, edac_dev->dev_idx); return 0;