]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/x86: classmate-laptop: Address memory leaks on driver removal
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 11 May 2026 20:03:34 +0000 (22:03 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Wed, 20 May 2026 10:07:07 +0000 (13:07 +0300)
Switch over cmpc_accel_add_v4() and cmpc_accel_add() to using
devm_kzalloc() for allocating the accel object which will cause it
to be freed automatically on device removal, so it won't be leaked
any more.

This also simplifies the rollback paths in these functions somewhat.

Fixes: 529aa8cb0a59 ("classmate-laptop: add support for Classmate PC ACPI devices")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Link: https://patch.msgid.link/10846403.nUPlyArG6x@rafael.j.wysocki
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/classmate-laptop.c

index e6eed3d65580ae9743c786a4caefd8106ff95381..a5fe34211afb991fb60a948748917d85b7d934d4 100644 (file)
@@ -400,7 +400,7 @@ static int cmpc_accel_add_v4(struct acpi_device *acpi)
        struct input_dev *inputdev;
        struct cmpc_accel *accel;
 
-       accel = kmalloc_obj(*accel);
+       accel = devm_kzalloc(&acpi->dev, sizeof(*accel), GFP_KERNEL);
        if (!accel)
                return -ENOMEM;
 
@@ -411,7 +411,7 @@ static int cmpc_accel_add_v4(struct acpi_device *acpi)
 
        error = device_create_file(&acpi->dev, &cmpc_accel_sensitivity_attr_v4);
        if (error)
-               goto failed_sensitivity;
+               return error;
 
        accel->g_select = CMPC_ACCEL_G_SELECT_DEFAULT;
        cmpc_accel_set_g_select_v4(acpi->handle, accel->g_select);
@@ -434,8 +434,6 @@ failed_input:
        device_remove_file(&acpi->dev, &cmpc_accel_g_select_attr_v4);
 failed_g_select:
        device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr_v4);
-failed_sensitivity:
-       kfree(accel);
        return error;
 }
 
@@ -650,7 +648,7 @@ static int cmpc_accel_add(struct acpi_device *acpi)
        struct input_dev *inputdev;
        struct cmpc_accel *accel;
 
-       accel = kmalloc_obj(*accel);
+       accel = devm_kzalloc(&acpi->dev, sizeof(*accel), GFP_KERNEL);
        if (!accel)
                return -ENOMEM;
 
@@ -659,7 +657,7 @@ static int cmpc_accel_add(struct acpi_device *acpi)
 
        error = device_create_file(&acpi->dev, &cmpc_accel_sensitivity_attr);
        if (error)
-               goto failed_file;
+               return error;
 
        error = cmpc_add_acpi_notify_device(acpi, "cmpc_accel",
                                            cmpc_accel_idev_init);
@@ -673,8 +671,6 @@ static int cmpc_accel_add(struct acpi_device *acpi)
 
 failed_input:
        device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr);
-failed_file:
-       kfree(accel);
        return error;
 }