From: Simon Horman <simon.horman@corigine.com>
To: Shenwei Wang <shenwei.wang@nxp.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
Fabio Estevam <festevam@gmail.com>,
dl-linux-imx <linux-imx@nxp.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Wong Vee Khee <veekhee@apple.com>,
Kurt Kanzenbach <kurt@linutronix.de>,
Mohammad Athari Bin Ismail <mohammad.athari.ismail@intel.com>,
Andrey Konovalov <andrey.konovalov@linaro.org>,
Jochen Henneberg <jh@henneberg-systemdesign.com>,
Tan Tee Min <tee.min.tan@linux.intel.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-stm32@st-md-mailman.stormreply.com"
<linux-stm32@st-md-mailman.stormreply.com>,
"imx@lists.linux.dev" <imx@lists.linux.dev>
Subject: Re: [EXT] Re: [PATCH v5 1/2] net: stmmac: add support for platform specific reset
Date: Tue, 4 Apr 2023 11:34:11 +0200 [thread overview]
Message-ID: <ZCvvE8l4dnMOEGQ2@corigine.com> (raw)
In-Reply-To: <AS8PR04MB91769E3A7396555DCAB43CC089929@AS8PR04MB9176.eurprd04.prod.outlook.com>
On Mon, Apr 03, 2023 at 10:16:46PM +0000, Shenwei Wang wrote:
>
>
> > -----Original Message-----
> > From: Simon Horman <simon.horman@corigine.com>
> > Sent: Monday, April 3, 2023 2:50 PM
> > To: Shenwei Wang <shenwei.wang@nxp.com>
> > Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
> > <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> > <pabeni@redhat.com>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> > <s.hauer@pengutronix.de>; Pengutronix Kernel Team <kernel@pengutronix.de>;
> > Giuseppe Cavallaro <peppe.cavallaro@st.com>; Alexandre Torgue
> > <alexandre.torgue@foss.st.com>; Jose Abreu <joabreu@synopsys.com>; Fabio
> > Estevam <festevam@gmail.com>; dl-linux-imx <linux-imx@nxp.com>; Maxime
> > Coquelin <mcoquelin.stm32@gmail.com>; Wong Vee Khee
> > <veekhee@apple.com>; Kurt Kanzenbach <kurt@linutronix.de>; Mohammad
> > Athari Bin Ismail <mohammad.athari.ismail@intel.com>; Andrey Konovalov
> > <andrey.konovalov@linaro.org>; Jochen Henneberg <jh@henneberg-
> > systemdesign.com>; Tan Tee Min <tee.min.tan@linux.intel.com>;
> > netdev@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-stm32@st-
> > md-mailman.stormreply.com; imx@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@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.
WARNING: multiple messages have this Message-ID (diff)
From: Simon Horman <simon.horman@corigine.com>
To: Shenwei Wang <shenwei.wang@nxp.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
Fabio Estevam <festevam@gmail.com>,
dl-linux-imx <linux-imx@nxp.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Wong Vee Khee <veekhee@apple.com>,
Kurt Kanzenbach <kurt@linutronix.de>,
Mohammad Athari Bin Ismail <mohammad.athari.ismail@intel.com>,
Andrey Konovalov <andrey.konovalov@linaro.org>,
Jochen Henneberg <jh@henneberg-systemdesign.com>,
Tan Tee Min <tee.min.tan@linux.intel.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-stm32@st-md-mailman.stormreply.com"
<linux-stm32@st-md-mailman.stormreply.com>,
"imx@lists.linux.dev" <imx@lists.linux.dev>
Subject: Re: [EXT] Re: [PATCH v5 1/2] net: stmmac: add support for platform specific reset
Date: Tue, 4 Apr 2023 11:34:11 +0200 [thread overview]
Message-ID: <ZCvvE8l4dnMOEGQ2@corigine.com> (raw)
In-Reply-To: <AS8PR04MB91769E3A7396555DCAB43CC089929@AS8PR04MB9176.eurprd04.prod.outlook.com>
On Mon, Apr 03, 2023 at 10:16:46PM +0000, Shenwei Wang wrote:
>
>
> > -----Original Message-----
> > From: Simon Horman <simon.horman@corigine.com>
> > Sent: Monday, April 3, 2023 2:50 PM
> > To: Shenwei Wang <shenwei.wang@nxp.com>
> > Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
> > <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> > <pabeni@redhat.com>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> > <s.hauer@pengutronix.de>; Pengutronix Kernel Team <kernel@pengutronix.de>;
> > Giuseppe Cavallaro <peppe.cavallaro@st.com>; Alexandre Torgue
> > <alexandre.torgue@foss.st.com>; Jose Abreu <joabreu@synopsys.com>; Fabio
> > Estevam <festevam@gmail.com>; dl-linux-imx <linux-imx@nxp.com>; Maxime
> > Coquelin <mcoquelin.stm32@gmail.com>; Wong Vee Khee
> > <veekhee@apple.com>; Kurt Kanzenbach <kurt@linutronix.de>; Mohammad
> > Athari Bin Ismail <mohammad.athari.ismail@intel.com>; Andrey Konovalov
> > <andrey.konovalov@linaro.org>; Jochen Henneberg <jh@henneberg-
> > systemdesign.com>; Tan Tee Min <tee.min.tan@linux.intel.com>;
> > netdev@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-stm32@st-
> > md-mailman.stormreply.com; imx@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@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.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-04-04 9:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-03 15:24 [PATCH v5 1/2] net: stmmac: add support for platform specific reset Shenwei Wang
2023-04-03 15:24 ` Shenwei Wang
2023-04-03 15:24 ` [PATCH v5 2/2] net: stmmac: dwmac-imx: use platform specific reset for imx93 SoCs Shenwei Wang
2023-04-03 15:24 ` Shenwei Wang
2023-04-03 19:51 ` Simon Horman
2023-04-03 19:51 ` Simon Horman
2023-04-03 19:49 ` [PATCH v5 1/2] net: stmmac: add support for platform specific reset Simon Horman
2023-04-03 19:49 ` Simon Horman
2023-04-03 22:16 ` [EXT] " Shenwei Wang
2023-04-03 22:16 ` Shenwei Wang
2023-04-04 9:34 ` Simon Horman [this message]
2023-04-04 9:34 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZCvvE8l4dnMOEGQ2@corigine.com \
--to=simon.horman@corigine.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrey.konovalov@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=jh@henneberg-systemdesign.com \
--cc=joabreu@synopsys.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=kurt@linutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=mohammad.athari.ismail@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peppe.cavallaro@st.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=shenwei.wang@nxp.com \
--cc=tee.min.tan@linux.intel.com \
--cc=veekhee@apple.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.