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

Reply via email to