From: Andrew Lunn <andrew@lunn.ch>
To: The list for a Better Approach To Mobile Ad-hoc Networking
<b.a.t.m.a.n@lists.open-mesh.org>
Subject: Re: [B.A.T.M.A.N.] [PATCH 2/5] batman-adv: Introduce generic BAT_ATTR_* macros
Date: Sun, 10 Oct 2010 10:45:27 +0200 [thread overview]
Message-ID: <20101010084527.GD19495@lunn.ch> (raw)
In-Reply-To: <20101010043931.GA32458@Sellars>
On Sun, Oct 10, 2010 at 06:39:31AM +0200, Linus L??ssing wrote:
> Especially for this commit, I'm not quite sure, if the usage of
> the macros is ok and appropritate or just a too extensive use / abuse
> of them. So comments highly appreciated :).
Just my personal preference. I suggest others comment as well.
> > +/* 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) \
I would probably break this up into 3 macros.
(And problem rename to BOOL instead of SWITCH.)
BAT_ATTR_STORE_SWITCH()
BAT_ATTR_SHOW_SWITCH()
BAT_ATTR_SWITCH()
where BAT_ATTR_SWITCH() just invokes the other two.
> > +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; \
> > +} \
Maybe turn the above into an inline function and then have the macro
define a tiny wrapper function which just calls the inline function?
> > +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"); \
> > +}
This is small enough that it is O.K. as a macro.
Then the same again for BAT_ATTR_UINT...
Andrew
next prev parent reply other threads:[~2010-10-10 8:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-10 4:29 [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: Wrapper functions for sysfs storing Linus Lüssing
2010-10-10 4:29 ` [B.A.T.M.A.N.] [PATCH 2/5] batman-adv: Introduce generic BAT_ATTR_* macros Linus Lüssing
2010-10-10 4:39 ` Linus Lüssing
2010-10-10 8:45 ` Andrew Lunn [this message]
2010-10-10 10:34 ` Sven Eckelmann
2010-10-10 12:42 ` Marek Lindner
2010-10-10 19:00 ` Linus Lüssing
2010-10-11 8:04 ` Sven Eckelmann
2010-10-10 4:29 ` [B.A.T.M.A.N.] [PATCH 3/5] batman-adv: Make hop_penalty configurable via sysfs Linus Lüssing
2010-10-10 12:49 ` Marek Lindner
2010-10-10 14:51 ` Linus Lüssing
2010-10-10 4:30 ` [B.A.T.M.A.N.] [PATCH 4/5] batman-adv: Make number of (re)broadcasts " Linus Lüssing
2010-10-10 12:53 ` Marek Lindner
2010-10-10 14:49 ` Linus Lüssing
2010-10-10 4:30 ` [B.A.T.M.A.N.] [PATCH 5/5] batman-adv: Fix resizing of broadcast seqno buffers on if deletion Linus Lüssing
2010-10-12 9:51 ` Marek Lindner
2010-10-10 8:12 ` [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: Wrapper functions for sysfs storing Andrew Lunn
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=20101010084527.GD19495@lunn.ch \
--to=andrew@lunn.ch \
--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