Skip to contentSkip to conversation

net: stmmac: use le32_to_cpu for p->des0 and p->des1

PATCH In review Min-Hua Chen 2 participants 3 messages May 19, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: use le32_to_cpu for p->des0 and p->des1

Use le32_to_cpu for p->des0 and p->des1 to fix the following sparse warnings:

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c:110:23: sparse: warning: restricted __le32 degrades to integer drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c:110:50: sparse: warning: restricted __le32 degrades to integer

---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +2 -1
index 13c347ee8be9..3d094d83e975 100644
@@ -107,7 +107,8 @@ static int dwxgmac2_rx_check_timestamp(void *desc)
 	ts_valid = !(rdes3 & XGMAC_RDES3_TSD) && (rdes3 & XGMAC_RDES3_TSA);
 
 	if (likely(desc_valid && ts_valid)) {
-		if ((p->des0 == 0xffffffff) && (p->des1 == 0xffffffff))
+		if ((le32_to_cpu(p->des0) == 0xffffffff) &&
+		    (le32_to_cpu(p->des1) == 0xffffffff))
 			return -EINVAL;
 		return 0;
 	}
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Min-Hua Chen

Use le32_to_cpu for p->des0 and p->des1 to fix the following sparse warnings:

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c:110:23: sparse: warning: restricted __le32 degrades to integer drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c:110:50: sparse: warning: restricted __le32 degrades to integer

---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +0 -0
index 13c347ee8be9..3d094d83e975 100644

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c static int dwxgmac2_rx_check_timestamp(void *desc) · line 111

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +2 -1
@@ -107,7 +107,8 @@ static int dwxgmac2_rx_check_timestamp(void *desc)
 	ts_valid = !(rdes3 & XGMAC_RDES3_TSD) && (rdes3 & XGMAC_RDES3_TSA);
 
 	if (likely(desc_valid && ts_valid)) {
-		if ((p->des0 == 0xffffffff) && (p->des1 == 0xffffffff))
+		if ((le32_to_cpu(p->des0) == 0xffffffff) &&
+		    (le32_to_cpu(p->des1) == 0xffffffff))

Hi Min-Hua Chen,

I'm not sure if it makes a meaningful difference in practice - and certainly it won't on LE systems. But I wonder if it's nicer to do the conversion on the constant rather than the variable part of the comparison.

		if ((p->des0 == cpu_to_le32(0xffffffff)) &&
		    (p->des1 == cpu_to_le32(0xffffffff)))
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +0 -0
 			return -EINVAL;
 		return 0;
 	}
Signature · 1 line
2.34.1
#2 lore raw

Hi Simon,

Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c static int dwxgmac2_rx_check_timestamp(void *desc) · line 111

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +2 -1
 	if (likely(desc_valid && ts_valid)) {
-		if ((p->des0 == 0xffffffff) && (p->des1 == 0xffffffff))
+		if ((le32_to_cpu(p->des0) == 0xffffffff) &&
+		    (le32_to_cpu(p->des1) == 0xffffffff))

Hi Min-Hua Chen,

Quoted 6 lines

I'm not sure if it makes a meaningful difference in practice - and certainly it won't on LE systems. But I wonder if it's nicer to do the conversion on the constant rather than the variable part of the comparison.

		if ((p->des0 == cpu_to_le32(0xffffffff)) &&
		    (p->des1 == cpu_to_le32(0xffffffff)))

After reading your suggestion, I think:
the 'p->des0 == cpu_to_le32(0xffffffff)' gives the readers a hint that p->des0 is __le32 type and I think it is easier (for me) to understand than 'le32_to_cpu(p->des0) == 0xffffffff'

I will submit v2 for this, thanks for your comment.

thanks,
Min-Hua