From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Jaroslav Pulchart <jaroslav.pulchart@gooddata.com>,
LKML <linux-kernel@vger.kernel.org>,
Linux ACPI <linux-acpi@vger.kernel.org>,
linux-hwmon@vger.kernel.org
Subject: [PATCH v1 1/3] hwmon: (acpi_power_meter) Drop redundant checks from three functions
Date: Sun, 01 Mar 2026 14:17:19 +0100 [thread overview]
Message-ID: <5085645.31r3eYUQgx@rafael.j.wysocki> (raw)
In-Reply-To: <5974797.DvuYhMxLoT@rafael.j.wysocki>
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Since acpi_power_meter_notify() and acpi_power_meter_remove() are
.notify() and .remove() callback functions of an ACPI driver,
respectively, the first argument of the former and the only argument
of the latter cannot be NULL. Likewise, the acpi_power_meter_resume()
argument cannot be NULL because it is a system resume callback
function.
Moreover, since all of these functions can only run after
acpi_power_meter_add() has returned 0, the driver_data field in the
struct acpi_device object used by them cannot be NULL either.
Accordingly, drop the redundant "device" checks against NULL from
acpi_power_meter_notify() and acpi_power_meter_remove(), drop the
redundant "dev" check against NULL from acpi_power_meter_resume(),
and drop the redundant acpi_driver_data() checks against NULL from
all of these functions.
Additionally, combine the initialization of the "resource" local
variable in acpi_power_meter_notify() and acpi_power_meter_remove()
with its declaration.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/hwmon/acpi_power_meter.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 1e3fab5f7946..49e57c20ef70 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -816,14 +816,9 @@ static int read_capabilities(struct acpi_power_meter_resource *resource)
/* Handle ACPI event notifications */
static void acpi_power_meter_notify(struct acpi_device *device, u32 event)
{
- struct acpi_power_meter_resource *resource;
+ struct acpi_power_meter_resource *resource = acpi_driver_data(device);
int res;
- if (!device || !acpi_driver_data(device))
- return;
-
- resource = acpi_driver_data(device);
-
guard(mutex)(&acpi_notify_lock);
switch (event) {
@@ -956,12 +951,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
static void acpi_power_meter_remove(struct acpi_device *device)
{
- struct acpi_power_meter_resource *resource;
+ struct acpi_power_meter_resource *resource = acpi_driver_data(device);
- if (!device || !acpi_driver_data(device))
- return;
-
- resource = acpi_driver_data(device);
if (!IS_ERR(resource->hwmon_dev))
hwmon_device_unregister(resource->hwmon_dev);
@@ -975,12 +966,7 @@ static int acpi_power_meter_resume(struct device *dev)
{
struct acpi_power_meter_resource *resource;
- if (!dev)
- return -EINVAL;
-
resource = acpi_driver_data(to_acpi_device(dev));
- if (!resource)
- return -EINVAL;
free_capabilities(resource);
read_capabilities(resource);
--
2.51.0
next prev parent reply other threads:[~2026-03-01 13:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-01 13:16 [PATCH v1 0/3] hwmon: (acpi_power_meter) Bind the driver to a platform device Rafael J. Wysocki
2026-03-01 13:17 ` Rafael J. Wysocki [this message]
2026-03-01 23:53 ` [PATCH v1 1/3] hwmon: (acpi_power_meter) Drop redundant checks from three functions Guenter Roeck
2026-03-01 13:18 ` [PATCH v1 2/3] hwmon: (acpi_power_meter) Register ACPI notify handler directly Rafael J. Wysocki
2026-03-01 23:54 ` Guenter Roeck
2026-03-01 13:18 ` [PATCH v1 3/3] hwmon: (acpi_power_meter) Convert ACPI driver to a platform one Rafael J. Wysocki
2026-03-02 0:01 ` Guenter Roeck
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=5085645.31r3eYUQgx@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=jaroslav.pulchart@gooddata.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/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
all inboxes | Powered by JetHome®