Skip to content

Commit 1d9a628

Browse files
liuhangbingregkh
authored andcommitted
hsr: use hsr_for_each_port_rtnl in hsr_port_get_hsr
[ Upstream commit 393c841 ] 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: c5a7591 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c9ac729 commit 1d9a628

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

net/hsr/hsr_device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
228228
struct hsr_priv *hsr = netdev_priv(dev);
229229
struct hsr_port *master;
230230

231+
rcu_read_lock();
231232
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
232233
if (master) {
233234
skb->dev = master->dev;
@@ -240,6 +241,8 @@ static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
240241
dev_core_stats_tx_dropped_inc(dev);
241242
dev_kfree_skb_any(skb);
242243
}
244+
rcu_read_unlock();
245+
243246
return NETDEV_TX_OK;
244247
}
245248

net/hsr/hsr_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt)
125125
{
126126
struct hsr_port *port;
127127

128-
hsr_for_each_port(hsr, port)
128+
hsr_for_each_port_rtnl(hsr, port)
129129
if (port->type == pt)
130130
return port;
131131
return NULL;

0 commit comments

Comments
 (0)