Skip to content

Commit

Permalink
kobject: return error code if writing /sys/.../uevent fails
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Peter Rajnoha authored and Greg Kroah-Hartman committed Dec 6, 2018
1 parent c37d721 commit df44b47
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 8 additions & 4 deletions drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,14 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
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;
}
Expand Down
6 changes: 4 additions & 2 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit df44b47

Please sign in to comment.