From patchwork Thu Oct 17 09:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13839645 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 677E4D21261 for ; Thu, 17 Oct 2024 09:07:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=eq4DcLX81xhHJQxcCvF71zsYnZphDuzGs7+nmZig8nY=; b=SPZxzGeYipR0Fi2NRxFnIK9/Vy U8OWW8kWuE/R5UFYEp95FFV9tBdoEY/T1MQ8yMvbYqPi/GtmxWsmTIiiVJbgsEmoVmrayKSARjoXm JEUq9FuqB/+kIV9mVaWKVBH3FNjMAk7x9MuDDAJBTQcpC4rk2q4w71sjLqPAajj75UpqzbQxn/q82 2EjbyvXghvMNxh/HyNXAe7HoPXUrrgTYeedxRe2pSMCbOWjLEQN38Zy8mZMhlfkdNe6RCMuAmnYa0 fx3vJyKzRc277A+jDvKi4Wq9/bf/Zkm2Tu6crxaUVSzN5WRItkOMvT+emAtDwvv5ER+OXS5Hi+uZO M83+6Y6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1MT8-0000000EHAY-2zRT; Thu, 17 Oct 2024 09:06:54 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1MRd-0000000EH1X-30VB for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 09:05:25 +0000 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-7e6ed072cdaso452639a12.0 for ; Thu, 17 Oct 2024 02:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729155920; x=1729760720; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eq4DcLX81xhHJQxcCvF71zsYnZphDuzGs7+nmZig8nY=; b=av+YH6ujsgmAiTscY5JwQlD5dOvVrVA80dltlFYUn36ms5RhIGvqFsRWt5EENtNPFU jmCEMO6boxfjqeWX8ksThqifeo2xvwYWTIsHXODo1MXzcs8z+HuZQ6AXALGToND8WLLm fIexTxai9Mm3y6QC0raiSQ97c3ybmPs4NvRyc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729155920; x=1729760720; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eq4DcLX81xhHJQxcCvF71zsYnZphDuzGs7+nmZig8nY=; b=VJodx3DBbby/eoD3gyaBbdIZKKZ2peBqLwhtkF6LSX2XBWPb3rSuye4mYL7LnH9RlF Y7rXzLDWEyNpFRTvSW3jD6qwaucEc1N1hjsF8D8VLXtAfEdkhpQQt1pfmNpAI35cdWyt ITVTI4T6oZdug++neinzqXBfei32BLYv5yNbBROVg39isaUsrSzwjIP25onZQORmpQz8 LbkBsaDeW+5AHRXPv/hoFt4OFni1DzWcWM5TlGjcbsIZc8lDGR7gHaVgDDC+R4qf9vy3 oD/WTWXR0Y/gCAIhF1yLzJvcdMyU0MDLSHWB9gFYSuMTVN9rctyMtSYbkGAk1NzxBXTK NvmA== X-Forwarded-Encrypted: i=1; AJvYcCUs3sQKa+rAafL7iH7+xXg5RCqlOaeG3Hm/0Lc+E4VadT/gW9wIpwflZMP3ao/hHG7qV0eRWHSYM+O0gBr8b5SV@lists.infradead.org X-Gm-Message-State: AOJu0YzE7OPmXlq3Jxb2EJBplUKA6M45bf5C+GDZiPBQiRqwVDu8eHeM F/tKrufhA3Brb7iSnxi3PbXUOs81XyyD0PkUC0wbnW0pZj9ks+xey7BU3Mu0oAKNY/9CwJYORyM = X-Google-Smtp-Source: AGHT+IE8sc7gGXO+epscpZQ4+3ix7OqJhkRjhM95PD83qJR77jaGJm3mMk8J1ijNb16KGYomMx1MwA== X-Received: by 2002:a17:90a:fe18:b0:2e2:af52:a7b7 with SMTP id 98e67ed59e1d1-2e31536e834mr19968279a91.34.1729155920193; Thu, 17 Oct 2024 02:05:20 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:fabb:a7ab:3d7:9aaa]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e3e08c0405sm1344305a91.14.2024.10.17.02.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:05:19 -0700 (PDT) From: Chen-Yu Tsai To: Daniel Lezcano , Amit Kucheria , Zhang Rui Cc: Icenowy Zheng , Mark Brown , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , AngeloGioacchino Del Regno , Matthias Brugger , linux-mediatek@lists.infradead.org, Hsin-Te Yuan , Chen-Yu Tsai Subject: [PATCH v3] thermal/of: support thermal zones w/o trips subnode Date: Thu, 17 Oct 2024 17:05:02 +0800 Message-ID: <20241017090503.1006068-1-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241017_020521_921426_887EE773 X-CRM114-Status: GOOD ( 16.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Icenowy Zheng Although the current device tree binding of thermal zones require the trips subnode, the binding in kernel v5.15 does not require it, and many device trees shipped with the kernel, for example, allwinner/sun50i-a64.dtsi and mediatek/mt8183-kukui.dtsi in ARM64, still comply to the old binding and contain no trips subnode. Allow the code to successfully register thermal zones w/o trips subnode for DT binding compatibility now. Furtherly, the inconsistency between DTs and bindings should be resolved by either adding empty trips subnode or dropping the trips subnode requirement. Fixes: d0c75fa2c17f ("thermal/of: Initialize trip points separately") Signed-off-by: Icenowy Zheng Reviewed-by: Mark Brown Signed-off-by: Chen-Yu Tsai --- Changes since v2: - Stacked on top of Krzysztof's cleanup patches - thermal: of: Use scoped memory and OF handling to simplify thermal_of_trips_init() [1] - Adjusted to account for eliminated error path [1] https://lore.kernel.org/all/20241010-b4-cleanup-h-of-node-put-thermal-v4-2-bfbe29ad81f4@linaro.org/ Changes since v1: - set *ntrips at beginning of thermal_of_trips_init() - Keep goto out_of_node_put in of_get_child_count(trips) == 0 branch - Check return value of thermal_of_trips_init(), if it is -ENXIO, print warning and clear |trips| pointer - Drop |mask| change, as the variable was removed I kept Mark's reviewed-by since the changes are more stylish than functional. --- drivers/thermal/thermal_of.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 93f7c6f8d06d..be1fa6478c21 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -99,14 +99,14 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips"); if (!trips) { - pr_err("Failed to find 'trips' node\n"); - return ERR_PTR(-EINVAL); + pr_debug("Failed to find 'trips' node\n"); + return ERR_PTR(-ENXIO); } count = of_get_child_count(trips); if (!count) { - pr_err("No trip point defined\n"); - return ERR_PTR(-EINVAL); + pr_debug("No trip point defined\n"); + return ERR_PTR(-ENXIO); } struct thermal_trip *tt __free(kfree) = kzalloc(sizeof(*tt) * count, GFP_KERNEL); @@ -386,9 +386,15 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * trips = thermal_of_trips_init(np, &ntrips); if (IS_ERR(trips)) { - pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); - ret = PTR_ERR(trips); - goto out_of_node_put; + if (PTR_ERR(trips) != -ENXIO) { + pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); + ret = PTR_ERR(trips); + goto out_of_node_put; + } + + pr_warn("Failed to find trip points for %pOFn id=%d\n", sensor, id); + trips = NULL; + ntrips = 0; } ret = thermal_of_monitor_init(np, &delay, &pdelay);