Re: [PATCH v2] net: enetc: Replace ifdef with IS_ENABLED

From: Vladimir Oltean
Date: Tue Sep 03 2024 - 18:45:39 EST


Hi Martyn,

On Tue, Sep 03, 2024 at 03:04:18PM +0100, Martyn Welch wrote:
> The enetc driver uses ifdefs when checking whether
> CONFIG_FSL_ENETC_PTP_CLOCK is enabled in a number of places. This works
> if the driver is compiled in but fails if the driver is available as a
> kernel module. Replace the instances of ifdef with use of the IS_ENABLED
> macro, that will evaluate as true when this feature is built as a kernel
> module and follows the kernel's coding style.
>
> Cc: Vadim Fedorenko <vadim.fedorenko@xxxxxxxxx>
> Signed-off-by: Martyn Welch <martyn.welch@xxxxxxxxxxxxx>
> ---
>
> Changes since v1:
> - Switched from preprocessor conditionals to normal C conditionals.

Thanks for the patch. Can you please send a v3 rebased on the latest
net-next, which now contains commit 3dd261ca7f84 ("net: enetc: Remove
setting of RX software timestamp")? The change needs rethinking a bit.

Also, could you git format-patch --subject-prefix="PATCH net-next v3"
next time? The networking subsystem tends to require that from patch
submitters, to indicate the tree that the patch should be applied to.

> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
> index 5e684b23c5f5..a9402c1907bf 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
> @@ -853,24 +853,25 @@ static int enetc_get_ts_info(struct net_device *ndev,
> info->phc_index = -1;
> }
>
> -#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
> - info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
> - SOF_TIMESTAMPING_RX_HARDWARE |
> - SOF_TIMESTAMPING_RAW_HARDWARE |
> - SOF_TIMESTAMPING_TX_SOFTWARE |
> - SOF_TIMESTAMPING_RX_SOFTWARE |
> - SOF_TIMESTAMPING_SOFTWARE;
> -
> - info->tx_types = (1 << HWTSTAMP_TX_OFF) |
> - (1 << HWTSTAMP_TX_ON) |
> - (1 << HWTSTAMP_TX_ONESTEP_SYNC);
> - info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
> - (1 << HWTSTAMP_FILTER_ALL);
> -#else
> - info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
> - SOF_TIMESTAMPING_TX_SOFTWARE |
> - SOF_TIMESTAMPING_SOFTWARE;
> -#endif
> + if (IS_ENABLED(CONFIG_FSL_ENETC_PTP_CLOCK)) {
> + info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
> + SOF_TIMESTAMPING_RX_HARDWARE |
> + SOF_TIMESTAMPING_RAW_HARDWARE |
> + SOF_TIMESTAMPING_TX_SOFTWARE |
> + SOF_TIMESTAMPING_RX_SOFTWARE |
> + SOF_TIMESTAMPING_SOFTWARE;
> +
> + info->tx_types = (1 << HWTSTAMP_TX_OFF) |
> + (1 << HWTSTAMP_TX_ON) |
> + (1 << HWTSTAMP_TX_ONESTEP_SYNC);
> + info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
> + (1 << HWTSTAMP_FILTER_ALL);
> + } else {
> + info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
> + SOF_TIMESTAMPING_TX_SOFTWARE |
> + SOF_TIMESTAMPING_SOFTWARE;
> + }
> +

How about:

if (!IS_ENABLED()) {
info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE;
return 0;
}

info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
SOF_TIMESTAMPING_RX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE |
SOF_TIMESTAMPING_TX_SOFTWARE;

info->tx_types = (1 << HWTSTAMP_TX_OFF) |
(1 << HWTSTAMP_TX_ON) |
(1 << HWTSTAMP_TX_ONESTEP_SYNC);
info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
(1 << HWTSTAMP_FILTER_ALL);

return 0;
?

I think I prefer the style with the early return.

> return 0;
> }
>
> --
> 2.45.2