From patchwork Fri Aug 16 07:40:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13765633 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 9E5BFC3DA4A for ; Fri, 16 Aug 2024 07:44:52 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1uGkngSoQ6xXDida4nnB27AlMz6Imue7QU/aLBQagO8=; b=oocz3E4ZcHKvwzl8vpqYIRHKWg 5+neoIK8RF+HZF2Om+TaLe99JOKv/eYT7xK/OWXZrRfElb+o137sz0TYFj0W1RiZmHJ8UFXxqUoA3 DhSPQKBWKD5ywEx66Gp06MHSlVhDnZ0l20nP/ahg1BRqDAt/OQ/JX+Bu27AiaUwu2iNxrDR9YCtLa KqpbHZP2yhKLXSsLFH/8qqkE9RS3LnRt7OYoQ+NzhyKdwe7yqdoslas8rSB1pCKoPy8TuWdGHGq+8 WS39PSam5/50GYM8+OCCHCQ7f/D8zwp5Mkt32KBr5eHfjtStxD6aHf8T0Dc1InSE+KwC6C3vT11LD CZ1nYrkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1serdU-0000000C91g-1WNG; Fri, 16 Aug 2024 07:44:36 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1serZo-0000000C7zE-2fQL for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 07:40:50 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-530e2287825so1710351e87.1 for ; Fri, 16 Aug 2024 00:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723794046; x=1724398846; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1uGkngSoQ6xXDida4nnB27AlMz6Imue7QU/aLBQagO8=; b=HoaPYJGdpcaDrO8c8rd5UzRI2w4RLufqOTA0rPdv5dgakxO4pJQcN4dJ/7H5+HylbQ T1Kbf3gHwTE9iL1+9/LSDLAB6cY05dK+4ZLCzaouypvoIb40zowOCi40D3blYvlt4lBY RCHVxDcyU21G3s6Hr0cq0NI2Gc42jldlxYX1seK3znASIlzJ2OF4gO7h92svE2DH5NpT Kcu8KlfRWhodIacgCgs+j0cjlgqCJ7dF84MMTU16phiHOgdNpwxuDmXdQNT+1fw/CC4A jKSWdc6hERI6x3sDjZ07oQdVx0TgYbqmvoNMlcadd3KvtQu55o8c129fb3+GfzQTw5Sj scGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723794046; x=1724398846; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1uGkngSoQ6xXDida4nnB27AlMz6Imue7QU/aLBQagO8=; b=r/n/4Ha/dvQJzJnw/TVTrRVrw4tW/J2kC3N/C+zd3yAoVV6nidXCO4gWoHD1xu40pG 3+xeC9QzM5QZBKKkdriMszsWqehRaqZlXl83G8gFmcAx1Kr2DbXU3epMvKSF0cENSEI2 2eHcRgNLPAweZwJGc+oXhWWVIhQGz/h4rall0Tw+xusmpFA84tB0CuphbPnhSz35X1kY uFOE9iMd/rD+vQi72jz0Q+p++7rZK5cZybOT7c4gp/1lj6Zr93AqKVUbTa4TKAye2xrY s6sKEvAd4d1IvYhAcgp67b/jclDBjBhKWB4KLRKg1BZDOF3iKvEyrUoh5r4nrDuK232l H3OA== X-Forwarded-Encrypted: i=1; AJvYcCV9aEDwN0o7dzNJIddI3hEzwfef7fbty/IXxJJqUNc0F9jIAGNHouxO25yuDY/4si7nvGr/4N0OWBuqodI++/YJ/mAWarTpIua+eTEiN85rwvuBg2E= X-Gm-Message-State: AOJu0Ywtz7fp1Abx5EoG+owHwAxeN5A1AHZyvu3e0Wc3byGQHL9kMAVH o2YkjrT+I7GUhZS6db5VAbrrZTSu8WRgfhTfFe/YmBtyWuwTh0c8AHrTWntJrFU= X-Google-Smtp-Source: AGHT+IHVpxmEDbWkRu0WtK0xFv4zm5wdQAu15HLyFiw3HU25oGcA8Yg4aEM9aSa1ga5Xo/0m7M9nHg== X-Received: by 2002:a05:6512:10c1:b0:533:6f3:9857 with SMTP id 2adb3069b0e04-5331c6904c5mr1276139e87.5.1723794046302; Fri, 16 Aug 2024 00:40:46 -0700 (PDT) Received: from [127.0.1.1] ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded3596esm68549625e9.22.2024.08.16.00.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 00:40:45 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 16 Aug 2024 09:40:31 +0200 Subject: [PATCH v2 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() MIME-Version: 1.0 Message-Id: <20240816-b4-cleanup-h-of-node-put-thermal-v2-1-cee9fc490478@linaro.org> References: <20240816-b4-cleanup-h-of-node-put-thermal-v2-0-cee9fc490478@linaro.org> In-Reply-To: <20240816-b4-cleanup-h-of-node-put-thermal-v2-0-cee9fc490478@linaro.org> To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Amit Kucheria , Thara Gopinath , Thierry Reding , Jonathan Hunter , Vasily Khoruzhick , Yangtao Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Chen-Yu Tsai , Krzysztof Kozlowski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1658; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=PGsw5QEex7CpuDWx1RGJUm5OKheN4rGmrB1iCwFW2V4=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmvwJ0a2oOLNxyHQgqOvUweDO+R4Igmr3Jpxu3e NoVVWn7VOaJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZr8CdAAKCRDBN2bmhouD 1x/KD/4vzaf8o3Cs0YXq3URfWkk0gwTnAVURfyW6uwwZpyfLnu/c3oMd7TTIoOy4TNwSwBSvZjc W1rBbtDFaOvz/BBNm219y03iR1zBBaOpeShkSB0pRHJDwWgHDJpXMX1rau2AlDrA+f4lwJjPILf VXDQDyQFtUhwZ9ANVb7UDabNpbh1ImBgtqpCVwkdG+D9Oo40/5W6IaiLPj/BywB05eaoKvlyQ8v sOBetRdJQ8g/TYq4YQLEWL9Ze8hkP/+60KpyrwR5Dq8aldz2hbKQHN0XyILqw6jq2/Ra1J600BI PjyOV7YkvKAqF4BWp6IX6+rn21G5Alc9RO6A3p+S2++7HhBwdR7qU6kWgg60hXYtQJFphCOq+a5 7Is+mjf50wlyoW/3KMKA8wfZKBaTD3i4fbMEdOd31RnBImAduYDdeYmTJtCso7+w9hPPPU6g7GX MyXe7aPL/JaXdn4pU0rPJ5GSCArix+Tg8WlCpLgIisjgtPoVULa3cSCOedhgTN7A+wYpiNMPDhx x+XBdvyGoCoX3au0cqqSH1wJIeUez1zzUyoN+MVfxo7rv2qrpcJm+mzOMSjhBlBFpyJ5Vd7eT5O WY1I3zLiEZZj+Gb9Zk4IpHXFreff/DOnjmmqZrSL/1B5/F5MQCkf9vIflh6tMbvHzx2aE6K3BfV +2Qf1zWMPdhl/Vw== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_004048_938572_4A4A195C X-CRM114-Status: GOOD ( 14.96 ) 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 Obtain the device node reference with scoped/cleanup.h and use scoped for_each_child_of_node_scoped() to reduce error handling in of_find_trip_id() and make the code a bit simpler. Reviewed-by: Chen-Yu Tsai Signed-off-by: Krzysztof Kozlowski --- drivers/thermal/thermal_of.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 1f252692815a..a2278d4ad886 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -22,11 +23,9 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip) { - struct device_node *trips; - struct device_node *t; int i = 0; - trips = of_get_child_by_name(np, "trips"); + 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 -EINVAL; @@ -35,20 +34,13 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip) /* * Find the trip id point associated with the cooling device map */ - for_each_child_of_node(trips, t) { - - if (t == trip) { - of_node_put(t); - goto out; - } + for_each_child_of_node_scoped(trips, t) { + if (t == trip) + return i; i++; } - i = -ENXIO; -out: - of_node_put(trips); - - return i; + return -ENXIO; } /*