From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"Kristen C. Accardi" <kristen.c.accardi@intel.com>,
Len Brown <lenb@kernel.org>
Subject: Re: [PATCH 1/4] ACPI / PM: Expose power states of ACPI devices to user space
Date: Tue, 22 Jan 2013 15:47:18 -0800 [thread overview]
Message-ID: <20130122234718.GC694@kroah.com> (raw)
In-Reply-To: <4706454.hY2fLkUfhN@vostro.rjw.lan>
On Tue, Jan 22, 2013 at 03:25:15AM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Make it possible to retrieve the current power state of a device with
> ACPI power management from user space via sysfs by adding two new
> attributes, power_state and real_power_state, to the sysfs directory
> associated with the struct acpi_device object representing the
> device's ACPI node.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> Documentation/ABI/testing/sysfs-devices-power_state | 20 ++++++
> Documentation/ABI/testing/sysfs-devices-real_power_state | 23 +++++++
> drivers/acpi/scan.c | 49 ++++++++++++++-
> 3 files changed, 91 insertions(+), 1 deletion(-)
>
> Index: linux-pm/drivers/acpi/scan.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/scan.c
> +++ linux-pm/drivers/acpi/scan.c
> @@ -178,6 +178,32 @@ err_out:
> }
> EXPORT_SYMBOL(acpi_bus_hot_remove_device);
>
> +static ssize_t real_power_state_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct acpi_device *adev = to_acpi_device(dev);
> + int state;
> + int ret;
> +
> + ret = acpi_device_get_power(adev, &state);
> + if (ret)
> + return ret;
> +
> + return sprintf(buf, "%s\n", acpi_power_state_string(state));
> +}
> +
> +static DEVICE_ATTR(real_power_state, 0444, real_power_state_show, NULL);
> +
> +static ssize_t power_state_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct acpi_device *adev = to_acpi_device(dev);
> +
> + return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
> +}
> +
> +static DEVICE_ATTR(power_state, 0444, power_state_show, NULL);
> +
> static ssize_t
> acpi_eject_store(struct device *d, struct device_attribute *attr,
> const char *buf, size_t count)
> @@ -369,8 +395,22 @@ static int acpi_device_setup_files(struc
> * hot-removal function from userland.
> */
> status = acpi_get_handle(dev->handle, "_EJ0", &temp);
> - if (ACPI_SUCCESS(status))
> + if (ACPI_SUCCESS(status)) {
> result = device_create_file(&dev->dev, &dev_attr_eject);
> + if (result)
> + return result;
> + }
> +
> + if (dev->flags.power_manageable) {
> + result = device_create_file(&dev->dev, &dev_attr_power_state);
> + if (result)
> + return result;
> +
> + if (dev->power.flags.power_resources)
> + result = device_create_file(&dev->dev,
> + &dev_attr_real_power_state);
> + }
> +
It isn't your fault, but I just noticed this when reading patch 2/4, but
I think you are racing userspace here. The device is registered,
userspace is notified that the device is present, and _then_ the acpi
core creates the sysfs files for the device.
That's not good, and needs to be fixed, especially now that you are
adding more and more sysfs files for these ACPI devices.
To do that, you need to set up "default" files for ACPI devices, they
can be enabled or not by the driver core, and will be created before the
event that the device is created is sent to userspace.
Care to fix that all up in a follow-on patchset before some tools start
to get confused?
thanks,
greg k-h
next prev parent reply other threads:[~2013-01-22 23:47 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-20 14:51 [RFC][PATCH 0/3] ACPI / PM: Export power resources information to user space Rafael J. Wysocki
2013-01-20 14:53 ` [RFC][PATCH 1/3] ACPI / PM: Expose reference count values of ACPI power resources Rafael J. Wysocki
2013-01-20 14:54 ` [RFC][PATCH 2/3] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-20 14:57 ` [RFC][PATCH 3/3] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-20 23:37 ` [RFC][PATCH 0/3] ACPI / PM: Export power resources information " Greg Kroah-Hartman
2013-01-21 0:11 ` Rafael J. Wysocki
2013-01-21 0:48 ` [RFC][Update][PATCH " Rafael J. Wysocki
2013-01-21 0:50 ` [RFC][Update][PATCH 1/3] ACPI / PM: Expose reference count values of ACPI power resources Rafael J. Wysocki
2013-01-21 0:51 ` [RFC][Update][PATCH 2/3] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-21 0:53 ` [RFC][Update][PATCH 3/3] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-21 13:03 ` [RFC][Update 2][PATCH 0/4] ACPI / PM: Export power information " Rafael J. Wysocki
2013-01-21 13:04 ` [RFC][Update 2][PATCH 1/4] ACPI / PM: Export power states of ACPI devices via sysfs Rafael J. Wysocki
2013-01-21 20:53 ` Greg Kroah-Hartman
2013-01-21 22:27 ` Rafael J. Wysocki
2013-01-21 22:26 ` Greg Kroah-Hartman
2013-01-21 22:59 ` Rafael J. Wysocki
2013-01-21 23:08 ` Greg Kroah-Hartman
2013-01-22 0:48 ` Rafael J. Wysocki
2013-01-21 13:05 ` [RFC][Update 2][PATCH 2/4] ACPI / PM: Expose reference count values of ACPI power resources Rafael J. Wysocki
2013-01-21 20:53 ` Greg Kroah-Hartman
2013-01-21 22:35 ` Rafael J. Wysocki
2013-01-21 22:33 ` Greg Kroah-Hartman
2013-01-21 13:06 ` [RFC][Update 2][PATCH 3/4] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-21 20:58 ` Greg Kroah-Hartman
2013-01-21 22:41 ` Rafael J. Wysocki
2013-01-21 22:38 ` Greg Kroah-Hartman
2013-01-21 13:08 ` [RFC][Update 2][PATCH 4/4] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-21 20:58 ` Greg Kroah-Hartman
2013-01-21 22:42 ` Rafael J. Wysocki
2013-01-22 2:15 ` [PATCH 0/4] ACPI / PM: Export power information " Rafael J. Wysocki
2013-01-22 2:25 ` [PATCH 1/4] ACPI / PM: Expose power states of ACPI devices " Rafael J. Wysocki
2013-01-22 23:42 ` Greg Kroah-Hartman
2013-01-22 23:47 ` Greg Kroah-Hartman [this message]
2013-01-23 0:01 ` Rafael J. Wysocki
2013-01-22 23:58 ` Greg Kroah-Hartman
2013-01-22 2:26 ` [PATCH 2/4] ACPI / PM: Expose current status of ACPI power resources Rafael J. Wysocki
2013-01-22 23:49 ` Greg Kroah-Hartman
2013-01-22 2:27 ` [PATCH 3/4] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-22 23:51 ` Greg Kroah-Hartman
2013-01-23 0:03 ` Rafael J. Wysocki
2013-01-22 2:28 ` [PATCH 4/4] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-22 23:56 ` Greg Kroah-Hartman
2013-01-23 0:08 ` Rafael J. Wysocki
2013-01-23 0:17 ` Rafael J. Wysocki
2013-01-23 0:28 ` Rafael J. Wysocki
2013-01-23 1:05 ` Greg Kroah-Hartman
2013-01-23 14:01 ` Rafael J. Wysocki
2013-01-23 1:03 ` Greg Kroah-Hartman
2013-01-23 14:00 ` Rafael J. Wysocki
2013-01-23 17:56 ` [Update][PATCH 0/5] ACPI / PM: Export power information " Rafael J. Wysocki
2013-01-23 17:58 ` [Update][PATCH 1/5] ACPI / scan: Prevent device add uevents from racing with " Rafael J. Wysocki
2013-01-24 0:33 ` Greg Kroah-Hartman
2013-01-23 17:59 ` [Update][PATCH 2/5] ACPI / PM: Expose power states of ACPI devices to " Rafael J. Wysocki
2013-01-23 18:00 ` [Update][PATCH 3/5] ACPI / PM: Expose current status of ACPI power resources Rafael J. Wysocki
2013-01-23 18:00 ` [Update][PATCH 4/5] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-24 0:33 ` Greg Kroah-Hartman
2013-01-25 20:13 ` [patch] sysfs: Fix build when sysfs is disabled David Rientjes
2013-01-25 20:42 ` Greg Kroah-Hartman
2013-01-25 20:53 ` Rafael J. Wysocki
2013-01-25 20:52 ` Rafael J. Wysocki
2013-01-25 21:34 ` David Rientjes
2013-01-23 18:01 ` [Update][PATCH 5/5] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-24 0:34 ` Greg Kroah-Hartman
2013-01-24 0:34 ` [Update][PATCH 0/5] ACPI / PM: Export power information " Greg Kroah-Hartman
2013-01-24 12:34 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130122234718.GC694@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=kristen.c.accardi@intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rjw@sisk.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).