platform/x86: dell-pc: avoid double free and invalid unregistration

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: 996ad41298 ("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>
This commit is contained in:
Thomas Weißschuh 2024-06-04 23:41:24 +02:00 committed by Ilpo Järvinen
parent 4894c364d5
commit dd637f5cd5
No known key found for this signature in database
GPG Key ID: 59AC4F6153E5CE31

View 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;
}