Re: [PATCH] [v2] module: don't ignore sysfs_create_link() failures

From: Arnd Bergmann
Date: Tue Mar 26 2024 - 10:14:28 EST


On Sat, Mar 23, 2024, at 17:50, Greg Kroah-Hartman wrote:
> On Fri, Mar 22, 2024 at 06:39:11PM +0100, Arnd Bergmann wrote:
>> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
>> index daee55c9b2d9..7ef75b60d331 100644
>> --- a/drivers/base/bus.c
>> +++ b/drivers/base/bus.c
>> @@ -674,7 +674,12 @@ int bus_add_driver(struct device_driver *drv)
>> if (error)
>> goto out_del_list;
>> }
>> - module_add_driver(drv->owner, drv);
>> + error = module_add_driver(drv->owner, drv);
>> + if (error) {
>> + printk(KERN_ERR "%s: failed to create module links for %s\n",
>> + __func__, drv->name);
>> + goto out_del_list;
>
> Don't we need to walk back the driver_attach() call here if this fails?

Yes, fixed now. There are still some other calls right after
it that print an error but don't cause bus_add_driver() to fail
though. We may want to add similar unwinding there, but that
feels like it should be a separate patch.

>>
>> if (!mk)
>> - return;
>> + return 0;
>> +
>> + ret = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
>> + if (ret && ret != -EEXIST)
>
> Why would EEXIST happen here? How can this be called twice?
>

My impression was that the lack of error handling and the
comment was ab out a case where that might happen
intentionally. I've removed it now as I couldn't find any
evidence that this is really needed. I suppose we would
find out in testing if we do.

Arnd