Skip to contentSkip to conversation

driver core: Introduce default attribute groups.

PATCH In review Cornelia Huck 2 participants 4 messages Dec 5, 2007 1 message not in the archive

Subsystems (6)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/3 driver core: Introduce default attribute groups.

This is lot like default attributes for devices (and indeed, a lot of the code is lifted from there).

---
 drivers/base/driver.c  |   44 +++++++++++++++++++++++++++++++++++++++++++-
 include/linux/device.h |    2 ++
 2 files changed, 45 insertions(+), 1 deletion(-)
drivers/base/driver.c +43 -1
Index: linux-2.6/drivers/base/driver.c
===================================================================
@@ -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);
 }
 
include/linux/device.h +2 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -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;
 };
 
#2 lore raw
Quoted 15 lines · Cornelia Huck

This is lot like default attributes for devices (and indeed, a lot of the code is lifted from there).

---
 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
===================================================================

drivers/base/driver.c void put_driver(struct device_driver * d · line 155

Quoted 5 lines
drivers/base/driver.c +2 -0
@@ -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)

Heh, I just added a driver_add_group() function, to fix up some other ppc driver :)

I'll delete that and use this series instead, it's nicer.

thanks,

greg k-h

#3 lore raw

PATCH 2/3 netiucv: Use device_driver default attribute groups.

In reply to a message not in the archive
---
 drivers/s390/net/netiucv.c |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)
drivers/s390/net/netiucv.c +6 -10
@@ -2089,6 +2089,11 @@ static struct attribute_group netiucv_dr
 	.attrs = netiucv_drv_attrs,
 };
 
+static struct attribute_group *netiucv_drv_attr_groups[] = {
+	&netiucv_drv_attr_group,
+	NULL,
+};
+
 static void netiucv_banner(void)
 {
 	PRINT_INFO("NETIUCV driver initialized\n");
@@ -2113,7 +2118,6 @@ static void __exit netiucv_exit(void)
 		netiucv_unregister_device(dev);
 	}
 
-	sysfs_remove_group(&netiucv_driver.kobj, &netiucv_drv_attr_group);
 	driver_unregister(&netiucv_driver);
 	iucv_unregister(&netiucv_handler, 1);
 	iucv_unregister_dbf_views();
@@ -2133,6 +2137,7 @@ static int __init netiucv_init(void)
 	if (rc)
 		goto out_dbf;
 	IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
+	netiucv_driver.groups = netiucv_drv_attr_groups;
 	rc = driver_register(&netiucv_driver);
 	if (rc) {
 		PRINT_ERR("NETIUCV: failed to register driver.\n");
@@ -2140,18 +2145,9 @@ static int __init netiucv_init(void)
 		goto out_iucv;
 	}
 
-	rc = sysfs_create_group(&netiucv_driver.kobj, &netiucv_drv_attr_group);
-	if (rc) {
-		PRINT_ERR("NETIUCV: failed to add driver attributes.\n");
-		IUCV_DBF_TEXT_(setup, 2,
-			       "ret %d - netiucv_drv_attr_group\n", rc);
-		goto out_driver;
-	}
 	netiucv_banner();
 	return rc;
 
-out_driver:
-	driver_unregister(&netiucv_driver);
 out_iucv:
 	iucv_unregister(&netiucv_handler, 1);
 out_dbf:
#4 lore raw

PATCH 3/3 zfcp: Use device_driver default attribute groups.

In reply to a message not in the archive
---
 drivers/s390/scsi/zfcp_ccw.c          |   14 ++++----------
 drivers/s390/scsi/zfcp_ext.h          |    3 +--
 drivers/s390/scsi/zfcp_sysfs_driver.c |   27 ++++-----------------------
 3 files changed, 9 insertions(+), 35 deletions(-)
drivers/s390/scsi/zfcp_ccw.c +4 -10
@@ -52,6 +52,9 @@ static struct ccw_driver zfcp_ccw_driver
 	.set_offline = zfcp_ccw_set_offline,
 	.notify      = zfcp_ccw_notify,
 	.shutdown    = zfcp_ccw_shutdown,
+	.driver = {
+		.groups = zfcp_driver_attr_groups,
+	},
 };
 
 MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
@@ -251,16 +254,7 @@ zfcp_ccw_notify(struct ccw_device *ccw_d
 int __init
 zfcp_ccw_register(void)
 {
-	int retval;
-
-	retval = ccw_driver_register(&zfcp_ccw_driver);
-	if (retval)
-		goto out;
-	retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
-	if (retval)
-		ccw_driver_unregister(&zfcp_ccw_driver);
- out:
-	return retval;
+	return ccw_driver_register(&zfcp_ccw_driver);
 }
 
 /**
drivers/s390/scsi/zfcp_ext.h +1 -2
@@ -27,8 +27,7 @@
 extern struct zfcp_data zfcp_data;
 
 /******************************** SYSFS  *************************************/
-extern int  zfcp_sysfs_driver_create_files(struct device_driver *);
-extern void zfcp_sysfs_driver_remove_files(struct device_driver *);
+extern struct attribute_group *zfcp_driver_attr_groups[];
 extern int  zfcp_sysfs_adapter_create_files(struct device *);
 extern void zfcp_sysfs_adapter_remove_files(struct device *);
 extern int  zfcp_sysfs_port_create_files(struct device *, u32);
drivers/s390/scsi/zfcp_sysfs_driver.c +4 -23
@@ -98,28 +98,9 @@ static struct attribute_group zfcp_drive
 	.attrs = zfcp_driver_attrs,
 };
 
-/**
- * zfcp_sysfs_create_driver_files - create sysfs driver files
- * @dev: pointer to belonging device
- *
- * Create all sysfs attributes of the zfcp device driver
- */
-int
-zfcp_sysfs_driver_create_files(struct device_driver *drv)
-{
-	return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
-}
-
-/**
- * zfcp_sysfs_remove_driver_files - remove sysfs driver files
- * @dev: pointer to belonging device
- *
- * Remove all sysfs attributes of the zfcp device driver
- */
-void
-zfcp_sysfs_driver_remove_files(struct device_driver *drv)
-{
-	sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
-}
+struct attribute_group *zfcp_driver_attr_groups[] = {
+	&zfcp_driver_attr_group,
+	NULL,
+};
 
 #undef ZFCP_LOG_AREA