net: macb: use correct __be32 and __be16 types
Subsystems (3)
PATCH 1/1 net: macb: use correct __be32 and __be16 types
This patch fixes the following sparse warnings. No functional changes.
Use cpu_to_be16() and cpu_to_be32() to convert constants before comparing them with __be16 type of psrc/pdst and __be32 type of ip4src/ip4dst. Apply be16_to_cpu() in GEM_BFINS().
Also, remove unnecessary parentheses reported by checkpatch.pl.
drivers/net/ethernet/cadence/macb_main.c:3448:39: sparse: warning: restricted __be32 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3453:39: sparse: warning: restricted __be32 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3458:40: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3458:69: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3483:20: sparse: warning: restricted __be32 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3497:20: sparse: warning: restricted __be32 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3511:21: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3511:50: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3517:30: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3518:30: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3525:36: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3526:38: sparse: warning: restricted __be16 degrades to integer drivers/net/ethernet/cadence/macb_main.c:3529:38: sparse: warning: restricted __be16 degrades to integer
--- drivers/net/ethernet/cadence/macb_main.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +13 -11
@@ -3445,17 +3445,18 @@ static void gem_enable_flow_filters(struct macb *bp, bool enable)/* only enable fields with no masking */ tp4sp_m = &(fs->m_u.tcp_ip4_spec); -if (enable && (tp4sp_m->ip4src ==0xFFFFFFFF )) +if (enable && tp4sp_m->ip4src ==cpu_to_be32 (0xFFFFFFFF )) t2_scr =GEM_BFINS (CMPAEN ,1 , t2_scr);else t2_scr =GEM_BFINS (CMPAEN ,0 , t2_scr); -if (enable && (tp4sp_m->ip4dst ==0xFFFFFFFF )) +if (enable && tp4sp_m->ip4dst ==cpu_to_be32 (0xFFFFFFFF )) t2_scr =GEM_BFINS (CMPBEN ,1 , t2_scr);else t2_scr =GEM_BFINS (CMPBEN ,0 , t2_scr); -if (enable && ((tp4sp_m->psrc ==0xFFFF ) || (tp4sp_m->pdst ==0xFFFF ))) +if (enable && (tp4sp_m->psrc ==cpu_to_be16 (0xFFFF ) || + tp4sp_m->pdst ==cpu_to_be16 (0xFFFF ))) t2_scr =GEM_BFINS (CMPCEN ,1 , t2_scr);else t2_scr =GEM_BFINS (CMPCEN ,0 , t2_scr);
@@ -3480,7 +3481,7 @@ static void gem_prog_cmp_regs(struct macb *bp, struct ethtool_rx_flow_spec *fs) tp4sp_m = &(fs->m_u.tcp_ip4_spec);/* ignore field if any masking set */ -if (tp4sp_m->ip4src ==0xFFFFFFFF ) { +if (tp4sp_m->ip4src ==cpu_to_be32 (0xFFFFFFFF )) {/* 1st compare reg - IP source address */ w0 =0 ; w1 =0 ;
@@ -3494,7 +3495,7 @@ static void gem_prog_cmp_regs(struct macb *bp, struct ethtool_rx_flow_spec *fs) }/* ignore field if any masking set */ -if (tp4sp_m->ip4dst ==0xFFFFFFFF ) { +if (tp4sp_m->ip4dst ==cpu_to_be32 (0xFFFFFFFF )) {/* 2nd compare reg - IP destination address */ w0 =0 ; w1 =0 ;
@@ -3508,25 +3509,26 @@ static void gem_prog_cmp_regs(struct macb *bp, struct ethtool_rx_flow_spec *fs) }/* ignore both port fields if masking set in both */ -if ((tp4sp_m->psrc ==0xFFFF ) || (tp4sp_m->pdst ==0xFFFF )) { +if (tp4sp_m->psrc ==cpu_to_be16 (0xFFFF ) || + tp4sp_m->pdst ==cpu_to_be16 (0xFFFF )) {/* 3rd compare reg - source port, destination port */ w0 =0 ; w1 =0 ; w1 =GEM_BFINS (T2CMPOFST ,GEM_T2COMPOFST_IPHDR , w1);if (tp4sp_m->psrc == tp4sp_m->pdst) { - w0 =GEM_BFINS (T2MASK , tp4sp_v->psrc, w0); - w0 =GEM_BFINS (T2CMP , tp4sp_v->pdst, w0); + w0 =GEM_BFINS (T2MASK ,be16_to_cpu (tp4sp_v->psrc), w0); + w0 =GEM_BFINS (T2CMP ,be16_to_cpu (tp4sp_v->pdst), w0); w1 =GEM_BFINS (T2DISMSK ,1 , w1);/* 32-bit compare */ w1 =GEM_BFINS (T2OFST ,IPHDR_SRCPORT_OFFSET , w1); }else {/* only one port definition */ w1 =GEM_BFINS (T2DISMSK ,0 , w1);/* 16-bit compare */ w0 =GEM_BFINS (T2MASK ,0xFFFF , w0); -if (tp4sp_m->psrc ==0xFFFF ) {/* src port */ - w0 =GEM_BFINS (T2CMP , tp4sp_v->psrc, w0); +if (tp4sp_m->psrc ==cpu_to_be16 (0xFFFF )) {/* src port */ + w0 =GEM_BFINS (T2CMP ,be16_to_cpu (tp4sp_v->psrc), w0); w1 =GEM_BFINS (T2OFST ,IPHDR_SRCPORT_OFFSET , w1); }else {/* dst port */ - w0 =GEM_BFINS (T2CMP , tp4sp_v->pdst, w0); + w0 =GEM_BFINS (T2CMP ,be16_to_cpu (tp4sp_v->pdst), w0); w1 =GEM_BFINS (T2OFST ,IPHDR_DSTPORT_OFFSET , w1); } }
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 5 lines · On Sat, 20 May 2023 06:19:39 +0800 Min-Hua Chen wrote:
This patch fixes the following sparse warnings. No functional changes.
Use
cpu_to_be16()andcpu_to_be32()to convert constants before comparing them with__be16type of psrc/pdst and__be32type of ip4src/ip4dst. Applybe16_to_cpu()inGEM_BFINS().
same story as with your stmmac patch, the warning is a false positive
Quoted 8 lines · On Sat, 20 May 2023 06:19:39 +0800 Min-Hua Chen wrote:
Quoted 5 lines
This patch fixes the following sparse warnings. No functional changes.
Use
cpu_to_be16()andcpu_to_be32()to convert constants before comparing them with__be16type of psrc/pdst and__be32type of ip4src/ip4dst. Applybe16_to_cpu()inGEM_BFINS().same story as with your stmmac patch, the warning is a false positive
yes, the same story and let's discuss this in the stmmac thread [1].
[1] https://lore.kernel.org/lkml/[email protected]/
thanks,
Min-Hua