Re: unregister_netdevice: waiting for DEV to become free (2)

From: Tetsuo Handa
Date: Thu Dec 05 2019 - 06:01:15 EST


On 2019/12/05 19:00, Jouni HÃgander wrote:
>> diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
>> index ae3bcb1540ec..562d06c274aa 100644
>> --- a/net/core/net-sysfs.c
>> +++ b/net/core/net-sysfs.c
>> @@ -1459,14 +1459,14 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)
>> struct kobject *kobj = &queue->kobj;
>> int error = 0;
>>
>> + dev_hold(queue->dev);
>> +
>> kobj->kset = dev->queues_kset;
>> error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL,
>> "tx-%u", index);
>> if (error)
>> goto err;
>>
>> - dev_hold(queue->dev);
>> -
>> #ifdef CONFIG_BQL
>> error = sysfs_create_group(kobj, &dql_group);
>> if (error)
>
> Now after reproducing the issue I think this is actually proper fix for
> the issue. It's not related to missing error handling in in
> tun_set_real_num_queues as I commented earlier. Can you prepare patch
> for this?

You can write the patch; I don't know about commit a3e23f719f5c4a38
("net-sysfs: call dev_hold if kobject_init_and_add success").

I was wondering how can the caller tell whether to drop the refcount, for
the caller won't be able to know which one (kobject_init_and_add() or
sysfs_create_group()) returned an error. Therefore, always taking the
refcount seems to be a proper fix...