[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <90674456-cacf-09a7-9e0f-fe292e039811@gmail.com>
Date: Sun, 19 Jul 2020 09:10:41 -0700
From: Florian Fainelli <f.fainelli@...il.com>
To: Andrew Lunn <andrew@...n.ch>
Cc: netdev@...r.kernel.org, Vivien Didelot <vivien.didelot@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Jiri Pirko <jiri@...lanox.com>,
Eric Dumazet <edumazet@...gle.com>,
Taehee Yoo <ap420073@...il.com>,
Cong Wang <xiyou.wangcong@...il.com>,
Maxim Mikityanskiy <maximmi@...lanox.com>,
Richard Cochran <richardcochran@...il.com>,
Michal Kubecek <mkubecek@...e.cz>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH net-next 2/4] net: dsa: Add wrappers for overloaded
ndo_ops
On 7/19/2020 8:40 AM, Andrew Lunn wrote:
>> +#if IS_ENABLED(CONFIG_NET_DSA)
>> +#define dsa_build_ndo_op(name, arg1_type, arg1_name, arg2_type, arg2_name) \
>> +static int inline dsa_##name(struct net_device *dev, arg1_type arg1_name, \
>> + arg2_type arg2_name) \
>> +{ \
>> + const struct dsa_netdevice_ops *ops; \
>> + int err = -EOPNOTSUPP; \
>> + \
>> + if (!dev->dsa_ptr) \
>> + return err; \
>> + \
>> + ops = dev->dsa_ptr->netdev_ops; \
>> + if (!ops || !ops->name) \
>> + return err; \
>> + \
>> + return ops->name(dev, arg1_name, arg2_name); \
>> +}
>> +#else
>> +#define dsa_build_ndo_op(name, ...) \
>> +static inline int dsa_##name(struct net_device *dev, ...) \
>> +{ \
>> + return -EOPNOTSUPP; \
>> +}
>> +#endif
>> +
>> +dsa_build_ndo_op(ndo_do_ioctl, struct ifreq *, ifr, int, cmd);
>> +dsa_build_ndo_op(ndo_get_phys_port_name, char *, name, size_t, len);
>
> Hi Florian
>
> I tend to avoid this sort of macro magic. Tools like
> https://elixir.bootlin.com/ and other cross references have trouble
> following it. The current macros only handle calls with two
> parameters. And i doubt it is actually saving many lines of code, if
> there are only two invocations.
It saves about 20 lines of code for each new function that is added.
Since the boilerplate logic is always the same, if you prefer I could
provide it as a separate helper function and avoid the macro to generate
the function body, yes let's do that.
--
Florian
Powered by blists - more mailing lists