kobject: return error code if writing /sys/.../uevent fails
authorPeter Rajnoha <prajnoha@redhat.com>
Wed, 5 Dec 2018 11:27:44 +0000 (12:27 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Dec 2018 15:07:43 +0000 (16:07 +0100)
Propagate error code back to userspace if writing the /sys/.../uevent
file fails. Before, the write operation always returned with success,
even if we failed to recognize the input string or if we failed to
generate the uevent itself.

With the error codes properly propagated back to userspace, we are
able to react in userspace accordingly by not assuming and awaiting
a uevent that is not delivered.

Signed-off-by: Peter Rajnoha <prajnoha@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/bus.c
drivers/base/core.c
kernel/module.c

index 8bfd27ec73d60d1d18a43f9bfcff29b4eb9a50a6..b886b15cb53b4adf90e48480944973c5a3ea7e4c 100644 (file)
@@ -611,8 +611,10 @@ static void remove_probe_files(struct bus_type *bus)
 static ssize_t uevent_store(struct device_driver *drv, const char *buf,
                            size_t count)
 {
-       kobject_synth_uevent(&drv->p->kobj, buf, count);
-       return count;
+       int rc;
+
+       rc = kobject_synth_uevent(&drv->p->kobj, buf, count);
+       return rc ? rc : count;
 }
 static DRIVER_ATTR_WO(uevent);
 
@@ -828,8 +830,10 @@ static void klist_devices_put(struct klist_node *n)
 static ssize_t bus_uevent_store(struct bus_type *bus,
                                const char *buf, size_t count)
 {
-       kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
-       return count;
+       int rc;
+
+       rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
+       return rc ? rc : count;
 }
 static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
 
index e2285059161deb9f010badd96115e89fbbb47f79..a4ced331bc50d99f068cec6d7890fc136874496f 100644 (file)
@@ -1073,8 +1073,14 @@ out:
 static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
                            const char *buf, size_t count)
 {
-       if (kobject_synth_uevent(&dev->kobj, buf, count))
+       int rc;
+
+       rc = kobject_synth_uevent(&dev->kobj, buf, count);
+
+       if (rc) {
                dev_err(dev, "uevent: failed to send synthetic uevent\n");
+               return rc;
+       }
 
        return count;
 }
index 49a4058915870cac3c54f336ff252703594e3bf0..0812a7f80fa740e00f6ea5d754d5403cdef1d557 100644 (file)
@@ -1207,8 +1207,10 @@ static ssize_t store_uevent(struct module_attribute *mattr,
                            struct module_kobject *mk,
                            const char *buffer, size_t count)
 {
-       kobject_synth_uevent(&mk->kobj, buffer, count);
-       return count;
+       int rc;
+
+       rc = kobject_synth_uevent(&mk->kobj, buffer, count);
+       return rc ? rc : count;
 }
 
 struct module_attribute module_uevent =