* [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro
@ 2022-10-21 11:47 Junxiao Chang
2022-10-21 11:47 ` [PATCH net-next 2/2] net: stmmac: remove duplicate dma queue channel macros Junxiao Chang
2022-10-25 4:00 ` [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro Jakub Kicinski
0 siblings, 2 replies; 4+ messages in thread
From: Junxiao Chang @ 2022-10-21 11:47 UTC (permalink / raw)
To: peppe.cavallaro, alexandre.torgue, joabreu, davem, edumazet, kuba,
pabeni, mcoquelin.stm32, Joao.Pinto, netdev, linux-stm32,
linux-arm-kernel, linux-kernel
Cc: junxiao.chang
Macro like "#define abc(x) (x, x)" is unsafe which might introduce
side effects. Each MTL RxQ DMA channel mask is 4 bits, so using
(0xf << chan) instead of GENMASK(x + 3, x) to avoid unsafe macro.
Fixes: d43042f4da3e ("net: stmmac: mapping mtl rx to dma channel")
Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 71dad409f78b0..3c1490408a1c3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -333,7 +333,7 @@ enum power_event {
#define MTL_RXQ_DMA_MAP1 0x00000c34 /* queue 4 to 7 */
#define MTL_RXQ_DMA_Q04MDMACH_MASK GENMASK(3, 0)
#define MTL_RXQ_DMA_Q04MDMACH(x) ((x) << 0)
-#define MTL_RXQ_DMA_QXMDMACH_MASK(x) GENMASK(11 + (8 * ((x) - 1)), 8 * (x))
+#define MTL_RXQ_DMA_QXMDMACH_MASK(x) (0xf << 8 * (x))
#define MTL_RXQ_DMA_QXMDMACH(chan, q) ((chan) << (8 * (q)))
#define MTL_CHAN_BASE_ADDR 0x00000d00
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next 2/2] net: stmmac: remove duplicate dma queue channel macros
2022-10-21 11:47 [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro Junxiao Chang
@ 2022-10-21 11:47 ` Junxiao Chang
2022-10-25 4:00 ` [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro Jakub Kicinski
1 sibling, 0 replies; 4+ messages in thread
From: Junxiao Chang @ 2022-10-21 11:47 UTC (permalink / raw)
To: peppe.cavallaro, alexandre.torgue, joabreu, davem, edumazet, kuba,
pabeni, mcoquelin.stm32, Joao.Pinto, netdev, linux-stm32,
linux-arm-kernel, linux-kernel
Cc: junxiao.chang
It doesn't need extra macros for queue 0 & 4. Same macro could
be used for all 8 queues.
Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 2 --
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 11 ++++-------
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 3c1490408a1c3..ccd49346d3b30 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -331,8 +331,6 @@ enum power_event {
#define MTL_RXQ_DMA_MAP0 0x00000c30 /* queue 0 to 3 */
#define MTL_RXQ_DMA_MAP1 0x00000c34 /* queue 4 to 7 */
-#define MTL_RXQ_DMA_Q04MDMACH_MASK GENMASK(3, 0)
-#define MTL_RXQ_DMA_Q04MDMACH(x) ((x) << 0)
#define MTL_RXQ_DMA_QXMDMACH_MASK(x) (0xf << 8 * (x))
#define MTL_RXQ_DMA_QXMDMACH(chan, q) ((chan) << (8 * (q)))
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index c25bfecb4a2df..64b916728bdd4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -219,15 +219,12 @@ static void dwmac4_map_mtl_dma(struct mac_device_info *hw, u32 queue, u32 chan)
else
value = readl(ioaddr + MTL_RXQ_DMA_MAP1);
- if (queue == 0 || queue == 4) {
- value &= ~MTL_RXQ_DMA_Q04MDMACH_MASK;
- value |= MTL_RXQ_DMA_Q04MDMACH(chan);
- } else if (queue > 4) {
- value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue - 4);
- value |= MTL_RXQ_DMA_QXMDMACH(chan, queue - 4);
- } else {
+ if (queue < 4) {
value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue);
value |= MTL_RXQ_DMA_QXMDMACH(chan, queue);
+ } else {
+ value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue - 4);
+ value |= MTL_RXQ_DMA_QXMDMACH(chan, queue - 4);
}
if (queue < 4)
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro
2022-10-21 11:47 [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro Junxiao Chang
2022-10-21 11:47 ` [PATCH net-next 2/2] net: stmmac: remove duplicate dma queue channel macros Junxiao Chang
@ 2022-10-25 4:00 ` Jakub Kicinski
2022-10-25 4:58 ` Chang, Junxiao
1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2022-10-25 4:00 UTC (permalink / raw)
To: Junxiao Chang
Cc: peppe.cavallaro, alexandre.torgue, joabreu, davem, edumazet,
pabeni, mcoquelin.stm32, Joao.Pinto, netdev, linux-stm32,
linux-arm-kernel, linux-kernel
On Fri, 21 Oct 2022 19:47:10 +0800 Junxiao Chang wrote:
> Macro like "#define abc(x) (x, x)" is unsafe which might introduce
> side effects. Each MTL RxQ DMA channel mask is 4 bits, so using
> (0xf << chan) instead of GENMASK(x + 3, x) to avoid unsafe macro.
>
> Fixes: d43042f4da3e ("net: stmmac: mapping mtl rx to dma channel")
You need to point out an existing usage where this is causing problems,
otherwise this is not a fix.
And squash the two patches together, it's going to be easier to review.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro
2022-10-25 4:00 ` [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro Jakub Kicinski
@ 2022-10-25 4:58 ` Chang, Junxiao
0 siblings, 0 replies; 4+ messages in thread
From: Chang, Junxiao @ 2022-10-25 4:58 UTC (permalink / raw)
To: Jakub Kicinski
Cc: peppe.cavallaro@st.com, alexandre.torgue@foss.st.com,
joabreu@synopsys.com, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, mcoquelin.stm32@gmail.com,
Joao.Pinto@synopsys.com, netdev@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Thank you for reviewing it. There is no real issue if this macro only be used in stmmac driver and parameter is not function or "i++".
I will squash these two patches.
Regards,
Junxiao
-----Original Message-----
From: Jakub Kicinski <kuba@kernel.org>
Sent: Tuesday, October 25, 2022 12:00 PM
To: Chang, Junxiao <junxiao.chang@intel.com>
Cc: peppe.cavallaro@st.com; alexandre.torgue@foss.st.com; joabreu@synopsys.com; davem@davemloft.net; edumazet@google.com; pabeni@redhat.com; mcoquelin.stm32@gmail.com; Joao.Pinto@synopsys.com; netdev@vger.kernel.org; linux-stm32@st-md-mailman.stormreply.com; linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro
On Fri, 21 Oct 2022 19:47:10 +0800 Junxiao Chang wrote:
> Macro like "#define abc(x) (x, x)" is unsafe which might introduce
> side effects. Each MTL RxQ DMA channel mask is 4 bits, so using (0xf
> << chan) instead of GENMASK(x + 3, x) to avoid unsafe macro.
>
> Fixes: d43042f4da3e ("net: stmmac: mapping mtl rx to dma channel")
You need to point out an existing usage where this is causing problems, otherwise this is not a fix.
And squash the two patches together, it's going to be easier to review.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-25 4:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-21 11:47 [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro Junxiao Chang
2022-10-21 11:47 ` [PATCH net-next 2/2] net: stmmac: remove duplicate dma queue channel macros Junxiao Chang
2022-10-25 4:00 ` [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro Jakub Kicinski
2022-10-25 4:58 ` Chang, Junxiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).