Instead of holding the device chain read_lock also while calling dev_get_stats just hold it only to check dev_isalive, if the dev is alive, hold that dev via dev_hold then release the read_lock.
When done handling the device, dev_put it. Signed-off-by: Saeed Mahameed <sae...@mellanox.com> --- net/core/net-sysfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index c476f0794132..ee6f9fed43df 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -563,13 +563,20 @@ static ssize_t netstat_show(const struct device *d, offset % sizeof(u64) != 0); read_lock(&dev_base_lock); - if (dev_isalive(dev)) { + if (dev_isalive(dev)) + dev_hold(dev); + else + dev = NULL; + read_unlock(&dev_base_lock); + + if (dev) { struct rtnl_link_stats64 temp; const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); + dev_put(dev); ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset)); } - read_unlock(&dev_base_lock); + return ret; } -- 2.14.3