[PATCH v1 1/3] hwmon: (acpi_power_meter) Drop redundant checks from three functions
From: Rafael J. Wysocki
Date: Sun Mar 01 2026 - 08:20:20 EST
From: "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>
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@xxxxxxxxx>
---
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