From dd637f5cd5f334d2d014872544470031415cec3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 4 Jun 2024 23:41:24 +0200 Subject: [PATCH] platform/x86: dell-pc: avoid double free and invalid unregistration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Lyndon Sanche Link: https://lore.kernel.org/r/20240604-dell-pc-double-free-v1-1-6d81255b2a44@weissschuh.net Reviewed-by: Ilpo Järvinen Signed-off-by: Ilpo Järvinen --- drivers/platform/x86/dell/dell-pc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/dell/dell-pc.c b/drivers/platform/x86/dell/dell-pc.c index dfe09c463d03e..972385ca1990b 100644 --- a/drivers/platform/x86/dell/dell-pc.c +++ b/drivers/platform/x86/dell/dell-pc.c @@ -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; } -- 2.49.0