Skip to contentSkip to conversation

ACPI: battery: Check for error code from devm_mutex_init() call

PATCH Applied Andy Shevchenko 3 participants 6 messages Oct 30, 2024 – Nov 4, 2024 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: battery: Check for error code from devm_mutex_init() call

Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.

Fixes 0710c1ce5045 ("ACPI: battery: initialize mutexes through devm_ APIs")
---
 drivers/acpi/battery.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/battery.c +6 -2
index 66662712e288..70f706d7634f 100644
@@ -1226,8 +1226,12 @@ static int acpi_battery_add(struct acpi_device *device)
 	strscpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
 	strscpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
 	device->driver_data = battery;
-	devm_mutex_init(&device->dev, &battery->lock);
-	devm_mutex_init(&device->dev, &battery->sysfs_lock);
+	result = devm_mutex_init(&device->dev, &battery->lock);
+	if (result)
+		return result;
+	result = devm_mutex_init(&device->dev, &battery->sysfs_lock);
+	if (result)
+		return result;
 	if (acpi_has_method(battery->device->handle, "_BIX"))
 		set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Reviewed-by on v1 1/1
#1 lore raw

Hi Andy,

Oct 30, 2024 10:28:03 Andy Shevchenko <[email protected]>:

Quoted 4 lines

Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.

Thanks!

Assuming you found this via some sort of tool and you already fixed up all the other places in the tree missing these checks, wouldn't it make sense to mark devm_mutex_init() as __must_check?

Quoted 2 lines
Fixes 0710c1ce5045 ("ACPI: battery: initialize mutexes through devm_ APIs")
Quoted 25 lines

---
drivers/acpi/battery.c | 8 ++++++--

1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/battery.c +6 -3
index 66662712e288..70f706d7634f 100644
@@ -1226,8 +1226,12 @@ static int acpi_battery_add(struct acpi_device *device)
     strscpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
     strscpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
     device->driver_data = battery;
-   devm_mutex_init(&device->dev, &battery->lock);
-   devm_mutex_init(&device->dev, &battery->sysfs_lock);
+   result = devm_mutex_init(&device->dev, &battery->lock);
+   if (result)
+       return result;
+   result = devm_mutex_init(&device->dev, &battery->sysfs_lock);
+   if (result)
+       return result;
     if (acpi_has_method(battery->device->handle, "_BIX"))
         set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
 
--

2.43.0.rc1.1336.g36b5255a03ac

#2 lore raw
Quoted 1 line · Thomas Weißschuh

Oct 30, 2024 10:28:03 Andy Shevchenko <[email protected]>:

...

Quoted 2 lines

Assuming you found this via some sort of tool and you already fixed up all the other places in the tree missing these checks,

The tool is called git grep.

Quoted 1 line

wouldn't it make sense to mark devm_mutex_init() as __must_check?

It's macro, any idea how to do that for the macros?

...

Quoted 1 line

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Oct 30, 2024 11:31:21 Andy Shevchenko <[email protected]>:

Quoted 8 lines · Thomas Weißschuh
Quoted 1 line

Oct 30, 2024 10:28:03 Andy Shevchenko <[email protected]>:

...

Quoted 1 line

wouldn't it make sense to mark devm_mutex_init() as __must_check?

It's macro, any idea how to do that for the macros?

It should work on __devm_mutex_init().
I don't think the expression macro  in between should interfere. Unfortunately I can't test it myself right now.

#4 lore raw
Quoted 3 lines · Thomas Weißschuh

Oct 30, 2024 11:31:21 Andy Shevchenko <[email protected]>:

Quoted 2 lines · Thomas Weißschuh
Quoted 1 line

Oct 30, 2024 10:28:03 Andy Shevchenko <[email protected]>:

...

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

wouldn't it make sense to mark devm_mutex_init() as __must_check?

It's macro, any idea how to do that for the macros?

It should work on __devm_mutex_init().
I don't think the expression macro  in between should interfere. Unfortunately I can't test it myself right now.

Okay, when you have a patch, feel free to Cc me for review.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#5 lore raw
In reply to Thomas Weißschuh
Quoted 12 lines · Thomas Weißschuh

Hi Andy,

Oct 30, 2024 10:28:03 Andy Shevchenko <[email protected]>:

Quoted 4 lines

Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.

Thanks!

Quoted 7 lines

Assuming you found this via some sort of tool and you already fixed up all the other places in the tree missing these checks, wouldn't it make sense to mark devm_mutex_init() as __must_check?

Quoted 2 lines
Fixes 0710c1ce5045 ("ACPI: battery: initialize mutexes through devm_ APIs")

Applied, thanks!

Quoted 26 lines
Quoted 25 lines

---
drivers/acpi/battery.c | 8 ++++++--

1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/battery.c +6 -3
index 66662712e288..70f706d7634f 100644
@@ -1226,8 +1226,12 @@ static int acpi_battery_add(struct acpi_device *device)
    strscpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
    strscpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
    device->driver_data = battery;
-   devm_mutex_init(&device->dev, &battery->lock);
-   devm_mutex_init(&device->dev, &battery->sysfs_lock);
+   result = devm_mutex_init(&device->dev, &battery->lock);
+   if (result)
+       return result;
+   result = devm_mutex_init(&device->dev, &battery->sysfs_lock);
+   if (result)
+       return result;
    if (acpi_has_method(battery->device->handle, "_BIX"))
        set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
 
--

2.43.0.rc1.1336.g36b5255a03ac