Unverified Commit de7233ed authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!14898 Revert "Revert "driver core: Fix uevent_show() vs driver detach race""

parents 02d56ff3 7d2ee5c8
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <linux/mutex.h>
#include <linux/pm_runtime.h>
#include <linux/netdevice.h>
#include <linux/rcupdate.h>
#include <linux/sched/signal.h>
#include <linux/sched/mm.h>
#include <linux/string_helpers.h>
@@ -2566,6 +2567,7 @@ static const char *dev_uevent_name(const struct kobject *kobj)
static int dev_uevent(const struct kobject *kobj, struct kobj_uevent_env *env)
{
	const struct device *dev = kobj_to_dev(kobj);
	struct device_driver *driver;
	int retval = 0;

	/* add device node properties if present */
@@ -2594,8 +2596,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();

	/* Add common DT information about the device */
	of_device_uevent(dev, env);
@@ -2665,11 +2671,8 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
	if (!env)
		return -ENOMEM;

	/* Synchronize with really_probe() */
	device_lock(dev);
	/* let the kset specific function add its keys */
	retval = kset->uevent_ops->uevent(&dev->kobj, env);
	device_unlock(dev);
	if (retval)
		goto out;

+4 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/rcupdate.h>
#include "base.h"

static char *make_driver_name(struct device_driver *drv)
@@ -101,6 +102,9 @@ void module_remove_driver(struct device_driver *drv)
	if (!drv)
		return;

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

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

	if (drv->owner)