Skip to content

Commit f7debee

Browse files
prajnohagregkh
authored andcommitted
kobject: return error code if writing /sys/.../uevent fails
[ Upstream commit df44b47 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 80eac18 commit f7debee

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
@@ -614,8 +614,10 @@ static void remove_probe_files(struct bus_type *bus)
614614
static ssize_t uevent_store(struct device_driver *drv, const char *buf,
615615
size_t count)
616616
{
617-
kobject_synth_uevent(&drv->p->kobj, buf, count);
618-
return count;
617+
int rc;
618+
619+
rc = kobject_synth_uevent(&drv->p->kobj, buf, count);
620+
return rc ? rc : count;
619621
}
620622
static DRIVER_ATTR_WO(uevent);
621623

@@ -831,8 +833,10 @@ static void klist_devices_put(struct klist_node *n)
831833
static ssize_t bus_uevent_store(struct bus_type *bus,
832834
const char *buf, size_t count)
833835
{
834-
kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
835-
return count;
836+
int rc;
837+
838+
rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
839+
return rc ? rc : count;
836840
}
837841
static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
838842

‎drivers/base/core.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,14 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
10671067
static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
10681068
const char *buf, size_t count)
10691069
{
1070-
if (kobject_synth_uevent(&dev->kobj, buf, count))
1070+
int rc;
1071+
1072+
rc = kobject_synth_uevent(&dev->kobj, buf, count);
1073+
1074+
if (rc) {
10711075
dev_err(dev, "uevent: failed to send synthetic uevent\n");
1076+
return rc;
1077+
}
10721078

10731079
return count;
10741080
}

‎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)