diff mbox

[07/11] batman-adv: Adding batman_if specific sysfs wrapper macros for UINT

Message ID 1294966794-17780-8-git-send-email-linus.luessing@ascom.ch
State Superseded, archived
Headers show

Commit Message

Linus Lüssing Jan. 14, 2011, 12:59 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 |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/batman-adv/bat_sysfs.c b/batman-adv/bat_sysfs.c
index cd7bb51..5954389 100644
--- a/batman-adv/bat_sysfs.c
+++ b/batman-adv/bat_sysfs.c
@@ -94,6 +94,49 @@  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);	\
+	ssize_t length;							\
+									\
+	if (!batman_if)							\
+		return 0;						\
+									\
+	length = __store_uint_attr(buff, count, _min, _max, _post_func,	\
+				 attr, &batman_if->_name, net_dev);	\
+									\
+	kref_put(&batman_if->refcount, hardif_free_ref);		\
+	return length;							\
+}
+
+#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);	\
+	ssize_t length;							\
+									\
+	if (!batman_if)							\
+		return 0;						\
+									\
+	length = sprintf(buff, "%i\n", atomic_read(&batman_if->_name));	\
+									\
+	kref_put(&batman_if->refcount, hardif_free_ref);		\
+	return length;							\
+}
+
+/* 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)