From 30f849cf21d3af906d44b1c58ed692e6ffe2780e Mon Sep 17 00:00:00 2001 From: Stefan Achatz Date: Fri, 26 Nov 2010 19:57:29 +0000 Subject: [PATCH] --- yaml --- r: 227621 b: refs/heads/master c: c97415a72521071c235e0879f9a600014afd87b1 h: refs/heads/master i: 227619: 7e024ad5c3a8711f358bd78bc8eaf5af4c8b8dd1 v: v3 --- [refs] | 2 +- trunk/drivers/base/core.c | 41 ++++++++++++++++++++++++++++++++++-- trunk/include/linux/device.h | 1 + 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/[refs] b/[refs] index 573c1fde9011..177cd79f0763 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: a7153258b70ccbe3922fcee9ca4271d4f4c2bc55 +refs/heads/master: c97415a72521071c235e0879f9a600014afd87b1 diff --git a/trunk/drivers/base/core.c b/trunk/drivers/base/core.c index 6ed645411c40..761359261589 100644 --- a/trunk/drivers/base/core.c +++ b/trunk/drivers/base/core.c @@ -338,6 +338,35 @@ static void device_remove_attributes(struct device *dev, device_remove_file(dev, &attrs[i]); } +static int device_add_bin_attributes(struct device *dev, + struct bin_attribute *attrs) +{ + int error = 0; + int i; + + if (attrs) { + for (i = 0; attr_name(attrs[i]); i++) { + error = device_create_bin_file(dev, &attrs[i]); + if (error) + break; + } + if (error) + while (--i >= 0) + device_remove_bin_file(dev, &attrs[i]); + } + return error; +} + +static void device_remove_bin_attributes(struct device *dev, + struct bin_attribute *attrs) +{ + int i; + + if (attrs) + for (i = 0; attr_name(attrs[i]); i++) + device_remove_bin_file(dev, &attrs[i]); +} + static int device_add_groups(struct device *dev, const struct attribute_group **groups) { @@ -378,12 +407,15 @@ static int device_add_attrs(struct device *dev) error = device_add_attributes(dev, class->dev_attrs); if (error) return error; + error = device_add_bin_attributes(dev, class->dev_bin_attrs); + if (error) + goto err_remove_class_attrs; } if (type) { error = device_add_groups(dev, type->groups); if (error) - goto err_remove_class_attrs; + goto err_remove_class_bin_attrs; } error = device_add_groups(dev, dev->groups); @@ -395,6 +427,9 @@ static int device_add_attrs(struct device *dev) err_remove_type_groups: if (type) device_remove_groups(dev, type->groups); + err_remove_class_bin_attrs: + if (class) + device_remove_bin_attributes(dev, class->dev_bin_attrs); err_remove_class_attrs: if (class) device_remove_attributes(dev, class->dev_attrs); @@ -412,8 +447,10 @@ static void device_remove_attrs(struct device *dev) if (type) device_remove_groups(dev, type->groups); - if (class) + if (class) { device_remove_attributes(dev, class->dev_attrs); + device_remove_bin_attributes(dev, class->dev_bin_attrs); + } } diff --git a/trunk/include/linux/device.h b/trunk/include/linux/device.h index dd4895313468..032bdb5406a2 100644 --- a/trunk/include/linux/device.h +++ b/trunk/include/linux/device.h @@ -197,6 +197,7 @@ struct class { struct class_attribute *class_attrs; struct device_attribute *dev_attrs; + struct bin_attribute *dev_bin_attrs; struct kobject *dev_kobj; int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);