From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Linux PM <linux-pm@vger.kernel.org>,
Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH v1] ACPI: PM: Fix NULL argument handling in acpi_device_get/set_power()
Date: Mon, 29 Aug 2022 17:21:43 +0200 [thread overview]
Message-ID: <12062887.O9o76ZdvQC@kreacher> (raw)
In-Reply-To: <12036348.O9o76ZdvQC@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
In principle, it should be valid to pass NULL as the ACPI device
pointer to acpi_device_get_power() and acpi_device_set_power() and they
both are expected to return -EINVAL in that case, but that has been
broken recently by commit 62fcb99bdf10 ("ACPI: Drop parent field from
struct acpi_device") which has caused the ACPI device pointer to be
dereferenced in these functions before the NULL check.
Fix that and while at it make acpi_device_set_power() only use the
parent field if the target ACPI device object's ignore_parent flag
in not set.
Fixes: 62fcb99bdf10 ("ACPI: Drop parent field from struct acpi_device")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
linux-next material.
---
drivers/acpi/device_pm.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
Index: linux-pm/drivers/acpi/device_pm.c
===================================================================
--- linux-pm.orig/drivers/acpi/device_pm.c
+++ linux-pm/drivers/acpi/device_pm.c
@@ -74,13 +74,15 @@ static int acpi_dev_pm_explicit_get(stru
*/
int acpi_device_get_power(struct acpi_device *device, int *state)
{
- struct acpi_device *parent = acpi_dev_parent(device);
int result = ACPI_STATE_UNKNOWN;
+ struct acpi_device *parent;
int error;
if (!device || !state)
return -EINVAL;
+ parent = acpi_dev_parent(device);
+
if (!device->flags.power_manageable) {
/* TBD: Non-recursive algorithm for walking up hierarchy. */
*state = parent ? parent->power.state : ACPI_STATE_D0;
@@ -159,7 +161,6 @@ static int acpi_dev_pm_explicit_set(stru
*/
int acpi_device_set_power(struct acpi_device *device, int state)
{
- struct acpi_device *parent = acpi_dev_parent(device);
int target_state = state;
int result = 0;
@@ -192,13 +193,17 @@ int acpi_device_set_power(struct acpi_de
return -ENODEV;
}
- if (!device->power.flags.ignore_parent && parent &&
- state < parent->power.state) {
- acpi_handle_debug(device->handle,
- "Cannot transition to %s for parent in %s\n",
- acpi_power_state_string(state),
- acpi_power_state_string(parent->power.state));
- return -ENODEV;
+ if (!device->power.flags.ignore_parent) {
+ struct acpi_device *parent;
+
+ parent = acpi_dev_parent(device);
+ if (parent && state < parent->power.state) {
+ acpi_handle_debug(device->handle,
+ "Cannot transition to %s for parent in %s\n",
+ acpi_power_state_string(state),
+ acpi_power_state_string(parent->power.state));
+ return -ENODEV;
+ }
}
/*
next prev parent reply other threads:[~2022-08-29 15:21 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 16:11 [PATCH v1 0/5] ACPI: Device enumeration rearrangements and parent field elimination Rafael J. Wysocki
2022-08-10 16:14 ` [PATCH v1 1/5] ACPI: Rename acpi_bus_get/put_acpi_device() Rafael J. Wysocki
2022-08-10 16:30 ` Guenter Roeck
2022-08-10 16:15 ` [PATCH v1 2/5] ACPI: scan: Rename acpi_bus_get_parent() and rearrange it Rafael J. Wysocki
2022-08-12 13:08 ` Punit Agrawal
2022-08-10 16:16 ` [PATCH v1 3/5] ACPI: scan: Rearrange initialization of ACPI device objects Rafael J. Wysocki
2022-08-10 16:17 ` [PATCH v1 4/5] ACPI: scan: Eliminate __acpi_device_add() Rafael J. Wysocki
2022-08-10 16:23 ` [PATCH v1 5/5][RFT] ACPI: Drop parent field from struct acpi_device Rafael J. Wysocki
2022-08-10 16:33 ` Mark Brown
2022-08-10 17:10 ` Mika Westerberg
2022-08-12 15:14 ` Wei Liu
2022-08-24 16:59 ` [PATCH v2 5/5] " Rafael J. Wysocki
2022-08-24 16:59 ` Rafael J. Wysocki
2022-08-24 18:23 ` Andy Shevchenko
2022-08-24 18:23 ` Andy Shevchenko
2022-08-24 18:34 ` Rafael J. Wysocki
2022-08-24 18:34 ` Rafael J. Wysocki
2022-08-27 13:19 ` Hanjun Guo
2022-08-27 13:19 ` Hanjun Guo
2022-08-29 15:54 ` Rafael J. Wysocki
2022-08-29 15:54 ` Rafael J. Wysocki
2022-08-30 21:29 ` Michael Kelley (LINUX)
2022-08-30 21:29 ` Michael Kelley (LINUX)
2022-08-12 13:11 ` [PATCH v1 0/5] ACPI: Device enumeration rearrangements and parent field elimination Punit Agrawal
2022-08-23 16:25 ` Rafael J. Wysocki
2022-08-29 15:21 ` Rafael J. Wysocki [this message]
2022-08-29 15:53 ` [PATCH v1] ACPI: Drop redundant acpi_dev_parent() header Rafael J. Wysocki
2022-08-30 2:17 ` Hanjun Guo
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=12062887.O9o76ZdvQC@kreacher \
--to=rjw@rjwysocki.net \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.