public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Driver Core patches for 2.6.7
Date: Tue, 22 Jun 2004 10:41:49 -0700	[thread overview]
Message-ID: <1087926109433@kroah.com> (raw)
In-Reply-To: <10879261084005@kroah.com>

ChangeSet 1.1722.85.6, 2004/06/03 17:37:14-07:00, mochel@digitalimplant.org

[Driver Model] Add default device attributes to struct bus_type.

- Add struct bus_type::dev_attrs, which is an array of device 
  attributes that are added to each device as they are registered.

 - Also make sure that we don't hang when removing bus attributes
   if adding one failed.. 


 drivers/base/bus.c     |   36 +++++++++++++++++++++++++++++++++++-
 include/linux/device.h |    1 +
 2 files changed, 36 insertions(+), 1 deletion(-)


diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c	Tue Jun 22 09:48:35 2004
+++ b/drivers/base/bus.c	Tue Jun 22 09:48:35 2004
@@ -392,6 +392,38 @@
 	
 }
 
+static int device_add_attrs(struct bus_type * bus, struct device * dev)
+{
+	int error = 0;
+	int i;
+
+	if (bus->dev_attrs) {
+		for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
+			error = device_create_file(dev,&bus->dev_attrs[i]);
+			if (error)
+				goto Err;
+		}
+	}
+ Done:
+	return error;
+ Err:
+	while (--i >= 0)
+		device_remove_file(dev,&bus->dev_attrs[i]);
+	goto Done;
+}
+
+
+static void device_remove_attrs(struct bus_type * bus, struct device * dev)
+{
+	int i;
+	
+	if (bus->dev_attrs) {
+		for (i = 0; attr_name(bus->dev_attrs[i]); i++)
+			device_remove_file(dev,&bus->dev_attrs[i]);
+	}
+}
+
+
 /**
  *	bus_add_device - add device to bus
  *	@dev:	device being added
@@ -411,6 +443,7 @@
 		list_add_tail(&dev->bus_list,&dev->bus->devices.list);
 		device_attach(dev);
 		up_write(&dev->bus->subsys.rwsem);
+		device_add_attrs(bus,dev);
 		sysfs_create_link(&bus->devices.kobj,&dev->kobj,dev->bus_id);
 	}
 	return error;
@@ -429,6 +462,7 @@
 {
 	if (dev->bus) {
 		sysfs_remove_link(&dev->bus->devices.kobj,dev->bus_id);
+		device_remove_attrs(dev->bus,dev);
 		down_write(&dev->bus->subsys.rwsem);
 		pr_debug("bus %s: remove device %s\n",dev->bus->name,dev->bus_id);
 		device_release_driver(dev);
@@ -569,7 +603,7 @@
  Done:
 	return error;
  Err:
-	while (i >= 0)
+	while (--i >= 0)
 		bus_remove_file(bus,&bus->bus_attrs[i]);
 	goto Done;
 }
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	Tue Jun 22 09:48:35 2004
+++ b/include/linux/device.h	Tue Jun 22 09:48:35 2004
@@ -55,6 +55,7 @@
 	struct kset		devices;
 
 	struct bus_attribute	* bus_attrs;
+	struct device_attribute	* dev_attrs;
 
 	int		(*match)(struct device * dev, struct device_driver * drv);
 	struct device * (*add)	(struct device * parent, char * bus_id);


  reply	other threads:[~2004-06-22 18:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-22 17:19 [BK PATCH] Driver Core patches for 2.6.7 Greg KH
2004-06-22 17:41 ` [PATCH] " Greg KH
2004-06-22 17:41   ` Greg KH
2004-06-22 17:41     ` Greg KH
2004-06-22 17:41       ` Greg KH
2004-06-22 17:41         ` Greg KH
2004-06-22 17:41           ` Greg KH [this message]
2004-06-22 17:41             ` Greg KH
2004-06-22 17:41               ` Greg KH
2004-06-22 17:41                 ` Greg KH
2004-06-22 17:41                   ` Greg KH
2004-06-22 17:41                     ` Greg KH
2004-06-22 17:41                       ` Greg KH
2004-06-22 17:41                         ` Greg KH
2004-06-22 17:41                           ` Greg KH
2004-06-22 17:41                             ` Greg KH
2004-06-22 17:41                               ` Greg KH
2004-06-22 17:41                                 ` Greg KH
2004-06-22 17:41                                   ` Greg KH
2004-06-22 17:41                                     ` Greg KH
2004-06-22 17:41                                       ` Greg KH
2004-06-22 17:41                                         ` Greg KH
2004-06-22 17:41                                           ` Greg KH
2004-06-22 17:41                                             ` Greg KH
2004-06-22 17:41                                               ` Greg KH
2004-06-22 17:41                                                 ` Greg KH
2004-06-22 17:41                                                   ` Greg KH
2004-06-22 17:41                                                     ` Greg KH
2004-06-22 17:41                                                       ` Greg KH
2004-06-22 17:41                                                         ` Greg KH
2004-06-22 17:41                                                           ` Greg KH
2004-06-22 17:41                                                             ` Greg KH
2004-06-22 17:41                                                               ` Greg KH
2004-06-22 17:41                                                                 ` Greg KH
2004-06-22 17:41                                                                   ` Greg KH
2004-06-22 17:41                                                                     ` Greg KH
2004-06-22 23:21         ` Dmitry Torokhov
2004-06-22 23:31           ` Greg KH
2004-06-22 23:44             ` Dmitry Torokhov
2004-06-22 23:51               ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1087926109433@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox