Path: blob/master/drivers/edac/edac_device_sysfs.c
15111 views
/*1* file for managing the edac_device class of devices for EDAC2*3* (C) 2007 SoftwareBitMaker4*5* This file may be distributed under the terms of the6* GNU General Public License.7*8* Written Doug Thompson <[email protected]>9*10*/1112#include <linux/ctype.h>13#include <linux/module.h>14#include <linux/slab.h>15#include <linux/edac.h>1617#include "edac_core.h"18#include "edac_module.h"1920#define EDAC_DEVICE_SYMLINK "device"2122#define to_edacdev(k) container_of(k, struct edac_device_ctl_info, kobj)23#define to_edacdev_attr(a) container_of(a, struct edacdev_attribute, attr)242526/*27* Set of edac_device_ctl_info attribute store/show functions28*/2930/* 'log_ue' */31static ssize_t edac_device_ctl_log_ue_show(struct edac_device_ctl_info32*ctl_info, char *data)33{34return sprintf(data, "%u\n", ctl_info->log_ue);35}3637static ssize_t edac_device_ctl_log_ue_store(struct edac_device_ctl_info38*ctl_info, const char *data,39size_t count)40{41/* if parameter is zero, turn off flag, if non-zero turn on flag */42ctl_info->log_ue = (simple_strtoul(data, NULL, 0) != 0);4344return count;45}4647/* 'log_ce' */48static ssize_t edac_device_ctl_log_ce_show(struct edac_device_ctl_info49*ctl_info, char *data)50{51return sprintf(data, "%u\n", ctl_info->log_ce);52}5354static ssize_t edac_device_ctl_log_ce_store(struct edac_device_ctl_info55*ctl_info, const char *data,56size_t count)57{58/* if parameter is zero, turn off flag, if non-zero turn on flag */59ctl_info->log_ce = (simple_strtoul(data, NULL, 0) != 0);6061return count;62}6364/* 'panic_on_ue' */65static ssize_t edac_device_ctl_panic_on_ue_show(struct edac_device_ctl_info66*ctl_info, char *data)67{68return sprintf(data, "%u\n", ctl_info->panic_on_ue);69}7071static ssize_t edac_device_ctl_panic_on_ue_store(struct edac_device_ctl_info72*ctl_info, const char *data,73size_t count)74{75/* if parameter is zero, turn off flag, if non-zero turn on flag */76ctl_info->panic_on_ue = (simple_strtoul(data, NULL, 0) != 0);7778return count;79}8081/* 'poll_msec' show and store functions*/82static ssize_t edac_device_ctl_poll_msec_show(struct edac_device_ctl_info83*ctl_info, char *data)84{85return sprintf(data, "%u\n", ctl_info->poll_msec);86}8788static ssize_t edac_device_ctl_poll_msec_store(struct edac_device_ctl_info89*ctl_info, const char *data,90size_t count)91{92unsigned long value;9394/* get the value and enforce that it is non-zero, must be at least95* one millisecond for the delay period, between scans96* Then cancel last outstanding delay for the work request97* and set a new one.98*/99value = simple_strtoul(data, NULL, 0);100edac_device_reset_delay_period(ctl_info, value);101102return count;103}104105/* edac_device_ctl_info specific attribute structure */106struct ctl_info_attribute {107struct attribute attr;108ssize_t(*show) (struct edac_device_ctl_info *, char *);109ssize_t(*store) (struct edac_device_ctl_info *, const char *, size_t);110};111112#define to_ctl_info(k) container_of(k, struct edac_device_ctl_info, kobj)113#define to_ctl_info_attr(a) container_of(a,struct ctl_info_attribute,attr)114115/* Function to 'show' fields from the edac_dev 'ctl_info' structure */116static ssize_t edac_dev_ctl_info_show(struct kobject *kobj,117struct attribute *attr, char *buffer)118{119struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj);120struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr);121122if (ctl_info_attr->show)123return ctl_info_attr->show(edac_dev, buffer);124return -EIO;125}126127/* Function to 'store' fields into the edac_dev 'ctl_info' structure */128static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,129struct attribute *attr,130const char *buffer, size_t count)131{132struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj);133struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr);134135if (ctl_info_attr->store)136return ctl_info_attr->store(edac_dev, buffer, count);137return -EIO;138}139140/* edac_dev file operations for an 'ctl_info' */141static const struct sysfs_ops device_ctl_info_ops = {142.show = edac_dev_ctl_info_show,143.store = edac_dev_ctl_info_store144};145146#define CTL_INFO_ATTR(_name,_mode,_show,_store) \147static struct ctl_info_attribute attr_ctl_info_##_name = { \148.attr = {.name = __stringify(_name), .mode = _mode }, \149.show = _show, \150.store = _store, \151};152153/* Declare the various ctl_info attributes here and their respective ops */154CTL_INFO_ATTR(log_ue, S_IRUGO | S_IWUSR,155edac_device_ctl_log_ue_show, edac_device_ctl_log_ue_store);156CTL_INFO_ATTR(log_ce, S_IRUGO | S_IWUSR,157edac_device_ctl_log_ce_show, edac_device_ctl_log_ce_store);158CTL_INFO_ATTR(panic_on_ue, S_IRUGO | S_IWUSR,159edac_device_ctl_panic_on_ue_show,160edac_device_ctl_panic_on_ue_store);161CTL_INFO_ATTR(poll_msec, S_IRUGO | S_IWUSR,162edac_device_ctl_poll_msec_show, edac_device_ctl_poll_msec_store);163164/* Base Attributes of the EDAC_DEVICE ECC object */165static struct ctl_info_attribute *device_ctrl_attr[] = {166&attr_ctl_info_panic_on_ue,167&attr_ctl_info_log_ue,168&attr_ctl_info_log_ce,169&attr_ctl_info_poll_msec,170NULL,171};172173/*174* edac_device_ctrl_master_release175*176* called when the reference count for the 'main' kobj177* for a edac_device control struct reaches zero178*179* Reference count model:180* One 'main' kobject for each control structure allocated.181* That main kobj is initially set to one AND182* the reference count for the EDAC 'core' module is183* bumped by one, thus added 'keep in memory' dependency.184*185* Each new internal kobj (in instances and blocks) then186* bumps the 'main' kobject.187*188* When they are released their release functions decrement189* the 'main' kobj.190*191* When the main kobj reaches zero (0) then THIS function192* is called which then decrements the EDAC 'core' module.193* When the module reference count reaches zero then the194* module no longer has dependency on keeping the release195* function code in memory and module can be unloaded.196*197* This will support several control objects as well, each198* with its own 'main' kobj.199*/200static void edac_device_ctrl_master_release(struct kobject *kobj)201{202struct edac_device_ctl_info *edac_dev = to_edacdev(kobj);203204debugf4("%s() control index=%d\n", __func__, edac_dev->dev_idx);205206/* decrement the EDAC CORE module ref count */207module_put(edac_dev->owner);208209/* free the control struct containing the 'main' kobj210* passed in to this routine211*/212kfree(edac_dev);213}214215/* ktype for the main (master) kobject */216static struct kobj_type ktype_device_ctrl = {217.release = edac_device_ctrl_master_release,218.sysfs_ops = &device_ctl_info_ops,219.default_attrs = (struct attribute **)device_ctrl_attr,220};221222/*223* edac_device_register_sysfs_main_kobj224*225* perform the high level setup for the new edac_device instance226*227* Return: 0 SUCCESS228* !0 FAILURE229*/230int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)231{232struct sysdev_class *edac_class;233int err;234235debugf1("%s()\n", __func__);236237/* get the /sys/devices/system/edac reference */238edac_class = edac_get_sysfs_class();239if (edac_class == NULL) {240debugf1("%s() no edac_class error\n", __func__);241err = -ENODEV;242goto err_out;243}244245/* Point to the 'edac_class' this instance 'reports' to */246edac_dev->edac_class = edac_class;247248/* Init the devices's kobject */249memset(&edac_dev->kobj, 0, sizeof(struct kobject));250251/* Record which module 'owns' this control structure252* and bump the ref count of the module253*/254edac_dev->owner = THIS_MODULE;255256if (!try_module_get(edac_dev->owner)) {257err = -ENODEV;258goto err_mod_get;259}260261/* register */262err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl,263&edac_class->kset.kobj,264"%s", edac_dev->name);265if (err) {266debugf1("%s()Failed to register '.../edac/%s'\n",267__func__, edac_dev->name);268goto err_kobj_reg;269}270kobject_uevent(&edac_dev->kobj, KOBJ_ADD);271272/* At this point, to 'free' the control struct,273* edac_device_unregister_sysfs_main_kobj() must be used274*/275276debugf4("%s() Registered '.../edac/%s' kobject\n",277__func__, edac_dev->name);278279return 0;280281/* Error exit stack */282err_kobj_reg:283module_put(edac_dev->owner);284285err_mod_get:286edac_put_sysfs_class();287288err_out:289return err;290}291292/*293* edac_device_unregister_sysfs_main_kobj:294* the '..../edac/<name>' kobject295*/296void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev)297{298debugf0("%s()\n", __func__);299debugf4("%s() name of kobject is: %s\n",300__func__, kobject_name(&dev->kobj));301302/*303* Unregister the edac device's kobject and304* allow for reference count to reach 0 at which point305* the callback will be called to:306* a) module_put() this module307* b) 'kfree' the memory308*/309kobject_put(&dev->kobj);310edac_put_sysfs_class();311}312313/* edac_dev -> instance information */314315/*316* Set of low-level instance attribute show functions317*/318static ssize_t instance_ue_count_show(struct edac_device_instance *instance,319char *data)320{321return sprintf(data, "%u\n", instance->counters.ue_count);322}323324static ssize_t instance_ce_count_show(struct edac_device_instance *instance,325char *data)326{327return sprintf(data, "%u\n", instance->counters.ce_count);328}329330#define to_instance(k) container_of(k, struct edac_device_instance, kobj)331#define to_instance_attr(a) container_of(a,struct instance_attribute,attr)332333/* DEVICE instance kobject release() function */334static void edac_device_ctrl_instance_release(struct kobject *kobj)335{336struct edac_device_instance *instance;337338debugf1("%s()\n", __func__);339340/* map from this kobj to the main control struct341* and then dec the main kobj count342*/343instance = to_instance(kobj);344kobject_put(&instance->ctl->kobj);345}346347/* instance specific attribute structure */348struct instance_attribute {349struct attribute attr;350ssize_t(*show) (struct edac_device_instance *, char *);351ssize_t(*store) (struct edac_device_instance *, const char *, size_t);352};353354/* Function to 'show' fields from the edac_dev 'instance' structure */355static ssize_t edac_dev_instance_show(struct kobject *kobj,356struct attribute *attr, char *buffer)357{358struct edac_device_instance *instance = to_instance(kobj);359struct instance_attribute *instance_attr = to_instance_attr(attr);360361if (instance_attr->show)362return instance_attr->show(instance, buffer);363return -EIO;364}365366/* Function to 'store' fields into the edac_dev 'instance' structure */367static ssize_t edac_dev_instance_store(struct kobject *kobj,368struct attribute *attr,369const char *buffer, size_t count)370{371struct edac_device_instance *instance = to_instance(kobj);372struct instance_attribute *instance_attr = to_instance_attr(attr);373374if (instance_attr->store)375return instance_attr->store(instance, buffer, count);376return -EIO;377}378379/* edac_dev file operations for an 'instance' */380static const struct sysfs_ops device_instance_ops = {381.show = edac_dev_instance_show,382.store = edac_dev_instance_store383};384385#define INSTANCE_ATTR(_name,_mode,_show,_store) \386static struct instance_attribute attr_instance_##_name = { \387.attr = {.name = __stringify(_name), .mode = _mode }, \388.show = _show, \389.store = _store, \390};391392/*393* Define attributes visible for the edac_device instance object394* Each contains a pointer to a show and an optional set395* function pointer that does the low level output/input396*/397INSTANCE_ATTR(ce_count, S_IRUGO, instance_ce_count_show, NULL);398INSTANCE_ATTR(ue_count, S_IRUGO, instance_ue_count_show, NULL);399400/* list of edac_dev 'instance' attributes */401static struct instance_attribute *device_instance_attr[] = {402&attr_instance_ce_count,403&attr_instance_ue_count,404NULL,405};406407/* The 'ktype' for each edac_dev 'instance' */408static struct kobj_type ktype_instance_ctrl = {409.release = edac_device_ctrl_instance_release,410.sysfs_ops = &device_instance_ops,411.default_attrs = (struct attribute **)device_instance_attr,412};413414/* edac_dev -> instance -> block information */415416#define to_block(k) container_of(k, struct edac_device_block, kobj)417#define to_block_attr(a) \418container_of(a, struct edac_dev_sysfs_block_attribute, attr)419420/*421* Set of low-level block attribute show functions422*/423static ssize_t block_ue_count_show(struct kobject *kobj,424struct attribute *attr, char *data)425{426struct edac_device_block *block = to_block(kobj);427428return sprintf(data, "%u\n", block->counters.ue_count);429}430431static ssize_t block_ce_count_show(struct kobject *kobj,432struct attribute *attr, char *data)433{434struct edac_device_block *block = to_block(kobj);435436return sprintf(data, "%u\n", block->counters.ce_count);437}438439/* DEVICE block kobject release() function */440static void edac_device_ctrl_block_release(struct kobject *kobj)441{442struct edac_device_block *block;443444debugf1("%s()\n", __func__);445446/* get the container of the kobj */447block = to_block(kobj);448449/* map from 'block kobj' to 'block->instance->controller->main_kobj'450* now 'release' the block kobject451*/452kobject_put(&block->instance->ctl->kobj);453}454455456/* Function to 'show' fields from the edac_dev 'block' structure */457static ssize_t edac_dev_block_show(struct kobject *kobj,458struct attribute *attr, char *buffer)459{460struct edac_dev_sysfs_block_attribute *block_attr =461to_block_attr(attr);462463if (block_attr->show)464return block_attr->show(kobj, attr, buffer);465return -EIO;466}467468/* Function to 'store' fields into the edac_dev 'block' structure */469static ssize_t edac_dev_block_store(struct kobject *kobj,470struct attribute *attr,471const char *buffer, size_t count)472{473struct edac_dev_sysfs_block_attribute *block_attr;474475block_attr = to_block_attr(attr);476477if (block_attr->store)478return block_attr->store(kobj, attr, buffer, count);479return -EIO;480}481482/* edac_dev file operations for a 'block' */483static const struct sysfs_ops device_block_ops = {484.show = edac_dev_block_show,485.store = edac_dev_block_store486};487488#define BLOCK_ATTR(_name,_mode,_show,_store) \489static struct edac_dev_sysfs_block_attribute attr_block_##_name = { \490.attr = {.name = __stringify(_name), .mode = _mode }, \491.show = _show, \492.store = _store, \493};494495BLOCK_ATTR(ce_count, S_IRUGO, block_ce_count_show, NULL);496BLOCK_ATTR(ue_count, S_IRUGO, block_ue_count_show, NULL);497498/* list of edac_dev 'block' attributes */499static struct edac_dev_sysfs_block_attribute *device_block_attr[] = {500&attr_block_ce_count,501&attr_block_ue_count,502NULL,503};504505/* The 'ktype' for each edac_dev 'block' */506static struct kobj_type ktype_block_ctrl = {507.release = edac_device_ctrl_block_release,508.sysfs_ops = &device_block_ops,509.default_attrs = (struct attribute **)device_block_attr,510};511512/* block ctor/dtor code */513514/*515* edac_device_create_block516*/517static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,518struct edac_device_instance *instance,519struct edac_device_block *block)520{521int i;522int err;523struct edac_dev_sysfs_block_attribute *sysfs_attrib;524struct kobject *main_kobj;525526debugf4("%s() Instance '%s' inst_p=%p block '%s' block_p=%p\n",527__func__, instance->name, instance, block->name, block);528debugf4("%s() block kobj=%p block kobj->parent=%p\n",529__func__, &block->kobj, &block->kobj.parent);530531/* init this block's kobject */532memset(&block->kobj, 0, sizeof(struct kobject));533534/* bump the main kobject's reference count for this controller535* and this instance is dependent on the main536*/537main_kobj = kobject_get(&edac_dev->kobj);538if (!main_kobj) {539err = -ENODEV;540goto err_out;541}542543/* Add this block's kobject */544err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl,545&instance->kobj,546"%s", block->name);547if (err) {548debugf1("%s() Failed to register instance '%s'\n",549__func__, block->name);550kobject_put(main_kobj);551err = -ENODEV;552goto err_out;553}554555/* If there are driver level block attributes, then added them556* to the block kobject557*/558sysfs_attrib = block->block_attributes;559if (sysfs_attrib && block->nr_attribs) {560for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) {561562debugf4("%s() creating block attrib='%s' "563"attrib->%p to kobj=%p\n",564__func__,565sysfs_attrib->attr.name,566sysfs_attrib, &block->kobj);567568/* Create each block_attribute file */569err = sysfs_create_file(&block->kobj,570&sysfs_attrib->attr);571if (err)572goto err_on_attrib;573}574}575kobject_uevent(&block->kobj, KOBJ_ADD);576577return 0;578579/* Error unwind stack */580err_on_attrib:581kobject_put(&block->kobj);582583err_out:584return err;585}586587/*588* edac_device_delete_block(edac_dev,block);589*/590static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev,591struct edac_device_block *block)592{593struct edac_dev_sysfs_block_attribute *sysfs_attrib;594int i;595596/* if this block has 'attributes' then we need to iterate over the list597* and 'remove' the attributes on this block598*/599sysfs_attrib = block->block_attributes;600if (sysfs_attrib && block->nr_attribs) {601for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) {602603/* remove each block_attrib file */604sysfs_remove_file(&block->kobj,605(struct attribute *) sysfs_attrib);606}607}608609/* unregister this block's kobject, SEE:610* edac_device_ctrl_block_release() callback operation611*/612kobject_put(&block->kobj);613}614615/* instance ctor/dtor code */616617/*618* edac_device_create_instance619* create just one instance of an edac_device 'instance'620*/621static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,622int idx)623{624int i, j;625int err;626struct edac_device_instance *instance;627struct kobject *main_kobj;628629instance = &edac_dev->instances[idx];630631/* Init the instance's kobject */632memset(&instance->kobj, 0, sizeof(struct kobject));633634instance->ctl = edac_dev;635636/* bump the main kobject's reference count for this controller637* and this instance is dependent on the main638*/639main_kobj = kobject_get(&edac_dev->kobj);640if (!main_kobj) {641err = -ENODEV;642goto err_out;643}644645/* Formally register this instance's kobject under the edac_device */646err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl,647&edac_dev->kobj, "%s", instance->name);648if (err != 0) {649debugf2("%s() Failed to register instance '%s'\n",650__func__, instance->name);651kobject_put(main_kobj);652goto err_out;653}654655debugf4("%s() now register '%d' blocks for instance %d\n",656__func__, instance->nr_blocks, idx);657658/* register all blocks of this instance */659for (i = 0; i < instance->nr_blocks; i++) {660err = edac_device_create_block(edac_dev, instance,661&instance->blocks[i]);662if (err) {663/* If any fail, remove all previous ones */664for (j = 0; j < i; j++)665edac_device_delete_block(edac_dev,666&instance->blocks[j]);667goto err_release_instance_kobj;668}669}670kobject_uevent(&instance->kobj, KOBJ_ADD);671672debugf4("%s() Registered instance %d '%s' kobject\n",673__func__, idx, instance->name);674675return 0;676677/* error unwind stack */678err_release_instance_kobj:679kobject_put(&instance->kobj);680681err_out:682return err;683}684685/*686* edac_device_remove_instance687* remove an edac_device instance688*/689static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev,690int idx)691{692struct edac_device_instance *instance;693int i;694695instance = &edac_dev->instances[idx];696697/* unregister all blocks in this instance */698for (i = 0; i < instance->nr_blocks; i++)699edac_device_delete_block(edac_dev, &instance->blocks[i]);700701/* unregister this instance's kobject, SEE:702* edac_device_ctrl_instance_release() for callback operation703*/704kobject_put(&instance->kobj);705}706707/*708* edac_device_create_instances709* create the first level of 'instances' for this device710* (ie 'cache' might have 'cache0', 'cache1', 'cache2', etc711*/712static int edac_device_create_instances(struct edac_device_ctl_info *edac_dev)713{714int i, j;715int err;716717debugf0("%s()\n", __func__);718719/* iterate over creation of the instances */720for (i = 0; i < edac_dev->nr_instances; i++) {721err = edac_device_create_instance(edac_dev, i);722if (err) {723/* unwind previous instances on error */724for (j = 0; j < i; j++)725edac_device_delete_instance(edac_dev, j);726return err;727}728}729730return 0;731}732733/*734* edac_device_delete_instances(edac_dev);735* unregister all the kobjects of the instances736*/737static void edac_device_delete_instances(struct edac_device_ctl_info *edac_dev)738{739int i;740741/* iterate over creation of the instances */742for (i = 0; i < edac_dev->nr_instances; i++)743edac_device_delete_instance(edac_dev, i);744}745746/* edac_dev sysfs ctor/dtor code */747748/*749* edac_device_add_main_sysfs_attributes750* add some attributes to this instance's main kobject751*/752static int edac_device_add_main_sysfs_attributes(753struct edac_device_ctl_info *edac_dev)754{755struct edac_dev_sysfs_attribute *sysfs_attrib;756int err = 0;757758sysfs_attrib = edac_dev->sysfs_attributes;759if (sysfs_attrib) {760/* iterate over the array and create an attribute for each761* entry in the list762*/763while (sysfs_attrib->attr.name != NULL) {764err = sysfs_create_file(&edac_dev->kobj,765(struct attribute*) sysfs_attrib);766if (err)767goto err_out;768769sysfs_attrib++;770}771}772773err_out:774return err;775}776777/*778* edac_device_remove_main_sysfs_attributes779* remove any attributes to this instance's main kobject780*/781static void edac_device_remove_main_sysfs_attributes(782struct edac_device_ctl_info *edac_dev)783{784struct edac_dev_sysfs_attribute *sysfs_attrib;785786/* if there are main attributes, defined, remove them. First,787* point to the start of the array and iterate over it788* removing each attribute listed from this device's instance's kobject789*/790sysfs_attrib = edac_dev->sysfs_attributes;791if (sysfs_attrib) {792while (sysfs_attrib->attr.name != NULL) {793sysfs_remove_file(&edac_dev->kobj,794(struct attribute *) sysfs_attrib);795sysfs_attrib++;796}797}798}799800/*801* edac_device_create_sysfs() Constructor802*803* accept a created edac_device control structure804* and 'export' it to sysfs. The 'main' kobj should already have been805* created. 'instance' and 'block' kobjects should be registered806* along with any 'block' attributes from the low driver. In addition,807* the main attributes (if any) are connected to the main kobject of808* the control structure.809*810* Return:811* 0 Success812* !0 Failure813*/814int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev)815{816int err;817struct kobject *edac_kobj = &edac_dev->kobj;818819debugf0("%s() idx=%d\n", __func__, edac_dev->dev_idx);820821/* go create any main attributes callers wants */822err = edac_device_add_main_sysfs_attributes(edac_dev);823if (err) {824debugf0("%s() failed to add sysfs attribs\n", __func__);825goto err_out;826}827828/* create a symlink from the edac device829* to the platform 'device' being used for this830*/831err = sysfs_create_link(edac_kobj,832&edac_dev->dev->kobj, EDAC_DEVICE_SYMLINK);833if (err) {834debugf0("%s() sysfs_create_link() returned err= %d\n",835__func__, err);836goto err_remove_main_attribs;837}838839/* Create the first level instance directories840* In turn, the nested blocks beneath the instances will841* be registered as well842*/843err = edac_device_create_instances(edac_dev);844if (err) {845debugf0("%s() edac_device_create_instances() "846"returned err= %d\n", __func__, err);847goto err_remove_link;848}849850851debugf4("%s() create-instances done, idx=%d\n",852__func__, edac_dev->dev_idx);853854return 0;855856/* Error unwind stack */857err_remove_link:858/* remove the sym link */859sysfs_remove_link(&edac_dev->kobj, EDAC_DEVICE_SYMLINK);860861err_remove_main_attribs:862edac_device_remove_main_sysfs_attributes(edac_dev);863864err_out:865return err;866}867868/*869* edac_device_remove_sysfs() destructor870*871* given an edac_device struct, tear down the kobject resources872*/873void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev)874{875debugf0("%s()\n", __func__);876877/* remove any main attributes for this device */878edac_device_remove_main_sysfs_attributes(edac_dev);879880/* remove the device sym link */881sysfs_remove_link(&edac_dev->kobj, EDAC_DEVICE_SYMLINK);882883/* walk the instance/block kobject tree, deconstructing it */884edac_device_delete_instances(edac_dev);885}886887888