LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] driver-core : get_device before create/remove sysfs files
@ 2008-01-30  1:56 Dave Young
  2008-01-30 10:32 ` Cornelia Huck
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Young @ 2008-01-30  1:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel

get dev reference before create/remove sysfiles, errno fixes as well.

Signed-off-by: Dave Young <hidave.darkstar@gmail.com> 

---
drivers/base/core.c |   12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff -upr a/drivers/base/core.c b/drivers/base/core.c
--- a/drivers/base/core.c	2008-01-30 09:49:56.000000000 +0800
+++ b/drivers/base/core.c	2008-01-30 09:49:56.000000000 +0800
@@ -414,7 +414,7 @@ struct kset *devices_kset;
  */
 int device_create_file(struct device *dev, struct device_attribute *attr)
 {
-	int error = 0;
+	int error = -ENODEV;
 	if (get_device(dev)) {
 		error = sysfs_create_file(&dev->kobj, &attr->attr);
 		put_device(dev);
@@ -442,9 +442,11 @@ void device_remove_file(struct device *d
  */
 int device_create_bin_file(struct device *dev, struct bin_attribute *attr)
 {
-	int error = -EINVAL;
-	if (dev)
+	int error = -ENODEV;
+	if (get_device(dev)) {
 		error = sysfs_create_bin_file(&dev->kobj, attr);
+		put_device(dev);
+	}
 	return error;
 }
 EXPORT_SYMBOL_GPL(device_create_bin_file);
@@ -456,8 +458,10 @@ EXPORT_SYMBOL_GPL(device_create_bin_file
  */
 void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
 {
-	if (dev)
+	if (get_device(dev)) {
 		sysfs_remove_bin_file(&dev->kobj, attr);
+		put_device(dev);
+	}
 }
 EXPORT_SYMBOL_GPL(device_remove_bin_file);
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-01-31  9:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-30  1:56 [PATCH] driver-core : get_device before create/remove sysfs files Dave Young
2008-01-30 10:32 ` Cornelia Huck
2008-01-31  1:17   ` Dave Young
2008-01-31  9:39     ` Cornelia Huck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).