Skip to content

Commit

Permalink
net: sysfs: fix locking in carrier read
Browse files Browse the repository at this point in the history
My previous patch added a call to linkwatch_sync_dev(),
but that of course needs to be called under RTNL, which
I missed earlier, but now saw RCU warnings from.

Fix that by acquiring the RTNL in a similar fashion to
how other files do it here.

Fixes: facd15d ("net: core: synchronize link-watch when carrier is queried")
Signed-off-by: Johannes Berg <[email protected]>
Link: https://lore.kernel.org/r/20231206172122.859df6ba937f.I9c80608bcfbab171943ff4942b52dbd5e97fe06e@changeid
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
jmberg-intel authored and kuba-moo committed Dec 9, 2023
1 parent 172db56 commit bf17b36
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions net/core/net-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,22 @@ static ssize_t carrier_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct net_device *netdev = to_net_dev(dev);
int ret = -EINVAL;

if (!rtnl_trylock())
return restart_syscall();

if (netif_running(netdev)) {
/* Synchronize carrier state with link watch,
* see also rtnl_getlink().
*/
linkwatch_sync_dev(netdev);

return sysfs_emit(buf, fmt_dec, !!netif_carrier_ok(netdev));
ret = sysfs_emit(buf, fmt_dec, !!netif_carrier_ok(netdev));
}
rtnl_unlock();

return -EINVAL;
return ret;
}
static DEVICE_ATTR_RW(carrier);

Expand Down

0 comments on commit bf17b36

Please sign in to comment.