[RFC PATCH 2/2] drivers/core: Add support for devm_ functions

Guenter Roeck
2013-03-15T03:24:52Z

Add support for devm_device_create_file and devm_device_remove_file.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/base/core.c | 18 ++++++++++++++++++
include/linux/device.h | 4 ++++
2 files changed, 22 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 56536f4b0..76ff488 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -568,6 +568,16 @@ int device_create_file(struct device *dev,
return error;
}

+int devm_device_create_file(struct device *dev,
+ const struct device_attribute *attr)
+{
+ int error = 0;
+ if (dev)
+ error = devm_sysfs_create_file(dev, &attr->attr);
+ return error;
+}
+EXPORT_SYMBOL_GPL(devm_device_create_file);
+
/**
* device_remove_file - remove sysfs attribute file.
* @dev: device.
@@ -580,6 +590,14 @@ void device_remove_file(struct device *dev,
sysfs_remove_file(&dev->kobj, &attr->attr);
}

+void devm_device_remove_file(struct device *dev,
+ const struct device_attribute *attr)
+{
+ if (dev)
+ devm_sysfs_remove_file(dev, &attr->attr);
+}
+EXPORT_SYMBOL_GPL(devm_device_remove_file);
+
/**
* device_create_bin_file - create sysfs binary attribute file for device.
* @dev: device.
diff --git a/include/linux/device.h b/include/linux/device.h
index 9d6464e..1c56fb7 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -521,8 +521,12 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,

extern int device_create_file(struct device *device,
const struct device_attribute *entry);
+extern int devm_device_create_file(struct device *device,
+ const struct device_attribute *entry);
extern void device_remove_file(struct device *dev,
const struct device_attribute *attr);
+extern void devm_device_remove_file(struct device *dev,
+ const struct device_attribute *attr);
extern int __must_check device_create_bin_file(struct device *dev,
const struct bin_attribute *attr);
extern void device_remove_bin_file(struct device *dev,
--
1.7.9.7