Linus Lüssing wrote:
+/* Use this, if you are going to turn a [name]_enabled in bat_priv on or off */ +#define BAT_ATTR_SWITCH(_name, _mode, _post_func) \ +static ssize_t store_##_name(struct kobject *kobj, struct attribute *attr, \ + char *buff, size_t count) \ +{ \
struct device *dev = to_dev(kobj->parent); \
struct net_device *net_dev = to_net_dev(dev); \
struct bat_priv *bat_priv = netdev_priv(net_dev); \
void (*post_func)(struct net_device *) = _post_func; \
int ret; \
ret = store_switch_attr(buff, count, net_dev, (char *)attr->name,
\ + &bat_priv->_name##_enabled); \ + if (post_func && ret) \
post_func(net_dev); \
return ret; \
+} \ +static ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \ + char *buff) \ +{ \
struct device *dev = to_dev(kobj->parent); \
struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev)); \
return sprintf(buff, "%s\n", \
atomic_read(&bat_priv->_name##_enabled) == 0 ? \
"disabled" : "enabled"); \
+} \ +BAT_ATTR(_name, _mode, show_##_name, store_##_name)
Please change the last line (and the similar line) to "static BAT_ATTR(...."
And yes, I like the idea to remove some redundancy.
Best regards, Sven