[openib-general] [PATCH] simplify sysfs slightly

Roland Dreier roland at topspin.com
Fri Sep 10 13:37:41 PDT 2004


Based on Greg's suggestion, I'm using the new __ATTR and __ATTR_RO
macros to shrink the code slightly:

Index: infiniband/core/ib_sysfs.c
===================================================================
--- infiniband/core/ib_sysfs.c	(revision 759)
+++ infiniband/core/ib_sysfs.c	(working copy)
@@ -37,13 +37,12 @@
 	ssize_t (*store)(struct ib_port *, struct port_attribute *, const char *buf, size_t count);
 };
 
-#define PORT_ATTR(_name, _mode, _show, _store) 		\
-struct port_attribute port_attr_##_name = { 		\
-	.attr  = { .name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
-	.show  = _show, 				\
-	.store = _store					\
-}
+#define PORT_ATTR(_name, _mode, _show, _store) \
+struct port_attribute port_attr_##_name = __ATTR(_name, _mode, _show, _store)
 
+#define PORT_ATTR_RO(_name) \
+struct port_attribute port_attr_##_name = __ATTR_RO(_name)
+
 struct port_table_attribute {
 	struct port_attribute attr;
 	int                   index;
@@ -66,8 +65,8 @@
 	.show = port_attr_show
 };
 
-static ssize_t show_port_state(struct ib_port *p, struct port_attribute *unused,
-			       char *buf)
+static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
+			  char *buf)
 {
 	struct ib_port_attr attr;
 	ssize_t ret;
@@ -90,8 +89,8 @@
 		       state_name[attr.state] : "UNKNOWN");
 }
 
-static ssize_t show_port_lid(struct ib_port *p, struct port_attribute *unused,
-			     char *buf)
+static ssize_t lid_show(struct ib_port *p, struct port_attribute *unused,
+			char *buf)
 {
 	struct ib_port_attr attr;
 	ssize_t ret;
@@ -103,8 +102,9 @@
 	return sprintf(buf, "0x%x\n", attr.lid);
 }
 
-static ssize_t show_port_lmc(struct ib_port *p, struct port_attribute *unused,
-			     char *buf)
+static ssize_t lid_mask_count_show(struct ib_port *p,
+				   struct port_attribute *unused,
+				   char *buf)
 {
 	struct ib_port_attr attr;
 	ssize_t ret;
@@ -116,8 +116,8 @@
 	return sprintf(buf, "%d\n", attr.lmc);
 }
 
-static ssize_t show_port_sm_lid(struct ib_port *p, struct port_attribute *unused,
-			     char *buf)
+static ssize_t sm_lid_show(struct ib_port *p, struct port_attribute *unused,
+			   char *buf)
 {
 	struct ib_port_attr attr;
 	ssize_t ret;
@@ -129,8 +129,8 @@
 	return sprintf(buf, "0x%x\n", attr.sm_lid);
 }
 
-static ssize_t show_port_sm_sl(struct ib_port *p, struct port_attribute *unused,
-			     char *buf)
+static ssize_t sm_sl_show(struct ib_port *p, struct port_attribute *unused,
+			  char *buf)
 {
 	struct ib_port_attr attr;
 	ssize_t ret;
@@ -142,7 +142,7 @@
 	return sprintf(buf, "%d\n", attr.sm_sl);
 }
 
-static ssize_t show_port_cap(struct ib_port *p, struct port_attribute *unused,
+static ssize_t cap_mask_show(struct ib_port *p, struct port_attribute *unused,
 			     char *buf)
 {
 	struct ib_port_attr attr;
@@ -155,12 +155,12 @@
 	return sprintf(buf, "0x%08x\n", attr.port_cap_flags);
 }
 
-static PORT_ATTR(state,          S_IRUGO, show_port_state, NULL);
-static PORT_ATTR(lid,            S_IRUGO, show_port_lid,   NULL);
-static PORT_ATTR(lid_mask_count, S_IRUGO, show_port_lmc,    NULL);
-static PORT_ATTR(sm_lid,         S_IRUGO, show_port_sm_lid, NULL);
-static PORT_ATTR(sm_sl,          S_IRUGO, show_port_sm_sl,  NULL);
-static PORT_ATTR(cap_mask,       S_IRUGO, show_port_cap,    NULL);
+static PORT_ATTR_RO(state);
+static PORT_ATTR_RO(lid);
+static PORT_ATTR_RO(lid_mask_count);
+static PORT_ATTR_RO(sm_lid);
+static PORT_ATTR_RO(sm_sl);
+static PORT_ATTR_RO(cap_mask);
 
 static struct attribute *port_default_attrs[] = {
 	&port_attr_state.attr,
@@ -517,7 +517,7 @@
 	return ret;
 }
 
-void ib_device_deregister_sysfs(struct ib_device *device)
+void ib_device_unregister_sysfs(struct ib_device *device)
 {
 	struct kobject *p, *t;
 	struct ib_port *port;





More information about the general mailing list