From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: gregkh@suse.de
Cc: linux-kernel@vger.kernel.org, Cornelia Huck <cornelia.huck@de.ibm.com>
Subject: [patch 1/3] driver core: Introduce default attribute groups.
Date: Wed, 5 Dec 2007 12:50:23 +0100 [thread overview]
Message-ID: <20071205125023.50f4c478@gondolin.boeblingen.de.ibm.com> (raw)
In-Reply-To: <20071205114119.905238262@de.ibm.com>
This is lot like default attributes for devices (and indeed,
a lot of the code is lifted from there).
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
drivers/base/driver.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
include/linux/device.h | 2 ++
2 files changed, 45 insertions(+), 1 deletion(-)
Index: linux-2.6/drivers/base/driver.c
===================================================================
--- linux-2.6.orig/drivers/base/driver.c 2007-12-05 09:53:15.000000000 +0100
+++ linux-2.6/drivers/base/driver.c 2007-12-05 12:41:02.000000000 +0100
@@ -151,6 +151,39 @@ void put_driver(struct device_driver * d
kobject_put(&drv->p->kobj);
}
+static int driver_add_groups(struct device_driver *drv,
+ struct attribute_group **groups)
+{
+ int error = 0;
+ int i;
+ struct driver_private *priv = drv->p;
+
+ if (groups) {
+ for (i = 0; groups[i]; i++) {
+ error = sysfs_create_group(&priv->kobj, groups[i]);
+ if (error) {
+ while (--i >= 0)
+ sysfs_remove_group(&priv->kobj,
+ groups[i]);
+ break;
+ }
+ }
+ }
+ return error;
+}
+
+static void driver_remove_groups(struct device_driver *drv,
+ struct attribute_group **groups)
+{
+ int i;
+ struct driver_private *priv = drv->p;
+
+ if (groups)
+ for (i = 0; groups[i]; i++)
+ sysfs_remove_group(&priv->kobj, groups[i]);
+}
+
+
/**
* driver_register - register driver with bus
* @drv: driver to register
@@ -161,12 +194,20 @@ void put_driver(struct device_driver * d
*/
int driver_register(struct device_driver * drv)
{
+ int ret;
+
if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) ||
(drv->bus->shutdown && drv->shutdown)) {
printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
}
- return bus_add_driver(drv);
+ ret = bus_add_driver(drv);
+ if (ret)
+ return ret;
+ ret = driver_add_groups(drv, drv->groups);
+ if (ret)
+ bus_remove_driver(drv);
+ return ret;
}
/**
@@ -178,6 +219,7 @@ int driver_register(struct device_driver
void driver_unregister(struct device_driver * drv)
{
+ driver_remove_groups(drv, drv->groups);
bus_remove_driver(drv);
}
Index: linux-2.6/include/linux/device.h
===================================================================
--- linux-2.6.orig/include/linux/device.h 2007-12-05 09:53:15.000000000 +0100
+++ linux-2.6/include/linux/device.h 2007-12-05 12:25:36.000000000 +0100
@@ -126,6 +126,8 @@ struct device_driver {
int (*suspend) (struct device * dev, pm_message_t state);
int (*resume) (struct device * dev);
+ struct attribute_group **groups;
+
struct driver_private *p;
};
next parent reply other threads:[~2007-12-05 11:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071205114119.905238262@de.ibm.com>
2007-12-05 11:50 ` Cornelia Huck [this message]
2007-12-05 16:24 ` Greg KH
2007-12-05 11:50 ` [patch 2/3] netiucv: Use device_driver " Cornelia Huck
2007-12-05 11:50 ` [patch 3/3] zfcp: " Cornelia Huck
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=20071205125023.50f4c478@gondolin.boeblingen.de.ibm.com \
--to=cornelia.huck@de.ibm.com \
--cc=gregkh@suse.de \
--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
all inboxes | Powered by JetHome®