diff --git a/master/domain.c b/master/domain.c index f361e2fb7ee121234045596c65c58381368e1dff..cf3f5cefb3d4bac58cb0bbe3bbcb7bc3bdb9b777 100644 --- a/master/domain.c +++ b/master/domain.c @@ -19,11 +19,7 @@ ssize_t ec_show_domain_attribute(struct kobject *, struct attribute *, char *); /*****************************************************************************/ -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, diff --git a/master/globals.h b/master/globals.h index 08807e9e424d3ce753020f2cc9682cacab2c3d65..d8f93e10e5365b5034384c7b96e3c50c78d1cf65 100644 --- a/master/globals.h +++ b/master/globals.h @@ -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); diff --git a/master/master.c b/master/master.c index 80ffd769a394d83352bf25360f077c4734e09998..347628c5cca633e2023cd0fa182e5171646a4046 100644 --- a/master/master.c +++ b/master/master.c @@ -29,11 +29,7 @@ ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *); /*****************************************************************************/ -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, diff --git a/master/module.c b/master/module.c index b4496e4e155f53c58d06002096cd8b2d924e957b..ab1a3717a027979905fe3f4be4e52c036e18fc82 100644 --- a/master/module.c +++ b/master/module.c @@ -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 @@ void __exit ec_cleanup_module(void); /*****************************************************************************/ -#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__ diff --git a/master/slave.c b/master/slave.c index afd30aed94221a1bd0a570e11ca4ba1a469c18d8..82a56a8133ad3d6ae2e5c8c6cc352751e4e21c9a 100644 --- a/master/slave.c +++ b/master/slave.c @@ -28,25 +28,11 @@ ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *); /*****************************************************************************/ -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,