Re: [PATCH] driver core: Fix uevent_show() vs driver detach race

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024/07/13 4:42, Dan Williams wrote:
> @@ -2668,8 +2670,12 @@ static int dev_uevent(const struct kobject *kobj, struct kobj_uevent_env *env)
>  	if (dev->type && dev->type->name)
>  		add_uevent_var(env, "DEVTYPE=%s", dev->type->name);
>  
> -	if (dev->driver)
> -		add_uevent_var(env, "DRIVER=%s", dev->driver->name);
> +	/* Synchronize with module_remove_driver() */
> +	rcu_read_lock();
> +	driver = READ_ONCE(dev->driver);
> +	if (driver)
> +		add_uevent_var(env, "DRIVER=%s", driver->name);
> +	rcu_read_unlock();
>  

Given that read of dev->driver is protected using RCU,

> @@ -97,6 +98,9 @@ void module_remove_driver(struct device_driver *drv)
>  	if (!drv)
>  		return;
>  

where is

	dev->driver = NULL;

performed prior to

> +	/* Synchronize with dev_uevent() */
> +	synchronize_rcu();
> +

this synchronize_rcu(), in order to make sure that
READ_ONCE(dev->driver) in dev_uevent() observes NULL?

>  	sysfs_remove_link(&drv->p->kobj, "module");
>  
>  	if (drv->owner)
> 





[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux