From nobody Sun Feb 8 20:00:20 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84556C001E0 for ; Fri, 7 Jul 2023 20:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232322AbjGGUiB (ORCPT ); Fri, 7 Jul 2023 16:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232282AbjGGUhy (ORCPT ); Fri, 7 Jul 2023 16:37:54 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B241FEB for ; Fri, 7 Jul 2023 13:37:52 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-313f1085ac2so2332332f8f.1 for ; Fri, 07 Jul 2023 13:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762271; x=1691354271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yUcFRaFpRqekh1XutoF5FSJVV/l/MywjnadXba/M7Ls=; b=N6kGPoHEYocK0GLv1K4DMPcmhTN9rJUEJYHQDBpPnfUl7IyxvK6/Ta+cmCpT9vbujb T8ySrUdHyECVCmx17VBkSNP2xyH84fTiKPMpFn/JRSzACYvPlQnUpN3eEvAWTuEek4NE Z3lzcFeqAnlPOyN6Or0QhPdZaxYXvknAIfZUBMVtEqMYAt/Qs6sRoRCd+XYxvpTa97Tq SWA4fCtMO3gUqH5BCbR1BpSspfdsaT7hzX57Lf8ZTNmZJjw+T9GNI/fcPgmMCsJNoeTM K0VryCKVNLk0E6BTgEOa5sU7t3oDtI/hGZOfeLzup+iHj1SR3LVw/uUfP3dgODdRdBrB g2vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762271; x=1691354271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yUcFRaFpRqekh1XutoF5FSJVV/l/MywjnadXba/M7Ls=; b=gFyo2TlzNs8gW1Sv71+RdUExk5y2VIbR+EK1bGw/kvXMTEwxiU8x6e0eOWP93D6+BS 74d+vENRs6RJsY5A4sjyS/1OCeTHbmyOrKRR98UuqDKw4h0pam7KEEtuD8XRNImYHw3B vcmL2UAk2QAyrR/kFxDbN282jza6QKYdLb2yGXwpbj27l77ibYddvtNlwnR7bhU5jn7C aMaLoMr7F5qY+Xg/Bo/qagADOoTi+85mY2Wz7acqzepOCtbXO/3fvF7assNNxV0RJ2cg iQFctsF1eNRgVK0HP2abNpZPoaXnG1ovA53FqYk6cwmUSaFbcuIej28dWMHpl30zSuzg M1Ug== X-Gm-Message-State: ABy/qLZoITu5JADOYUgrzbAFdHzWf5A5CVGdCW3s0JKYhgI7sBAn8ecd LaqKZ64RQqkENBeWfymY6uJOyQ== X-Google-Smtp-Source: APBJJlGUPPMDg0BAP/ewPfJ5t0eKHzjC40OAub6ONAm9mN5qz2r2Pjv2SffMR8kpntYaWX+Ue7TP8A== X-Received: by 2002:adf:ee03:0:b0:314:15b7:1fb4 with SMTP id y3-20020adfee03000000b0031415b71fb4mr4868023wrn.52.1688762271183; Fri, 07 Jul 2023 13:37:51 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id i4-20020adfefc4000000b003143be36d99sm5260674wrp.58.2023.07.07.13.37.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:37:50 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, thierry.reding@gmail.com, linux-kernel@vger.kernel.org, srinivas.pandruvada@linux.intel.com, Amit Kucheria , Zhang Rui , Lukasz Luba Subject: [PATCH v2 1/4] thermal/core: Hardening the self-encapsulation Date: Fri, 7 Jul 2023 22:37:28 +0200 Message-Id: <20230707203731.848188-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707203731.848188-1-daniel.lezcano@linaro.org> References: <20230707203731.848188-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The thermal private header has leaked all around the drivers which interacted with the core internals. The thermal zone structure which was part of the exported header led also to a leakage of the fields into the different drivers, making very difficult to improve the core code without having to change the drivers. Now we fixed how the thermal drivers were interacting with the thermal zones (actually fixed how they should not interact). The thermal zone structure has been moved to the private thermal core header. This header has been removed from the different drivers and must belong to the core code only. In order to prevent this private header to be included again in the drivers, make explicit only the core code can include this header by defining a THERMAL_CORE_SUBSYS macro. The private header will contain a check against this macro. The Tegra SoCtherm driver needs to access thermal_core.h to have the get_thermal_instance() function definition. It is the only one remaining driver which need to access the thermal_core.h header, so the check will emit a warning at compilation time. Thierry Reding is reworking the driver to get rid of this function [1] and thus when the changes will be merged, the compilation warning will be converted to a compilation error, closing definitively the door to the drivers willing to play with the thermal zone device internals. No functional changes intended. [1] https://lore.kernel.org/all/20230414125721.1043589-1-thierry.reding@gma= il.com/ Cc: Thierry Reding Acked-by: Rafael J. Wysocki Signed-off-by: Daniel Lezcano --- drivers/thermal/gov_bang_bang.c | 1 + drivers/thermal/gov_fair_share.c | 1 + drivers/thermal/gov_power_allocator.c | 1 + drivers/thermal/gov_step_wise.c | 1 + drivers/thermal/gov_user_space.c | 1 + drivers/thermal/thermal_acpi.c | 1 + drivers/thermal/thermal_core.c | 1 + drivers/thermal/thermal_core.h | 4 ++++ drivers/thermal/thermal_helpers.c | 1 + drivers/thermal/thermal_hwmon.c | 1 + drivers/thermal/thermal_netlink.c | 1 + drivers/thermal/thermal_of.c | 1 + drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/thermal_trip.c | 1 + 14 files changed, 17 insertions(+) diff --git a/drivers/thermal/gov_bang_bang.c b/drivers/thermal/gov_bang_ban= g.c index 1b121066521f..752c627075ba 100644 --- a/drivers/thermal/gov_bang_bang.c +++ b/drivers/thermal/gov_bang_bang.c @@ -11,6 +11,7 @@ =20 #include =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 static int thermal_zone_trip_update(struct thermal_zone_device *tz, int tr= ip_id) diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_sh= are.c index 03c2daeb6ee8..108cb5074594 100644 --- a/drivers/thermal/gov_fair_share.c +++ b/drivers/thermal/gov_fair_share.c @@ -13,6 +13,7 @@ #include #include "thermal_trace.h" =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 /** diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_po= wer_allocator.c index 8642f1096b91..d1c6ad92e5b4 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -14,6 +14,7 @@ #define CREATE_TRACE_POINTS #include "thermal_trace_ipa.h" =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 #define INVALID_TRIP -1 diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wis= e.c index 1050fb4d94c2..1c844004afe5 100644 --- a/drivers/thermal/gov_step_wise.c +++ b/drivers/thermal/gov_step_wise.c @@ -14,6 +14,7 @@ #include #include "thermal_trace.h" =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 /* diff --git a/drivers/thermal/gov_user_space.c b/drivers/thermal/gov_user_sp= ace.c index 8bc1c22aaf03..8883c9ca930f 100644 --- a/drivers/thermal/gov_user_space.c +++ b/drivers/thermal/gov_user_space.c @@ -13,6 +13,7 @@ #include #include =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 static int user_space_bind(struct thermal_zone_device *tz) diff --git a/drivers/thermal/thermal_acpi.c b/drivers/thermal/thermal_acpi.c index 0e5698818f69..556c9f0cc40d 100644 --- a/drivers/thermal/thermal_acpi.c +++ b/drivers/thermal/thermal_acpi.c @@ -9,6 +9,7 @@ #include #include =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 /* diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 842f678c1c3e..6bca97e27d59 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -24,6 +24,7 @@ #define CREATE_TRACE_POINTS #include "thermal_trace.h" =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" #include "thermal_hwmon.h" =20 diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index 17c1bbed734d..2f58eb9854ff 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -14,6 +14,10 @@ =20 #include "thermal_netlink.h" =20 +#ifndef THERMAL_CORE_SUBSYS +#warning This header can only be included by the thermal core code +#endif + /* Default Thermal Governor */ #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE) #define DEFAULT_THERMAL_GOVERNOR "step_wise" diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_he= lpers.c index cfba0965a22d..164c4627949e 100644 --- a/drivers/thermal/thermal_helpers.c +++ b/drivers/thermal/thermal_helpers.c @@ -19,6 +19,7 @@ #include #include =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" #include "thermal_trace.h" =20 diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmo= n.c index c3ae44659b81..ba2ae5be0c23 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -17,6 +17,7 @@ #include =20 #include "thermal_hwmon.h" +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 /* hwmon sys I/F */ diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_ne= tlink.c index 08bc46c3ec7b..f3ac6432bf5f 100644 --- a/drivers/thermal/thermal_netlink.c +++ b/drivers/thermal/thermal_netlink.c @@ -11,6 +11,7 @@ #include #include =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 static const struct genl_multicast_group thermal_genl_mcgrps[] =3D { diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 6fb14e521197..0f2aca2d1dea 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -17,6 +17,7 @@ #include #include =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 /*** functions parsing device tree nodes ***/ diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysf= s.c index 6c20c9f90a05..ccda2579ae82 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -19,6 +19,7 @@ #include #include =20 +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 /* sys I/F for thermal zone */ diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c index 907f3a4d7bc8..61d927c35776 100644 --- a/drivers/thermal/thermal_trip.c +++ b/drivers/thermal/thermal_trip.c @@ -7,6 +7,7 @@ * * Thermal trips handling */ +#define THERMAL_CORE_SUBSYS #include "thermal_core.h" =20 int __for_each_thermal_trip(struct thermal_zone_device *tz, --=20 2.34.1