Re: [PATCH 1/2] power: sysfs: Add link to wakeup class device.

From: Matthias Kaehlcke
Date: Fri Sep 06 2019 - 19:40:32 EST


Hi Ravi,

On Wed, Jul 24, 2019 at 10:43:54AM -0700, Ravi Chandra Sadineni wrote:
> https://patchwork.kernel.org/patch/11045069/ creates a virtual
> device

To refer to unsubmitted patches in the commit message it is
probably better to use the subject ("PM / wakeup: show wakeup
sources stats in sysfs") and add a link after '---', or say
"${subject}" [1] and put the link at the bottom of the commit message

You might want to try again now that the patch has landed :)

> under wakeup class for each wake capable device exposing all related
> sysfs attributes. But there isn't a symlink from the actual device
> node to these virtual devices. This patch creates a symlink from the
> actual device to the corresponding wakeup_source device under wakeup
> class.

> Signed-off-by: Ravi Chandra Sadineni <ravisadineni@xxxxxxxxxxxx>
> ---
> drivers/base/power/power.h | 2 ++
> drivers/base/power/sysfs.c | 25 +++++++++++++++++++++++++
> drivers/base/power/wakeup.c | 2 ++
> 3 files changed, 29 insertions(+)
>
> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> index c511def48b48..32b0f5c080a9 100644
> --- a/drivers/base/power/power.h
> +++ b/drivers/base/power/power.h
> @@ -67,6 +67,8 @@ extern void dpm_sysfs_remove(struct device *dev);
> extern void rpm_sysfs_remove(struct device *dev);
> extern int wakeup_sysfs_add(struct device *dev);
> extern void wakeup_sysfs_remove(struct device *dev);
> +extern void wakeup_source_sysfs_link_add(struct device *dev);
> +extern void wakeup_source_sysfs_link_remove(struct device *dev);

the names seem a bit clunky, how about wakeup_sysfs_add/remove_link()?

> extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
> extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
> extern int pm_qos_sysfs_add_flags(struct device *dev);
> diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
> index d713738ce796..fbbdb7b16ac5 100644
> --- a/drivers/base/power/sysfs.c
> +++ b/drivers/base/power/sysfs.c
> @@ -95,6 +95,7 @@
> const char power_group_name[] = "power";
> EXPORT_SYMBOL_GPL(power_group_name);
>
> +static const char wakeup_source_symlink_name[] = "wakeup_source";
> static const char ctrl_auto[] = "auto";
> static const char ctrl_on[] = "on";
>
> @@ -679,6 +680,30 @@ int dpm_sysfs_add(struct device *dev)
> return rc;
> }
>
> +void wakeup_source_sysfs_link_add(struct device *dev)
> +{
> + struct wakeup_source *ws;
> + int err;
> +
> + ws = dev->power.wakeup;
> + if (ws && ws->dev) {
> + err = sysfs_add_link_to_group(&dev->kobj, power_group_name,
> + &ws->dev->kobj, wakeup_source_symlink_name);
> + if (err) {
> + dev_err(dev,
> + "could not add %s symlink err %d\n",

I'd suggest

"could not add '%s' symlink: %d\n",

or

"could not add 'wakeup_source' symlink: %d\n",

the latter is easier to grep.

> + wakeup_source_symlink_name,
> + err);
> + }
> + }
> +}
> +
> +void wakeup_source_sysfs_link_remove(struct device *dev)
> +{
> + sysfs_remove_link_from_group(&dev->kobj, power_group_name,
> + wakeup_source_symlink_name);
> +}
> +
> int wakeup_sysfs_add(struct device *dev)
> {
> return sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> index fe779fe13a7f..87dfe401b035 100644
> --- a/drivers/base/power/wakeup.c
> +++ b/drivers/base/power/wakeup.c
> @@ -270,6 +270,7 @@ static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws)
> if (dev->power.wakeirq)
> device_wakeup_attach_irq(dev, dev->power.wakeirq);
> spin_unlock_irq(&dev->power.lock);
> + wakeup_source_sysfs_link_add(dev);
> return 0;
> }
>
> @@ -391,6 +392,7 @@ static struct wakeup_source *device_wakeup_detach(struct device *dev)
> ws = dev->power.wakeup;
> dev->power.wakeup = NULL;
> spin_unlock_irq(&dev->power.lock);
> + wakeup_source_sysfs_link_remove(dev);

you want to do this before the wakeup source is detached.