Re: [PATCH v2] net: enetc: Replace ifdef with IS_ENABLED
From: Martyn Welch
Date: Wed Sep 04 2024 - 05:00:46 EST
On Wed, 2024-09-04 at 01:44 +0300, Vladimir Oltean wrote:
> 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.
>
Sure no worries.
> 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_HARDWA
> > RE |
> > + SOF_TIMESTAMPING_RAW_HARDW
> > ARE |
> > + SOF_TIMESTAMPING_TX_SOFTWA
> > RE |
> > + SOF_TIMESTAMPING_RX_SOFTWA
> > RE |
> > + 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_SOFTWA
> > RE |
> > + 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.
>
Works for me. I'd actually considered that whilst reworking from v1,
but decided to keep the flow close to what it currently was.
Martyn
> > return 0;
> > }
> >
> > --
> > 2.45.2