[PATCH 1/1] kobject: Don't emit change events if not in sysfs

From: Abhishek Pandit-Subedi
Date: Mon Oct 19 2020 - 18:33:10 EST


Add a check to make sure the kobj is created and in sysfs before sending
a change event notification. Otherwise, udev rules that depend on the
change notification may find that the path that changed doesn't actually
exist.

Fixes: a45aca510b73b7 (PM: sleep: core: Emit changed uevent on wakeup_sysfs_add/remove)
Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@xxxxxxxxxxxx>
---

lib/kobject_uevent.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 7998affa45d49a..f08197e907d5ce 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -473,6 +473,11 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
if (action == KOBJ_REMOVE)
kobj->state_remove_uevent_sent = 1;

+ if (action == KOBJ_CHANGE && !kobj->state_in_sysfs) {
+ pr_debug("kobject: can't emit KOBJ_CHANGE until in sysfs\n");
+ return -EINVAL;
+ }
+
pr_debug("kobject: '%s' (%p): %s\n",
kobject_name(kobj), kobj, __func__);

--
2.29.0.rc1.297.gfa9743e501-goog