From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6279247CC96; Tue, 16 Jun 2026 18:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781636357; cv=none; b=udwLMnbHf3gJjV2PqXmkijSI8f1le3PP6x/V0ktBonTCX7UnzRTv/vFGJjqFVXqkOBSVH9w+E3HBhTkkY4FeKBUvxYegZxDXb2a6+CFydE8Q31qaNtpON4HEzpL7QPrNeaO+bPDWB7RTWr+13hvU+lSnwt3NcA6p1Vgq1hDuNwk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781636357; c=relaxed/simple; bh=WU+vBU2kgOYwCRxtg+dx++jny3PIg4ycVNyA3DzMSi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i+7tR1FOgxjntPHS1iHQ2ee3tjHzJ//vpmxiC0XBR08B2cBLJBQP9c+ZkePq4OM5QBGe4bqmodgdZQQPF3MW/K/VkYJQCSo0XddHONmjdMDlQA5yO/RDueXkRNQtleBYIHz6IXrQNSWK22wOQ3ylQx50VgmKLikOCo5BXYxifm4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JtG0r09r; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JtG0r09r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43AFC1F000E9; Tue, 16 Jun 2026 18:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781636356; bh=x+NqU4jW1fFQVLLnyLVP6CuGXTBeOSEY2FZ7M/jvUM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JtG0r09r88mHmQ0GQxWEWKuFW0Xwqm0663huaIxqVZrYH98e+OGtnihbNmAIF+BS+ KjdxhO3aIFg+2Z0oo7aTuu5hvgfjft8Hb9cjY6GlpL/3FAWgALKPOFSMmJ1kKfbe01 67NeXhlA28x4Bt1LIV7q1r1AE7Hs2kLWvMp6j12M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.10 224/342] thermal: core: Fix thermal zone governor cleanup issues Date: Tue, 16 Jun 2026 20:28:40 +0530 Message-ID: <20260616145058.635809566@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145048.348037099@linuxfoundation.org> References: <20260616145048.348037099@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Rafael J. Wysocki" [ Upstream commit 41ff66baf81c6541f4f985dd7eac4494d03d9440 ] If thermal_zone_device_register_with_trips() fails after adding a thermal governor to the thermal zone being registered, the governor is not removed from it as appropriate which may lead to a memory leak. In turn, thermal_zone_device_unregister() calls thermal_set_governor() without acquiring the thermal zone lock beforehand which may race with a governor update via sysfs and may lead to a use-after-free in that case. Address these issues by adding two thermal_set_governor() calls, one to thermal_release() to remove the governor from the given thermal zone, and one to the thermal zone registration error path to cover failures preceding the thermal zone device registration. Fixes: e33df1d2f3a0 ("thermal: let governors have private data for each thermal zone") Cc: All applicable Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/5092923.31r3eYUQgx@rafael.j.wysocki [ adapted context for missing mutex_destroy/complete ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/thermal_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -986,6 +986,7 @@ static void thermal_release(struct devic sizeof("thermal_zone") - 1)) { tz = to_thermal_zone(dev); thermal_zone_destroy_device_groups(tz); + thermal_set_governor(tz, NULL); kfree(tz); } else if (!strncmp(dev_name(dev), "cooling_device", sizeof("cooling_device") - 1)) { @@ -1447,8 +1448,10 @@ thermal_zone_device_register(const char /* sys I/F */ /* Add nodes that are always present via .groups */ result = thermal_zone_create_device_groups(tz, mask); - if (result) + if (result) { + thermal_set_governor(tz, NULL); goto remove_id; + } /* A new thermal zone needs to be updated anyway. */ atomic_set(&tz->need_update, 1); @@ -1571,8 +1574,6 @@ void thermal_zone_device_unregister(stru cancel_delayed_work_sync(&tz->poll_queue); - thermal_set_governor(tz, NULL); - thermal_remove_hwmon_sysfs(tz); ida_simple_remove(&thermal_tz_ida, tz->id); ida_destroy(&tz->ida);