mirror of
https://github.com/torvalds/linux
synced 2024-07-21 18:51:47 +00:00
net: sysfs: fix locking in carrier read
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: facd15dfd6
("net: core: synchronize link-watch when carrier is queried")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Link: https://lore.kernel.org/r/20231206172122.859df6ba937f.I9c80608bcfbab171943ff4942b52dbd5e97fe06e@changeid
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
172db56d90
commit
bf17b36ccd
|
@ -193,6 +193,10 @@ 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,
|
||||
|
@ -200,10 +204,11 @@ static ssize_t carrier_show(struct device *dev,
|
|||
*/
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue