From: "Linus Lüssing" <linus.luessing@web.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 4/4] batman-adv: Ommit storing struct device in sysfs functions
Date: Wed, 13 Oct 2010 00:22:05 +0200 [thread overview]
Message-ID: <1286922125-18097-5-git-send-email-linus.luessing@web.de> (raw)
In-Reply-To: <1286922125-18097-1-git-send-email-linus.luessing@web.de>
We actually do not need an extra struct device variable, therefore
replacing them with defines that directly get the bat_priv or
net_device. This further reduces the code size in bat_sysfs.c and
especially shortens some macros.
Signed-off-by: Linus Lüssing <linus.luessing@web.de>
---
bat_sysfs.c | 40 ++++++++++++++--------------------------
1 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/bat_sysfs.c b/bat_sysfs.c
index 0d58e9c..c20af1f 100644
--- a/bat_sysfs.c
+++ b/bat_sysfs.c
@@ -29,7 +29,9 @@
#include "vis.h"
#include "compat.h"
-#define to_dev(obj) container_of(obj, struct device, kobj)
+#define to_dev(obj) container_of(obj, struct device, kobj)
+#define kobj_to_netdev(obj) to_net_dev(to_dev(obj->parent))
+#define kobj_to_batpriv(obj) netdev_priv(kobj_to_netdev(obj))
/* Use this, if you have customized show and store functions */
#define BAT_ATTR(_name, _mode, _show, _store) \
@@ -44,8 +46,7 @@ struct bat_attribute bat_attr_##_name = { \
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 net_device *net_dev = kobj_to_netdev(kobj); \
struct bat_priv *bat_priv = netdev_priv(net_dev); \
return __store_bool_attr(buff, count, _post_func, attr, \
&bat_priv->_name, net_dev); \
@@ -55,9 +56,7 @@ ssize_t store_##_name(struct kobject *kobj, struct attribute *attr, \
ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \
char *buff) \
{ \
- 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); \
+ struct bat_priv *bat_priv = kobj_to_batpriv(kobj); \
return sprintf(buff, "%s\n", \
atomic_read(&bat_priv->_name) == 0 ? \
"disabled" : "enabled"); \
@@ -74,8 +73,7 @@ ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \
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 net_device *net_dev = kobj_to_netdev(kobj); \
struct bat_priv *bat_priv = netdev_priv(net_dev); \
return __store_uint_attr(buff, count, _min, _max, _post_func, \
attr, &bat_priv->_name, net_dev); \
@@ -85,9 +83,7 @@ ssize_t store_##_name(struct kobject *kobj, struct attribute *attr, \
ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \
char *buff) \
{ \
- 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); \
+ struct bat_priv *bat_priv = kobj_to_batpriv(kobj); \
return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \
} \
@@ -207,8 +203,7 @@ inline static ssize_t __store_uint_attr(char *buff, size_t count,
static ssize_t show_vis_mode(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));
+ struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
int vis_mode = atomic_read(&bat_priv->vis_mode);
return sprintf(buff, "%s\n",
@@ -219,8 +214,7 @@ static ssize_t show_vis_mode(struct kobject *kobj, struct attribute *attr,
static ssize_t store_vis_mode(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 net_device *net_dev = kobj_to_netdev(kobj);
struct bat_priv *bat_priv = netdev_priv(net_dev);
unsigned long val;
int ret, vis_mode_tmp = -1;
@@ -261,8 +255,7 @@ static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr,
static ssize_t show_gw_mode(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));
+ struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
int down, up, bytes_written;
int gw_mode = atomic_read(&bat_priv->gw_mode);
int gw_class = atomic_read(&bat_priv->gw_class);
@@ -295,9 +288,7 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr,
static ssize_t store_gw_mode(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 net_device *net_dev = kobj_to_netdev(kobj);
return gw_mode_set(net_dev, buff, count);
}
@@ -377,8 +368,7 @@ void sysfs_del_meshif(struct net_device *dev)
static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr,
char *buff)
{
- struct device *dev = to_dev(kobj->parent);
- struct net_device *net_dev = to_net_dev(dev);
+ struct net_device *net_dev = kobj_to_netdev(kobj);
struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
ssize_t length;
@@ -396,8 +386,7 @@ static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr,
static ssize_t store_mesh_iface(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 net_device *net_dev = kobj_to_netdev(kobj);
struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
int status_tmp = -1;
int ret;
@@ -450,8 +439,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr,
char *buff)
{
- struct device *dev = to_dev(kobj->parent);
- struct net_device *net_dev = to_net_dev(dev);
+ struct net_device *net_dev = kobj_to_netdev(kobj);
struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
ssize_t length;
--
1.7.1
next prev parent reply other threads:[~2010-10-12 22:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-12 22:22 [B.A.T.M.A.N.] Simplifying sysfs code Linus Lüssing
2010-10-12 22:22 ` [B.A.T.M.A.N.] [PATCH 1/4] batman-adv: Unify sysfs file names with their bat_priv atomics Linus Lüssing
2010-10-12 22:22 ` [B.A.T.M.A.N.] [PATCH 2/4] batman-adv: Wrapper functions for sysfs storing Linus Lüssing
2010-10-12 22:22 ` [B.A.T.M.A.N.] [PATCH 3/4] batman-adv: Introduce generic BAT_ATTR_* macros Linus Lüssing
2010-10-16 2:11 ` Sven Eckelmann
2010-10-17 17:31 ` [B.A.T.M.A.N.] [PATCHv2 " Linus Lüssing
2010-10-12 22:22 ` Linus Lüssing [this message]
2010-10-13 11:33 ` [B.A.T.M.A.N.] [PATCH 5/4] batman-adv: Make hop_penalty configurable via sysfs Linus Lüssing
2010-10-15 16:01 ` Marek Lindner
2010-10-18 10:01 ` [B.A.T.M.A.N.] [PATCH] batman-adv: Adding sysfs API documentation for hop_penalty Linus Lüssing
2010-10-18 10:11 ` Marek Lindner
2010-10-18 21:44 ` [B.A.T.M.A.N.] [PATCH] batman-adv: Adding sysfs ABI " Linus Lüssing
2010-10-23 1:46 ` Marek Lindner
2010-10-23 1:45 ` [B.A.T.M.A.N.] [PATCH 5/4] batman-adv: Make hop_penalty configurable via sysfs Marek Lindner
2010-10-15 16:06 ` [B.A.T.M.A.N.] Simplifying sysfs code Marek Lindner
2010-10-18 10:06 ` Marek Lindner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1286922125-18097-5-git-send-email-linus.luessing@web.de \
--to=linus.luessing@web.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox