From patchwork Tue Aug 9 08:56:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 596351 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 BE798C19F2D for ; Tue, 9 Aug 2022 08:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241431AbiHII4m (ORCPT ); Tue, 9 Aug 2022 04:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241412AbiHII4h (ORCPT ); Tue, 9 Aug 2022 04:56:37 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BCF022526 for ; Tue, 9 Aug 2022 01:56:36 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 186-20020a1c02c3000000b003a34ac64bdfso6358961wmc.1 for ; Tue, 09 Aug 2022 01:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=E7W+A8RBq7Usp9JU9F1Ru53gxwOjNDrCjAkC1uG7hB8=; b=duOEo4jhZ/rVYKJMgBewxuJ1d2OjLLB769TXL72ui4HlLcAbsyltdnaPxgFHaSeQOp T/4Ixk9KUpJLPo8N3EIVlfU5+6ZM77l4+azpSuREEeHjvMFyRzSrzq/arC3dtssTMSvN 2XO1ZSI1YahN+1jmOO/89WFcXRQ0AB5rC6ce8Vqom2h9FBNQ+gAM/BIYErKSr2+MGuAC 0gKJyUQT2Vldz713bUkaGWFlzUr9z/Fgy473spa8Lr3BMnOZTXmZhPXKRTtTiybHVCx8 K6ypLaCEaHHxN+OHVvNBqmpOpSFDoOLBZEXB4Nhrv4Hb3lkCMB0cPqI57M+64vOBu4D/ arIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=E7W+A8RBq7Usp9JU9F1Ru53gxwOjNDrCjAkC1uG7hB8=; b=v1nefWXInL3T23ovZHJC7Oiv+pBjTIt/WiKsMZRlWzaVyyZoYIUT022MXvxkgNq+xj O4/SAxQxHAQ1yVaXN+NTpL/2BT5o5jwjH20TX2XsUv00S7zYc4vJxkSJnDr+fUx31koz gnqzTWuIw7GrYgXuQuSoFWYhqpmSrLQ3Y2s6Iz+Sso8jZctjVaytysB3VCxLe4/ColFX Pw9jXY2lOGrq0x4dhi3fN2Pt8FsM21zPIsJOBtjdi9/l+7LTvoqqScgUrSwuVFB/yJJ2 VMBKVgN72ufPh80mb5JetfhGhiMiCwVgwZ1WZqOj2k7GUDg52WNyT+TIrgLsC10Filxj GQTg== X-Gm-Message-State: ACgBeo3HoIj4VCbf1B5HQTStnVCNmhMwkAA+BEZYc882m7ez22JXJrXs +Uipc+0T6L5VxDClX2DQW/4qwA== X-Google-Smtp-Source: AA6agR7z1CJ1RF2MrhdQknTLEgot8gRvIjx/js8TvCI9KcAmyLht/K30vPbEOddZTV0NfOKw1c7L1Q== X-Received: by 2002:a05:600c:5021:b0:3a5:29a9:99b4 with SMTP id n33-20020a05600c502100b003a529a999b4mr9404360wmr.205.1660035394743; Tue, 09 Aug 2022 01:56:34 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id c5-20020adfe705000000b0021f1522c93bsm15746147wrm.45.2022.08.09.01.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 01:56:34 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: michael@walle.cc, dan.carpenter@oracle.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui Subject: [PATCH v2 1/4] thermal/of: Fix error code in of_thermal_zone_find() Date: Tue, 9 Aug 2022 10:56:26 +0200 Message-Id: <20220809085629.509116-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Dan Carpenter Currently, if we cannot find the correct thermal zone then this error path returns NULL and it would lead to an Oops in the caller. Return ERR_PTR(-EINVAL) instead. Fixes: 3bd52ac87347 ("thermal/of: Rework the thermal device tree initialization") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/YvDzovkMCQecPDjz@kili Signed-off-by: Daniel Lezcano Reviewed-by: Guenter Roeck --- drivers/thermal/thermal_of.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index c2bb5954b21e..368eb58e97cf 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -368,6 +368,7 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int } } } + tz = ERR_PTR(-EINVAL); out: of_node_put(np); return tz; From patchwork Tue Aug 9 08:56:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 596612 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 DA8E3C25B07 for ; Tue, 9 Aug 2022 08:56:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241416AbiHII4n (ORCPT ); Tue, 9 Aug 2022 04:56:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241422AbiHII4j (ORCPT ); Tue, 9 Aug 2022 04:56:39 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F8EC2252E for ; Tue, 9 Aug 2022 01:56:37 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v3so13632693wrp.0 for ; Tue, 09 Aug 2022 01:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Nioz9jTvIYC3MkuoeeXOKouVDzG9rikhwfoHFhwSrUc=; b=S9TVsuzhOehWyZ5xdtK2r1ilTAigVStRKNqjVuKafJ/sYabydAO5C7D0o57Cso5KsL 3i+3b2buufmLBShKTEMSN1Cd5qYkGP9uzuQnwug7XsKGW4eDgFQkcdSmalaqRSGZjzXi r3zNaFGFMCYhOVzImwGkdkhS/7xTlC979GXQzB3E+7J2lnA1YXZ3qWswlzrPoIIMxhgy 18fn4x60XS01oFeODecUSRZ84aTaf6CPbtWQ7QeGz0tS0CWoxvpN/GkbKSaL4i9SXxws ZQpM8OaU+ulM0W+EIsAg/g6nXk6Aj0GT2qPW0OXrLKs8b2jJSzhbiUkHNFLrsK2PhVsV uCHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Nioz9jTvIYC3MkuoeeXOKouVDzG9rikhwfoHFhwSrUc=; b=HrnzaX54/WZbqDDBI7REmrLhy3E1uY4tQzN9pD7UasGQ1hC1WcOrn+K3hydX5vneZl o81Z7QGsCzarqvXDngvcTBM02aiDcRexsuibgdCGsev3oFvt1Y+NOEWiypYcp67WCFu5 Gk3OaFkyn5old3e8v+9SsQcMxjxF32SPTBs5RDqGvdEUn8q20uLxjw3Mtyk8r/fc+TuL ldo6lIAjvuXUyw2m+Wypbb3RJHs5O9aLX+qQC9P1IWloesbWF4E1oo1WsTNhBdYjeu9t uV8COMXURjKSoEVyl90RSH+Ihesww8tLrLYf7FfhtLQrYCQNsDiYF5Op6C/l41u/ggt/ BJ7Q== X-Gm-Message-State: ACgBeo1eRtKGQ3ZCL0jyv8r6NisOVPA8Oyt8rVPHD2EJOOUXldXDAGsM OPcKYn4SUQzoCDpNSChAzVZQbg== X-Google-Smtp-Source: AA6agR7Eeiw5PNfZ+41IJRCAonp78CCNCVne7eY4Y5ynKDBWgjuBMuWBDLcEIrPRmi5qtdEkPldv9A== X-Received: by 2002:a5d:4945:0:b0:21e:de03:2d11 with SMTP id r5-20020a5d4945000000b0021ede032d11mr13542950wrs.308.1660035395982; Tue, 09 Aug 2022 01:56:35 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id c5-20020adfe705000000b0021f1522c93bsm15746147wrm.45.2022.08.09.01.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 01:56:35 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: michael@walle.cc, dan.carpenter@oracle.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui Subject: [PATCH v2 2/4] thermal/of: Return -ENODEV instead of -EINVAL if registration fails Date: Tue, 9 Aug 2022 10:56:27 +0200 Message-Id: <20220809085629.509116-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220809085629.509116-1-daniel.lezcano@linaro.org> References: <20220809085629.509116-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The previous version of the OF code was returning -ENODEV if no thermal zones description was found or if the lookup of the sensor in the thermal zones was not found. The backend drivers are expecting this return value as an information about skipping the sensor initialization and considered as normal. Fix the return value by replacing -EINVAL by -ENODEV and remove the error message as this missing is not considered as an error. Signed-off-by: Daniel Lezcano Tested-by: Michael Walle --- v2: - Change the error message to a debug message - Only show an error if the error is not -ENODEV --- drivers/thermal/thermal_of.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 368eb58e97cf..3effc729be4b 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -328,8 +328,8 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int np = of_find_node_by_name(NULL, "thermal-zones"); if (!np) { - pr_err("Unable to find thermal zones description\n"); - return ERR_PTR(-EINVAL); + pr_debug("No thermal zones description\n"); + return ERR_PTR(-ENODEV); } /* @@ -368,7 +368,7 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int } } } - tz = ERR_PTR(-EINVAL); + tz = ERR_PTR(-ENODEV); out: of_node_put(np); return tz; @@ -642,7 +642,8 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, np = of_thermal_zone_find(sensor, id); if (IS_ERR(np)) { - pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id); + if (PTR_ERR(np) != -ENODEV) + pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id); return ERR_CAST(np); } From patchwork Tue Aug 9 08:56:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 596350 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 B43AEC19F2D for ; Tue, 9 Aug 2022 08:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241390AbiHII4q (ORCPT ); Tue, 9 Aug 2022 04:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241363AbiHII4l (ORCPT ); Tue, 9 Aug 2022 04:56:41 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E1FC22523 for ; Tue, 9 Aug 2022 01:56:39 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id j1so13590576wrw.1 for ; Tue, 09 Aug 2022 01:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=bXLpXmWL+T2aMJD2mxacKkNa6+tQMtWwj5lWrNrsUB4=; b=DnIqRWDo09RJul5vv+F5yTbZTopzEj3jbl38jNbPUKWwObnJ5P4dZfKlxyXkFB2VJg veF3hn4jAAcE1lSxatgP7Ry6C+N/BauvxaDw9NLeP2Tr+BMEVkFi0r6Xqn8gjFJJnzdk HF2IUKVgo+qzeMV9LFFvcakMb7a2h1orRYKZKQyR654M+M4+RLeQuHGja57/xEKWx0s8 Lywbb0ZdnbGTMhPO7sn8k+p0Y3IobsUlz7RRaTy20cXevux0fIoz+OqTWycPVMmzox3k qSoHvxWKYqQ+pzd3QciVR/KzCAydWgG/XcSJItFvHMG6SWdAKYkGo0Snh+FC8pU72kYh hDSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=bXLpXmWL+T2aMJD2mxacKkNa6+tQMtWwj5lWrNrsUB4=; b=Z2zCiybBMiUtcC0bpOgtmQDKbBlFXhSI+N18jqYtsPr/Hj4HveLxweM6GzL24c2qAJ 9gKD9yKzbnEwsXUjI+aCGmKxdH8onnobbIj6Z0DfH8KX9R7YDzD+T1dZsVDVDsy1uux5 6k22ifPIs/rd6irjRErq4QoTYY9baR2HLdQkgU/MpRA7Ow5Rph1hOGWy6/Y+hg3khfRl 0WX2LzaXVp9dmut6ja/3IMn+AKnq0Nnpk0HBw2LnwBewDqx2Ak8/wuT66QaZAp1R+aQo D65Bi4rG++u7ul6Ck5oEn/5n0UxjbLoJgT8WNNgFiY/1Cuis3dQItuxrb/St/cYt8Nz7 HW8w== X-Gm-Message-State: ACgBeo1bpEJRsr8LxKKtsbjQBdKTImR6dKCniKaunNvx4KvUzFLG9/30 6aDJneBezD1hZAzV69Mnpxg4dg== X-Google-Smtp-Source: AA6agR4yrlmW3A2BU6dz6lzflbszCSmZXiu9M69XebLiEQKaMKzbnJhCPb5iMGPYgITbRuulDIDLRg== X-Received: by 2002:a05:6000:178c:b0:223:141:8a14 with SMTP id e12-20020a056000178c00b0022301418a14mr4040423wrg.629.1660035397455; Tue, 09 Aug 2022 01:56:37 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id c5-20020adfe705000000b0021f1522c93bsm15746147wrm.45.2022.08.09.01.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 01:56:36 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: michael@walle.cc, dan.carpenter@oracle.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS) Subject: [PATCH v2 3/4] dt-bindings: thermal: Fix missing required property Date: Tue, 9 Aug 2022 10:56:28 +0200 Message-Id: <20220809085629.509116-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220809085629.509116-1-daniel.lezcano@linaro.org> References: <20220809085629.509116-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When the thermal zone description was converted to yaml schema, the required 'trips' property was forgotten. The initial text bindings was describing: " [ ... ] * Thermal zone nodes The thermal zone node is the node containing all the required info for describing a thermal zone, including its cooling device bindings. The thermal zone node must contain, apart from its own properties, one sub-node containing trip nodes and one sub-node containing all the zone cooling maps. Required properties: - polling-delay: The maximum number of milliseconds to wait between polls Type: unsigned when checking this thermal zone. Size: one cell - polling-delay-passive: The maximum number of milliseconds to wait Type: unsigned between polls when performing passive cooling. Size: one cell - thermal-sensors: A list of thermal sensor phandles and sensor specifier Type: list of used while monitoring the thermal zone. phandles + sensor specifier - trips: A sub-node which is a container of only trip point nodes Type: sub-node required to describe the thermal zone. Optional property: - cooling-maps: A sub-node which is a container of only cooling device Type: sub-node map nodes, used to describe the relation between trips and cooling devices. [ ... ] " Now the schema describes: " [ ... ] required: - polling-delay - polling-delay-passive - thermal-sensors [ ... ] " Add the missing 'trips' property in the required properties. Fixed: 1202a442a31fd ("dt-bindings: thermal: Add yaml bindings for thermal zones") Signed-off-by: Daniel Lezcano Acked-by: Rob Herring --- Documentation/devicetree/bindings/thermal/thermal-zones.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml b/Documentation/devicetree/bindings/thermal/thermal-zones.yaml index 2d34f3ccb257..8d2c6d74b605 100644 --- a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml +++ b/Documentation/devicetree/bindings/thermal/thermal-zones.yaml @@ -214,6 +214,7 @@ patternProperties: - polling-delay - polling-delay-passive - thermal-sensors + - trips additionalProperties: false From patchwork Tue Aug 9 08:56:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 596611 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 AB026C25B06 for ; Tue, 9 Aug 2022 08:56:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241432AbiHII4r (ORCPT ); Tue, 9 Aug 2022 04:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241406AbiHII4l (ORCPT ); Tue, 9 Aug 2022 04:56:41 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD49E2250D for ; Tue, 9 Aug 2022 01:56:40 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id l4so13517374wrm.13 for ; Tue, 09 Aug 2022 01:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=x3LAwxQixbirt9XaznuF2BMc0lzOuvCPnP/nz7piIPA=; b=y1UiaG7mgsxxxkHnliUc3V8iryz12DjSbv11GtTXD23OEibQT/XAqSoQKUw1FwtP0a 4PB6f8dcAvqUXBldjTJ/HOZlpXYjgwkFgPqZyA6xgbqqtw3MuMTxIoxBy11TW+tezsMW 2K+EroHeyLUojbWRl4p6oJdLzXQM24WSHMYmp2ieA58bdAssSyQ9jaMO8FckuonPcoS5 8o5jCUwCZY4ghfg1159eLT3VYm9sLSpjvDYCMFkE21Hq+LCtQjG1mwmbN+bcpCR8b+YH Q4ioh3CAQqruy2aXfBXa+KFs4DdUs73sq2XWs8V2CjPQx58tgMpu5OC393sK9GFVAT0p j+Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=x3LAwxQixbirt9XaznuF2BMc0lzOuvCPnP/nz7piIPA=; b=yZrx7w3wTXpbuqwuMNQopWSWHz4zKoMXmGe6l9VPg7H0u07DOXWOPjzvZrkHIQgxs4 zTRaFntW6oJCgBsWtY6aZtHScSgXHRDTQB1T7uwZHV4NT7GqAYFiE6YOg79AQteSscVY u/XaFhGn5uEcTJQC3wuInRgfZtI2Bbat3MW6jpufs+a/+oFuqm5KPNWi8XPv1oB8SumB DaEsI0mmJAm5wXahdUW2e7smbqur88+g5rnHvst1G1FTA3VHG+mfVj9z1z6RMG7aNRyM 49QHKzN85mskGUwQAbh51+rMpK6Z3VEGPhNKj7dJsM9VXn11GEgBq90QVJeHf2a4iOus fP1Q== X-Gm-Message-State: ACgBeo1LeZk8UwXwrs9Lhqbw/tgDAivdJzuRHnGjCgyqxVC0XH9zo5cE BbMJuTiPVM3i3D9dXBO4rjL57A== X-Google-Smtp-Source: AA6agR4QnB1mLDfIpQIOqHx/tKNQwqELMOrfwW0X/9YINERn8kfF19WXMyx+PJyM+67u+QoAeBdf9Q== X-Received: by 2002:a5d:5483:0:b0:220:6b87:8f79 with SMTP id h3-20020a5d5483000000b002206b878f79mr13962163wrv.17.1660035398746; Tue, 09 Aug 2022 01:56:38 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id c5-20020adfe705000000b0021f1522c93bsm15746147wrm.45.2022.08.09.01.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 01:56:38 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: michael@walle.cc, dan.carpenter@oracle.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui Subject: [PATCH v2 4/4] thermal/of: Fix free after use in thermal_of_unregister() Date: Tue, 9 Aug 2022 10:56:29 +0200 Message-Id: <20220809085629.509116-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220809085629.509116-1-daniel.lezcano@linaro.org> References: <20220809085629.509116-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The thermal zone is freed after being unregistered. The release method devm_thermal_zone_device_register() calls -> thermal_of_zone_device_unregister() This one calls thermal_zone_device_unregister() which frees the thermal zone. However, thermal_of_zone_device_unregister() does access this freed pointer to free different resources allocated by the thermal_of framework which is invalid. It results in a kernel panic: [ 1.915140] thermal_sys: Failed to find thermal zone for tmu id=2 [ 1.921279] qoriq_thermal 1f80000.tmu: Failed to register sensors [ 1.927395] qoriq_thermal: probe of 1f80000.tmu failed with error -22 [ 1.934189] Unable to handle kernel paging request at virtual address 01adadadadadad88 [ 1.942146] Mem abort info: [ 1.944948] ESR = 0x0000000096000004 [ 1.948708] EC = 0x25: DABT (current EL), IL = 32 bits [ 1.954042] SET = 0, FnV = 0 [ 1.957107] EA = 0, S1PTW = 0 [ 1.960253] FSC = 0x04: level 0 translation fault [ 1.965147] Data abort info: [ 1.968030] ISV = 0, ISS = 0x00000004 [ 1.971878] CM = 0, WnR = 0 [ 1.974852] [01adadadadadad88] address between user and kernel address ranges [ 1.982016] Internal error: Oops: 96000004 [#1] SMP [ 1.986907] Modules linked in: [ 1.989969] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.19.0-next-20220808-00080-g1c46f44502e0 #1697 [ 1.999135] Hardware name: Kontron KBox A-230-LS (DT) [ 2.004199] pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 2.011185] pc : kfree+0x5c/0x3c0 [ 2.014516] lr : devm_thermal_of_zone_release+0x38/0x60 [ 2.019761] sp : ffff80000a22bad0 [ 2.023081] x29: ffff80000a22bad0 x28: 0000000000000000 x27: ffff800009960464 [ 2.030245] x26: ffff800009a16960 x25: 0000000000000006 x24: ffff800009f09a40 [ 2.037407] x23: ffff800009ab9008 x22: ffff800008d0eea8 x21: 01adadadadadad80 [ 2.044569] x20: 6b6b6b6b6b6b6b6b x19: ffff00200232b800 x18: 00000000fffffffb [ 2.051731] x17: ffff800008d0eea0 x16: ffff800008d07d44 x15: ffff800008d0d154 [ 2.056647] usb 1-1: new high-speed USB device number 2 using xhci-hcd [ 2.058893] x14: ffff800008d0cddc x13: ffff8000088d1c2c x12: ffff8000088d5034 [ 2.072597] x11: ffff8000088d46d4 x10: 0000000000000000 x9 : ffff800008d0eea8 [ 2.079759] x8 : ffff002000b1a158 x7 : bbbbbbbbbbbbbbbb x6 : ffff80000a0f53b8 [ 2.086921] x5 : ffff80000a22b960 x4 : 0000000000000000 x3 : 0000000000000000 [ 2.094082] x2 : fffffc0000000000 x1 : ffff002000838040 x0 : 01adb1adadadad80 [ 2.101244] Call trace: [ 2.103692] kfree+0x5c/0x3c0 [ 2.106666] devm_thermal_of_zone_release+0x38/0x60 [ 2.111561] release_nodes+0x64/0xd0 [ 2.115146] devres_release_all+0xbc/0x350 [ 2.119253] device_unbind_cleanup+0x20/0x70 [ 2.123536] really_probe+0x1a0/0x2e4 [ 2.127208] __driver_probe_device+0x80/0xec [ 2.131490] driver_probe_device+0x44/0x130 [ 2.135685] __driver_attach+0x104/0x1b4 [ 2.139619] bus_for_each_dev+0x7c/0xe0 [ 2.143465] driver_attach+0x30/0x40 [ 2.147048] bus_add_driver+0x160/0x210 [ 2.150894] driver_register+0x84/0x140 [ 2.154741] __platform_driver_register+0x34/0x40 [ 2.159461] qoriq_tmu_init+0x28/0x34 [ 2.163133] do_one_initcall+0x50/0x250 [ 2.166979] kernel_init_freeable+0x278/0x31c [ 2.171349] kernel_init+0x30/0x140 [ 2.174847] ret_from_fork+0x10/0x20 [ 2.178433] Code: b25657e2 d34cfc00 d37ae400 8b020015 (f94006a1) [ 2.184546] ---[ end trace 0000000000000000 ]--- Store the allocated resource pointers before the thermal zone is free and use them to release the resource after unregistering the thermal zone. Reported-by: Michael Walle Signed-off-by: Daniel Lezcano Tested-by: Michael Walle --- drivers/thermal/thermal_of.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 3effc729be4b..fd2fb84bf246 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -596,11 +596,15 @@ static int thermal_of_unbind(struct thermal_zone_device *tz, */ void thermal_of_zone_unregister(struct thermal_zone_device *tz) { + struct thermal_trip *trips = tz->trips; + struct thermal_zone_params *tzp = tz->tzp; + struct thermal_zone_device_ops *ops = tz->ops; + thermal_zone_device_disable(tz); thermal_zone_device_unregister(tz); - kfree(tz->trips); - kfree(tz->tzp); - kfree(tz->ops); + kfree(trips); + kfree(tzp); + kfree(ops); } EXPORT_SYMBOL_GPL(thermal_of_zone_unregister);