]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
platform/x86: dell-pc: avoid double free and invalid unregistration
authorThomas Weißschuh <linux@weissschuh.net>
Tue, 4 Jun 2024 21:41:24 +0000 (23:41 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 7 Jun 2024 13:18:35 +0000 (16:18 +0300)
If platform_profile_register() fails it does kfree(thermal_handler) and
leaves the pointer value around.
Any call to thermal_cleanup() will try to kfree(thermal_handler) again.
This will happen right away in dell_init().
In addition, platform_profile_remove() will be called although no
profile is registered.

NULL out the thermal_handler, so thermal_cleanup() avoids the double free.

Fixes: 996ad4129810 ("platform/x86: dell-pc: Implement platform_profile")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Lyndon Sanche <lsanche@lyndeno.ca>
Link: https://lore.kernel.org/r/20240604-dell-pc-double-free-v1-1-6d81255b2a44@weissschuh.net
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/dell/dell-pc.c

index dfe09c463d03e6124a38306929a2e54c1ad00adf..972385ca1990b00738b73331baae484fa6d4b905 100644 (file)
@@ -261,8 +261,10 @@ static int thermal_init(void)
 
        /* Clean up if failed */
        ret = platform_profile_register(thermal_handler);
-       if (ret)
+       if (ret) {
                kfree(thermal_handler);
+               thermal_handler = NULL;
+       }
 
        return ret;
 }