[EXT] Re: [PATCH v5 1/2] net: stmmac: add support for platform specific reset

Simon Horman simon.horman at corigine.com
Tue Apr 4 02:34:11 PDT 2023


On Mon, Apr 03, 2023 at 10:16:46PM +0000, Shenwei Wang wrote:
> 
> 
> > -----Original Message-----
> > From: Simon Horman <simon.horman at corigine.com>
> > Sent: Monday, April 3, 2023 2:50 PM
> > To: Shenwei Wang <shenwei.wang at nxp.com>
> > Cc: David S. Miller <davem at davemloft.net>; Eric Dumazet
> > <edumazet at google.com>; Jakub Kicinski <kuba at kernel.org>; Paolo Abeni
> > <pabeni at redhat.com>; Shawn Guo <shawnguo at kernel.org>; Sascha Hauer
> > <s.hauer at pengutronix.de>; Pengutronix Kernel Team <kernel at pengutronix.de>;
> > Giuseppe Cavallaro <peppe.cavallaro at st.com>; Alexandre Torgue
> > <alexandre.torgue at foss.st.com>; Jose Abreu <joabreu at synopsys.com>; Fabio
> > Estevam <festevam at gmail.com>; dl-linux-imx <linux-imx at nxp.com>; Maxime
> > Coquelin <mcoquelin.stm32 at gmail.com>; Wong Vee Khee
> > <veekhee at apple.com>; Kurt Kanzenbach <kurt at linutronix.de>; Mohammad
> > Athari Bin Ismail <mohammad.athari.ismail at intel.com>; Andrey Konovalov
> > <andrey.konovalov at linaro.org>; Jochen Henneberg <jh at henneberg-
> > systemdesign.com>; Tan Tee Min <tee.min.tan at linux.intel.com>;
> > netdev at vger.kernel.org; linux-arm-kernel at lists.infradead.org; linux-stm32 at st-
> > md-mailman.stormreply.com; imx at lists.linux.dev
> > Subject: [EXT] Re: [PATCH v5 1/2] net: stmmac: add support for platform specific
> > reset
> > 
> > Caution: EXT Email
> > 
> > On Mon, Apr 03, 2023 at 10:24:07AM -0500, Shenwei Wang wrote:
> > > This patch adds support for platform-specific reset logic in the
> > > stmmac driver. Some SoCs require a different reset mechanism than the
> > > standard dwmac IP reset. To support these platforms, a new function
> > > pointer 'fix_soc_reset' is added to the plat_stmmacenet_data structure.
> > > The stmmac_reset in hwif.h is modified to call the 'fix_soc_reset'
> > > function if it exists. This enables the driver to use the
> > > platform-specific reset logic when necessary.
> > >
> > > Signed-off-by: Shenwei Wang <shenwei.wang at nxp.com>
> > > ---
> > >  v5:
> > >   - add the missing __iomem tag in the stmmac_reset definition.
> > >
> > >  drivers/net/ethernet/stmicro/stmmac/hwif.c | 10 ++++++++++
> > > drivers/net/ethernet/stmicro/stmmac/hwif.h |  3 +--
> > >  include/linux/stmmac.h                     |  1 +
> > >  3 files changed, 12 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c
> > > b/drivers/net/ethernet/stmicro/stmmac/hwif.c
> > > index bb7114f970f8..0eefa697ffe8 100644
> > > --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c
> > > +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c
> > > @@ -87,6 +87,16 @@ static int stmmac_dwxlgmac_quirks(struct stmmac_priv
> > *priv)
> > >       return 0;
> > >  }
> > >
> > > +int stmmac_reset(struct stmmac_priv *priv, void __iomem *ioaddr) {
> > > +     struct plat_stmmacenet_data *plat = priv ? priv->plat : NULL;
> > 
> > Here the case where priv is NULL is handled.
> > 
> > > +
> > > +     if (plat && plat->fix_soc_reset)
> > > +             return plat->fix_soc_reset(plat, ioaddr);
> > > +
> > > +     return stmmac_do_callback(priv, dma, reset, ioaddr);
> > 
> > But this will dereference priv unconditionally.
> > 
> 
> The original macro implementation assumes that the priv pointer will not be NULL. However, adding 
> an extra condition check for priv in the stmmac_reset() function can ensure that the code is more 
> robust and secure.

But it seems to me that it is not safe because stmmac_do_callback
will dereference priv even if it is NULL.

So I think either the NULL case should be handled in a safe way.
Or there is no point in checking for it at all.



More information about the linux-arm-kernel mailing list