Udev rules that depend on the power/wakeup attribute don't get triggered
correctly if device_set_wakeup_capable is called after the device is
created. This can happen for several reasons (driver sets wakeup after
device is created, wakeup is changed on parent device, etc) and it seems
reasonable to emit a changed event when adding or removing attributes on
the device.
Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
---
Changes in v3:
- Simplified error handling
Changes in v2:
- Add newline at end of bt_dev_err
drivers/base/power/sysfs.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 24d25cf8ab1487..04c82373c8f240 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* sysfs entries for device PM */
#include <linux/device.h>
+#include <linux/kobject.h>
#include <linux/string.h>
#include <linux/export.h>
#include <linux/pm_qos.h>
@@ -739,12 +740,18 @@ int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
int wakeup_sysfs_add(struct device *dev)
{
- return sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
+ int ret = sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
+
+ if (ret)
+ return ret;
+
+ return kobject_uevent(&dev->kobj, KOBJ_CHANGE);
}
void wakeup_sysfs_remove(struct device *dev)
{
sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
+ return kobject_uevent(&dev->kobj, KOBJ_CHANGE);
}
int pm_qos_sysfs_add_resume_latency(struct device *dev)
--
2.27.0.212.ge8ba1cc988-goog
On Tue, Jul 7, 2020 at 5:49 PM Abhishek Pandit-Subedi
<[email protected]> wrote:
>
> Udev rules that depend on the power/wakeup attribute don't get triggered
> correctly if device_set_wakeup_capable is called after the device is
> created. This can happen for several reasons (driver sets wakeup after
> device is created, wakeup is changed on parent device, etc) and it seems
> reasonable to emit a changed event when adding or removing attributes on
> the device.
>
> Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
> ---
>
> Changes in v3:
> - Simplified error handling
>
> Changes in v2:
> - Add newline at end of bt_dev_err
>
> drivers/base/power/sysfs.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
> index 24d25cf8ab1487..04c82373c8f240 100644
> --- a/drivers/base/power/sysfs.c
> +++ b/drivers/base/power/sysfs.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0
> /* sysfs entries for device PM */
> #include <linux/device.h>
> +#include <linux/kobject.h>
> #include <linux/string.h>
> #include <linux/export.h>
> #include <linux/pm_qos.h>
> @@ -739,12 +740,18 @@ int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
>
> int wakeup_sysfs_add(struct device *dev)
> {
> - return sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
> + int ret = sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
> +
> + if (ret)
> + return ret;
> +
> + return kobject_uevent(&dev->kobj, KOBJ_CHANGE);
Returning an error code here may be misleading, because the basic
operation (i.e. merging the attribute group) has succeeded already.
What about printing a message if kobject_uevent() returns an error and
returning 0 anyway?
> }
>
> void wakeup_sysfs_remove(struct device *dev)
> {
> sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
> + return kobject_uevent(&dev->kobj, KOBJ_CHANGE);
This is a void function, so it cannot return anything.
> }
>
> int pm_qos_sysfs_add_resume_latency(struct device *dev)
> --
I admit I didn't test this but I built it with allmodconfig.
Sadly, this only raised a warning instead of an error so I didn't go
look through the build logs (ignore the 5.4, the remote here is the
linux-pm git repo):
/usr/local/google/home/abhishekpandit/chromiumos/src/third_party/kernel/v5.4/drivers/base/power/sysfs.c:
In function ‘wakeup_sysfs_remove’:
/usr/local/google/home/abhishekpandit/chromiumos/src/third_party/kernel/v5.4/drivers/base/power/sysfs.c:754:9:
warning: ‘return’ with a value, in function returning void
[-Wreturn-type]
754 | return kobject_uevent(&dev->kobj, KOBJ_CHANGE);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/abhishekpandit/chromiumos/src/third_party/kernel/v5.4/drivers/base/power/sysfs.c:751:6:
note: declared here
751 | void wakeup_sysfs_remove(struct device *dev)
Will send up another fix.
Thanks
Abhishek
On Tue, Jul 7, 2020 at 9:00 AM Greg Kroah-Hartman
<[email protected]> wrote:
>
> On Tue, Jul 07, 2020 at 08:49:05AM -0700, Abhishek Pandit-Subedi wrote:
> > Udev rules that depend on the power/wakeup attribute don't get triggered
> > correctly if device_set_wakeup_capable is called after the device is
> > created. This can happen for several reasons (driver sets wakeup after
> > device is created, wakeup is changed on parent device, etc) and it seems
> > reasonable to emit a changed event when adding or removing attributes on
> > the device.
> >
> > Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
> > ---
> >
> > Changes in v3:
> > - Simplified error handling
> >
> > Changes in v2:
> > - Add newline at end of bt_dev_err
> >
> > drivers/base/power/sysfs.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
> > index 24d25cf8ab1487..04c82373c8f240 100644
> > --- a/drivers/base/power/sysfs.c
> > +++ b/drivers/base/power/sysfs.c
> > @@ -1,6 +1,7 @@
> > // SPDX-License-Identifier: GPL-2.0
> > /* sysfs entries for device PM */
> > #include <linux/device.h>
> > +#include <linux/kobject.h>
> > #include <linux/string.h>
> > #include <linux/export.h>
> > #include <linux/pm_qos.h>
> > @@ -739,12 +740,18 @@ int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
> >
> > int wakeup_sysfs_add(struct device *dev)
> > {
> > - return sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
> > + int ret = sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
> > +
> > + if (ret)
> > + return ret;
> > +
> > + return kobject_uevent(&dev->kobj, KOBJ_CHANGE);
> > }
> >
> > void wakeup_sysfs_remove(struct device *dev)
> > {
> > sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
> > + return kobject_uevent(&dev->kobj, KOBJ_CHANGE);
>
> Always test build and hopefully actually test, your patches before
> sending them out :(
>