[08/10] batman-adv: Adding batman_if specific sysfs wrapper macros for UINT

Message ID 1292320696-11983-9-git-send-email-linus.luessing@ascom.ch (mailing list archive)
State Superseded, archived
Headers

Commit Message

Linus Lüssing Dec. 14, 2010, 9:58 a.m. UTC
  This allows us to easily add a sysfs parameter for an unsigned int
later, which is not for a batman mesh interface (e.g. bat0), but for a
common interface instead. It allows reading and writing an atomic_t in
batman_if (instead of bat_priv compared to the mesh variant).

Signed-off-by: Linus Lüssing <linus.luessing@ascom.ch>
---
 bat_sysfs.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
  

Comments

Marek Lindner Dec. 28, 2010, 3:14 p.m. UTC | #1
On Tuesday 14 December 2010 10:58:14 Linus Lüssing wrote:
> +#define BAT_ATTR_IF_STORE_UINT(_name, _min, _max, _post_func)          \
> +ssize_t store_##_name(struct kobject *kobj, struct attribute *attr,    \
> +                            char *buff, size_t count)                  \
> +{                                                                      \
> +       struct net_device *net_dev = kobj_to_netdev(kobj);              \
> +       struct batman_if *batman_if = get_batman_if_by_netdev(net_dev); \
> +       return __store_uint_attr(buff, count, _min, _max, _post_func,   \
> +                                attr, &batman_if->_name, net_dev);     \
> +}
> +
> +#define BAT_ATTR_IF_SHOW_UINT(_name)                                   \
> +ssize_t show_##_name(struct kobject *kobj, struct attribute *attr,     \
> +                           char *buff)                                 \
> +{                                                                      \
> +       struct net_device *net_dev = kobj_to_netdev(kobj);              \
> +       struct batman_if *batman_if = get_batman_if_by_netdev(net_dev); \
> +       return sprintf(buff, "%i\n", atomic_read(&batman_if->_name));   \
> +}     

get_batman_if_by_netdev() increases the batman_if refcount which is never 
decreased. Check the other get_batman_if_by_netdev() calls in the same file to 
get an idea how to handle this,

Cheers,
Marek
  

Patch

diff --git a/bat_sysfs.c b/bat_sysfs.c
index cd7bb51..98c10a3 100644
--- a/bat_sysfs.c
+++ b/bat_sysfs.c
@@ -94,6 +94,33 @@  ssize_t show_##_name(struct kobject *kobj, struct attribute *attr,	\
 	static BAT_ATTR(_name, _mode, show_##_name, store_##_name)
 
 
+#define BAT_ATTR_IF_STORE_UINT(_name, _min, _max, _post_func)		\
+ssize_t store_##_name(struct kobject *kobj, struct attribute *attr,	\
+			     char *buff, size_t count)			\
+{									\
+	struct net_device *net_dev = kobj_to_netdev(kobj);		\
+	struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);	\
+	return __store_uint_attr(buff, count, _min, _max, _post_func,	\
+				 attr, &batman_if->_name, net_dev);	\
+}
+
+#define BAT_ATTR_IF_SHOW_UINT(_name)					\
+ssize_t show_##_name(struct kobject *kobj, struct attribute *attr,	\
+			    char *buff)					\
+{									\
+	struct net_device *net_dev = kobj_to_netdev(kobj);		\
+	struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);	\
+	return sprintf(buff, "%i\n", atomic_read(&batman_if->_name));	\
+}									\
+
+/* Use this, if you are going to set [name] in batman_if to unsigned integer
+ * values only */
+#define BAT_ATTR_IF_UINT(_name, _mode, _min, _max, _post_func)		\
+	static BAT_ATTR_IF_STORE_UINT(_name, _min, _max, _post_func)	\
+	static BAT_ATTR_IF_SHOW_UINT(_name)				\
+	static BAT_ATTR(_name, _mode, show_##_name, store_##_name)
+
+
 static int store_bool_attr(char *buff, size_t count,
 			   struct net_device *net_dev,
 			   char *attr_name, atomic_t *attr)