Macro for SysFS attribute definition
authorFlorian Pose <fp@igh-essen.com>
Tue, 11 Apr 2006 10:17:30 +0000
changeset 184 2fc86cec12df
parent 183 8ae1e011e96c
child 185 af570302dcee
Macro for SysFS attribute definition
master/domain.c
master/globals.h
master/master.c
master/module.c
master/slave.c
--- a/master/domain.c	Tue Apr 11 10:05:21 2006 +0000
+++ b/master/domain.c	Tue Apr 11 10:17:30 2006 +0000
@@ -19,11 +19,7 @@
 
 /*****************************************************************************/
 
-static struct attribute attr_data_size = {
-    .name = "data_size",
-    .owner = THIS_MODULE,
-    .mode = S_IRUGO
-};
+EC_SYSFS_READ_ATTR(data_size);
 
 static struct attribute *def_attrs[] = {
     &attr_data_size,
--- a/master/globals.h	Tue Apr 11 10:05:21 2006 +0000
+++ b/master/globals.h	Tue Apr 11 10:17:30 2006 +0000
@@ -43,6 +43,14 @@
 #define EC_DBG(fmt, args...) \
     printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args)
 
+#define EC_LIT(X) #X
+#define EC_STR(X) EC_LIT(X)
+
+#define EC_SYSFS_READ_ATTR(NAME) \
+    static struct attribute attr_##NAME = { \
+        .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO \
+    }
+
 /*****************************************************************************/
 
 extern void ec_print_data(const uint8_t *, size_t);
--- a/master/master.c	Tue Apr 11 10:05:21 2006 +0000
+++ b/master/master.c	Tue Apr 11 10:17:30 2006 +0000
@@ -29,11 +29,7 @@
 
 /*****************************************************************************/
 
-static struct attribute attr_slave_count = {
-    .name = "slave_count",
-    .owner = THIS_MODULE,
-    .mode = S_IRUGO
-};
+EC_SYSFS_READ_ATTR(slave_count);
 
 static struct attribute *ec_def_attrs[] = {
     &attr_slave_count,
--- a/master/module.c	Tue Apr 11 10:05:21 2006 +0000
+++ b/master/module.c	Tue Apr 11 10:17:30 2006 +0000
@@ -22,6 +22,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 
+#include "globals.h"
 #include "master.h"
 #include "device.h"
 
@@ -32,9 +33,6 @@
 
 /*****************************************************************************/
 
-#define EC_LIT(X) #X
-#define EC_STR(X) EC_LIT(X)
-
 #define COMPILE_INFO "Revision " EC_STR(SVNREV) \
                      ", compiled by " EC_STR(USER) \
                      " at " __DATE__ " " __TIME__
--- a/master/slave.c	Tue Apr 11 10:05:21 2006 +0000
+++ b/master/slave.c	Tue Apr 11 10:17:30 2006 +0000
@@ -28,25 +28,11 @@
 
 /*****************************************************************************/
 
-static struct attribute attr_ring_position = {
-    .name = "ring_position", .owner = THIS_MODULE, .mode = S_IRUGO
-};
-
-static struct attribute attr_station_address = {
-    .name = "station_address", .owner = THIS_MODULE, .mode = S_IRUGO
-};
-
-static struct attribute attr_vendor_name = {
-    .name = "vendor_name", .owner = THIS_MODULE, .mode = S_IRUGO
-};
-
-static struct attribute attr_product_name = {
-    .name = "product_name", .owner = THIS_MODULE, .mode = S_IRUGO
-};
-
-static struct attribute attr_product_desc = {
-    .name = "product_description", .owner = THIS_MODULE, .mode = S_IRUGO
-};
+EC_SYSFS_READ_ATTR(ring_position);
+EC_SYSFS_READ_ATTR(station_address);
+EC_SYSFS_READ_ATTR(vendor_name);
+EC_SYSFS_READ_ATTR(product_name);
+EC_SYSFS_READ_ATTR(product_desc);
 
 static struct attribute *def_attrs[] = {
     &attr_ring_position,