Skip to content

Commit e0b6090

Browse files
hogander-unikiedavem330
authored andcommitted
net-sysfs: Call dev_hold always in netdev_queue_add_kobject
Dev_hold has to be called always in netdev_queue_add_kobject. Otherwise usage count drops below 0 in case of failure in kobject_init_and_add. Fixes: b8eb718 ("net-sysfs: Fix reference count leak in rx|netdev_queue_add_kobject") Reported-by: Hulk Robot <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: David Miller <[email protected]> Cc: Lukas Bulwahn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8bef0af commit e0b6090

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

net/core/net-sysfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,14 +1459,17 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)
14591459
struct kobject *kobj = &queue->kobj;
14601460
int error = 0;
14611461

1462+
/* Kobject_put later will trigger netdev_queue_release call
1463+
* which decreases dev refcount: Take that reference here
1464+
*/
1465+
dev_hold(queue->dev);
1466+
14621467
kobj->kset = dev->queues_kset;
14631468
error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL,
14641469
"tx-%u", index);
14651470
if (error)
14661471
goto err;
14671472

1468-
dev_hold(queue->dev);
1469-
14701473
#ifdef CONFIG_BQL
14711474
error = sysfs_create_group(kobj, &dql_group);
14721475
if (error)

0 commit comments

Comments
 (0)