public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] ipv6: sr: Add unlikely hint to idev NULL check in seg6_hmac_validate_skb
@ 2026-03-11  7:23 Minhong He
  2026-03-11  8:57 ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: Minhong He @ 2026-03-11  7:23 UTC (permalink / raw)
  To: andrea.mayer, davem, dsahern, edumazet, kuba, pabeni, horms,
	david.lebrun, netdev
  Cc: linux-kernel, Minhong He

In seg6_hmac_validate_skb(), the pointer returned by __in6_dev_get()
can theoretically be NULL if the network device lacks proper IPv6
initialization or is being torn down. However, this is an exceptional
error path; in normal operation, the device will always have a valid
inet6_dev structure.

Marking this NULL check with unlikely() helps the compiler optimize
branch prediction and code layout. It ensures that the common case
(valid idev) remains in the hot path, while the error handling code
is placed out of line, improving CPU pipeline efficiency for high-speed
SRv6 packet processing.

Fixes: bf355b8d2c30 ("ipv6: sr: add core files for SR HMAC support")
Signed-off-by: Minhong He <heminhong@kylinos.cn>
---
 net/ipv6/seg6_hmac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
index ee6bac0160ac..a8f279ffb678 100644
--- a/net/ipv6/seg6_hmac.c
+++ b/net/ipv6/seg6_hmac.c
@@ -184,6 +184,8 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb)
 	int require_hmac;
 
 	idev = __in6_dev_get(skb->dev);
+	if (unlikely(!idev))
+		return false;
 
 	srh = (struct ipv6_sr_hdr *)skb_transport_header(skb);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-19  0:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11  7:23 [PATCH net] ipv6: sr: Add unlikely hint to idev NULL check in seg6_hmac_validate_skb Minhong He
2026-03-11  8:57 ` Eric Dumazet
2026-03-13  2:26   ` [PATCH net v2] ipv6: sr: Add NULL check for idev " Minhong He
2026-03-13  2:38     ` Jakub Kicinski
2026-03-14 22:49     ` Andrea Mayer
2026-03-15 16:01     ` [net,v2] " Simon Horman
2026-03-16  7:33       ` [PATCH net v3] ipv6: add NULL checks for idev in SRv6 paths Minhong He
2026-03-18  0:51         ` Andrea Mayer
2026-03-19  0:44         ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox