2022-10-21 12:40:03

by Chang, Junxiao

[permalink] [raw]
Subject: [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro

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 <[email protected]>
---
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


2022-10-25 04:13:38

by Jakub Kicinski

[permalink] [raw]
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.

2022-10-25 05:28:46

by Chang, Junxiao

[permalink] [raw]
Subject: RE: [PATCH net-next 1/2] net: stmmac: fix unsafe MTL DMA macro

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 <[email protected]>
Sent: Tuesday, October 25, 2022 12:00 PM
To: Chang, Junxiao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
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.