Skip to content

Commit df44b47

Browse files
prajnohagregkh
authored andcommitted
kobject: return error code if writing /sys/.../uevent fails
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>
1 parent c37d721 commit df44b47

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎drivers/base/bus.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,10 @@ static void remove_probe_files(struct bus_type *bus)
611611
static ssize_t uevent_store(struct device_driver *drv, const char *buf,
612612
size_t count)
613613
{
614-
kobject_synth_uevent(&drv->p->kobj, buf, count);
615-
return count;
614+
int rc;
615+
616+
rc = kobject_synth_uevent(&drv->p->kobj, buf, count);
617+
return rc ? rc : count;
616618
}
617619
static DRIVER_ATTR_WO(uevent);
618620

@@ -828,8 +830,10 @@ static void klist_devices_put(struct klist_node *n)
828830
static ssize_t bus_uevent_store(struct bus_type *bus,
829831
const char *buf, size_t count)
830832
{
831-
kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
832-
return count;
833+
int rc;
834+
835+
rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
836+
return rc ? rc : count;
833837
}
834838
static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
835839

‎drivers/base/core.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,14 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
10731073
static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
10741074
const char *buf, size_t count)
10751075
{
1076-
if (kobject_synth_uevent(&dev->kobj, buf, count))
1076+
int rc;
1077+
1078+
rc = kobject_synth_uevent(&dev->kobj, buf, count);
1079+
1080+
if (rc) {
10771081
dev_err(dev, "uevent: failed to send synthetic uevent\n");
1082+
return rc;
1083+
}
10781084

10791085
return count;
10801086
}

‎kernel/module.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,10 @@ static ssize_t store_uevent(struct module_attribute *mattr,
12071207
struct module_kobject *mk,
12081208
const char *buffer, size_t count)
12091209
{
1210-
kobject_synth_uevent(&mk->kobj, buffer, count);
1211-
return count;
1210+
int rc;
1211+
1212+
rc = kobject_synth_uevent(&mk->kobj, buffer, count);
1213+
return rc ? rc : count;
12121214
}
12131215

12141216
struct module_attribute module_uevent =

0 commit comments

Comments
 (0)