Re: [PATCH net-next 2/4] net: dsa: Add wrappers for overloaded ndo_ops

From: Andrew Lunn
Date: Sun Jul 19 2020 - 11:40:23 EST


> +#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.

Andrew