Skip to content

Commit

Permalink
net-sysfs: call dev_hold if kobject_init_and_add success
Browse files Browse the repository at this point in the history
[ Upstream commit a3e23f7 ]

In netdev_queue_add_kobject and rx_queue_add_kobject,
if sysfs_create_group failed, kobject_put will call
netdev_queue_release to decrease dev refcont, however
dev_hold has not be called. So we will see this while
unregistering dev:

unregister_netdevice: waiting for bcsh0 to become free. Usage count = -1

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: d0d6683 ("net: don't decrement kobj reference count on init failure")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
YueHaibing authored and gregkh committed Apr 3, 2019
1 parent 8dcf078 commit d9d215b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net/core/net-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)
if (error)
return error;

dev_hold(queue->dev);

if (dev->sysfs_rx_queue_group) {
error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group);
if (error) {
Expand All @@ -943,7 +945,6 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)
}

kobject_uevent(kobj, KOBJ_ADD);
dev_hold(queue->dev);

return error;
}
Expand Down Expand Up @@ -1472,6 +1473,8 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)
if (error)
return error;

dev_hold(queue->dev);

#ifdef CONFIG_BQL
error = sysfs_create_group(kobj, &dql_group);
if (error) {
Expand All @@ -1481,7 +1484,6 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)
#endif

kobject_uevent(kobj, KOBJ_ADD);
dev_hold(queue->dev);

return 0;
}
Expand Down

0 comments on commit d9d215b

Please sign in to comment.