Skip to contentSkip to conversation

e1000e: use ip_hdrlen() instead of bit shift

PATCH In review Moon Yeounsu 2 participants 3 messages Aug 1, 2024 – Aug 2, 2024

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

PATCH 1/1 e1000e: use ip_hdrlen() instead of bit shift

There's no reason to use bit shift to find the UDP header. It's not intuitive and it reinvents well-defined functions.

---
 drivers/net/ethernet/intel/e1000e/netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/e1000e/netdev.c +1 -1
index 360ee26557f7..07c4cf84bdf3 100644
@@ -5731,7 +5731,7 @@ static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
 		if (ip->protocol != IPPROTO_UDP)
 			return 0;
 
-		udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
+		udp = (struct udphdr *)((u8 *)ip + ip_hdrlen(skb));
 		if (ntohs(udp->dest) != 67)
 			return 0;
 
Signature · 1 line
2.45.2
#1 lore raw
Quoted 13 lines · Moon Yeounsu

There's no reason to use bit shift to find the UDP header. It's not intuitive and it reinvents well-defined functions.

---
 drivers/net/ethernet/intel/e1000e/netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/e1000e/netdev.c +0 -0
index 360ee26557f7..07c4cf84bdf3 100644

drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, · line 5734

Quoted 5 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1 -1
@@ -5731,7 +5731,7 @@ static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
 		if (ip->protocol != IPPROTO_UDP)
 			return 0;
 
-		udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
+		udp = (struct udphdr *)((u8 *)ip + ip_hdrlen(skb));

This helper needs skb_network_header being set up correctly, are you sure thats the case here? ip pointer is fetched via data + 14 right above, so it doesn't look like this would work.

#2 lore raw
Quoted 3 lines · Florian Westphal

This helper needs skb_network_header being set up correctly, are you sure thats the case here? ip pointer is fetched via data + 14 right above, so it doesn't look like this would work.

I read it once more carefully, and yes, you are right. Sorry for wasting your time...
It is my first patch to the netdev subsystem. So... I was too excited. It's all my fault. Next time, I'll be careful and deliberate.

Thank you for reviewing.