ACPI: battery: Check for error code from devm_mutex_init() call
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 30 Oct 2024 16:27:54 +0000 (18:27 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 4 Nov 2024 16:49:47 +0000 (17:49 +0100)
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")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://patch.msgid.link/20241030162754.2110946-1-andriy.shevchenko@linux.intel.com
[ rjw: Added 2 empty code lines ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/battery.c

index d4dc4d19a2fd892bdfb1a809efa2b611b68e3717..aed4a37da03ea2221e9a0caae4eaae13da6364f2 100644 (file)
@@ -1225,8 +1225,14 @@ 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);