Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hsr: use hsr_for_each_port_rtnl in hsr_port_get_hsr

hsr_port_get_hsr() iterates over ports using hsr_for_each_port(),
but many of its callers do not hold the required RCU lock.

Switch to hsr_for_each_port_rtnl(), since most callers already hold
the rtnl lock. After review, all callers are covered by either the rtnl
lock or the RCU lock, except hsr_dev_xmit(). Fix this by adding an
RCU read lock there.

Fixes: c5a759117210 ("net/hsr: Use list_head (and rcu) instead of array for slave devices.")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250905091533.377443-3-liuhangbin@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Hangbin Liu and committed by
Paolo Abeni
393c841f 8884c693

+4 -1
+3
net/hsr/hsr_device.c
··· 226 226 struct hsr_priv *hsr = netdev_priv(dev); 227 227 struct hsr_port *master; 228 228 229 + rcu_read_lock(); 229 230 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); 230 231 if (master) { 231 232 skb->dev = master->dev; ··· 239 238 dev_core_stats_tx_dropped_inc(dev); 240 239 dev_kfree_skb_any(skb); 241 240 } 241 + rcu_read_unlock(); 242 + 242 243 return NETDEV_TX_OK; 243 244 } 244 245
+1 -1
net/hsr/hsr_main.c
··· 134 134 { 135 135 struct hsr_port *port; 136 136 137 - hsr_for_each_port(hsr, port) 137 + hsr_for_each_port_rtnl(hsr, port) 138 138 if (port->type == pt) 139 139 return port; 140 140 return NULL;