From patchwork Tue Aug 20 09:40:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13769785 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 7CE73C3DA4A for ; Tue, 20 Aug 2024 09:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=tc1WNoWmGA0bJNVZj+Ge6NR0EiCq5nPfYTxO6W4wsRQ=; b=CZQ1wJGTCS4LJ1 QY8zEKw82BnY90rCLjkAvle18VSIeRHl5q2Boqy4n6cL4TBOMH/66AoY6X17M71YbjnnjPZhycENb MNEBYaGOey+MkAJJXtXPcgcwfuRtNahwl+vGFaT78S2Z+qErQCbu0Nq75pS0+E3mJYfHpTqOvzQdK fYUOvCuYqPgP5xGSw0kJf+96O3yvgpHebnsl3zJLUwYn/qhgaXYEFnCG9g4fqL4Qb5rhdQhFOWbKM VRr7jd0wBiYXwfYMZCgfT22ta59NnDQ2CTjH2yEmjCERnqEl44xfp/11P19yhM/pF61zTMS6ZZSdU ud/ctqTmYCN4ZjnEFScA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgLPd-00000004dpy-0urN; Tue, 20 Aug 2024 09:44:25 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgLLp-00000004cbt-017i for linux-riscv@lists.infradead.org; Tue, 20 Aug 2024 09:40:30 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a8647056026so77638766b.0 for ; Tue, 20 Aug 2024 02:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724146827; x=1724751627; 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=ml5kmP2AZ4rRTo1ml+BArOzT8EmV3i5O4Bq4nH6wu1k=; b=h3mEfBAWBxrzC4jmr5tNibLB9yLYVFllUrHov923tCiAzb9nUc/XR4yf/vbzP8HIQo ql1v1rdNWkXeGOt80Y9xlkUhPMCue/ClN2WRv7yZAnZpNnsoPo6xu3J2jPyV8gT6pfJ0 sQD7FZNkOPiVOaywavosT//As4im0/i+IbLwFNJXaMzhM79yiaw7X9XF9rD+ncv1UDvU XyiSJs3WG7I2SF7tGU7mMsjb8Da/ZzzsA866JyE03izlv07WTmlcs7EK0qzgk4SHlMla c/poRfK7jwmY21KCK4Pj1yMFGSem1ntXiRZUG8Qqi84+VFOW56MiZsaA7pnqNPUicdUz Av9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724146827; x=1724751627; 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=ml5kmP2AZ4rRTo1ml+BArOzT8EmV3i5O4Bq4nH6wu1k=; b=p5IyseWqZqxOf3DGwehsP4iGOHU1l3jTRk86QB50XaiWtMJZTthocrtHZZ1N2v3IeE JCth6tZMtqmgxFHqNaCogIcsy3mwSDjSBmqDX2KsoWMnWXZOq+bkReo3lbzS6vXt0Pkk OtVj5HF/3oUqkiH9raKmkwrCU/lQjSqjjc+z2e1wIj4Zs6/GCOIhU0DXWe7lKa8pbP32 2iZW9Bn+pS75KBEcd9RrCcMM87NfmZRFXk6bwmbbOOgxShzRy5YHps26YT7nctZ35PJn uLbltI5sb0fdZGK2SQDk6jn2UFaBWNb8RF1ipBKkQKpCAzAnWwRUEaCigtanKonUNaq8 OeBA== X-Forwarded-Encrypted: i=1; AJvYcCXzzy4OJX0FVJJmarTy/fXRlAO4z640yzGikyecjip95uRNVYNYJ3F50YZzzL6CzYdGDLG7Q+zXnfHgDfVrTpxkDdE3mwnXPNjyuT2xev9C X-Gm-Message-State: AOJu0YymhkBWVDo5xvyaMpaBGtpllVPuPdsNGeZLU1tktSByHQ0ttRKR i7PJnGWrYx7xTqCTbmyYHLGZG2Nt82refcibQ89wuk7TgR+wiQd3kv8rap62BidMnIkX4y33Eh8 Y X-Google-Smtp-Source: AGHT+IFWIcPWJD7AezJob3CaaT6BEKEOeCZ2xK2iLUqEJ3Fjit54kT8/4nWS9N5eeGL5wXOTPMbcfw== X-Received: by 2002:a17:907:e207:b0:a7a:bad3:e5b9 with SMTP id a640c23a62f3a-a83928a9ea4mr984286166b.11.1724146827093; Tue, 20 Aug 2024 02:40:27 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a83838d023dsm733613366b.64.2024.08.20.02.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 02:40:26 -0700 (PDT) From: Krzysztof Kozlowski To: Anup Patel , "Rafael J. Wysocki" , Daniel Lezcano , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v2 1/2] cpuidle: riscv-sbi: Use scoped device node handling to fix missing of_node_put Date: Tue, 20 Aug 2024 11:40:22 +0200 Message-ID: <20240820094023.61155-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240820_024029_090570_A9F2AB85 X-CRM114-Status: GOOD ( 14.06 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Two return statements in sbi_cpuidle_dt_init_states() did not drop the OF node reference count. Solve the issue and simplify entire error handling with scoped/cleanup.h. Fixes: 6abf32f1d9c5 ("cpuidle: Add RISC-V SBI CPU idle driver") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Anup Patel --- Changes in v2: 1. Re-write commit msg, because this is actually a fix. --- drivers/cpuidle/cpuidle-riscv-sbi.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c index a6e123dfe394..5bb3401220d2 100644 --- a/drivers/cpuidle/cpuidle-riscv-sbi.c +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt +#include #include #include #include @@ -236,19 +237,16 @@ static int sbi_cpuidle_dt_init_states(struct device *dev, { struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu); struct device_node *state_node; - struct device_node *cpu_node; u32 *states; int i, ret; - cpu_node = of_cpu_device_node_get(cpu); + struct device_node *cpu_node __free(device_node) = of_cpu_device_node_get(cpu); if (!cpu_node) return -ENODEV; states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL); - if (!states) { - ret = -ENOMEM; - goto fail; - } + if (!states) + return -ENOMEM; /* Parse SBI specific details from state DT nodes */ for (i = 1; i < state_count; i++) { @@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev, pr_debug("sbi-state %#x index %d\n", states[i], i); } - if (i != state_count) { - ret = -ENODEV; - goto fail; - } + if (i != state_count) + return -ENODEV; /* Initialize optional data, used for the hierarchical topology. */ ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu); @@ -277,10 +273,7 @@ static int sbi_cpuidle_dt_init_states(struct device *dev, /* Store states in the per-cpu struct. */ data->states = states; -fail: - of_node_put(cpu_node); - - return ret; + return 0; } static void sbi_cpuidle_deinit_cpu(int cpu) From patchwork Tue Aug 20 09:40:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13769786 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 21EB9C5320E for ; Tue, 20 Aug 2024 09:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HOr+RpwnLMqvvUhpxE5Kj/bdLWhWjnRFqnMTDQdy1k0=; b=IaTVlPoWoryDL7 A9BJXmlTpe2HHwR2tU+nbpK7e5P1UsTopSexp/14U7mYrv5oFOW71JzKVhvczITXz0rqdt6rM8+Vj 7LtGxsv71+v09v/6OfCGnqgDmZzdcIS4r/sh1DkrE5MYxQ/QND8Y8J1bGPvMZbgb/XeRrpcUdXVg5 K9yGxO1CVDrB5oWuT4QiWSMhm7Io0qP/3DUWqRp+JnZencJneeXBrbe1YmbGIYU4ero4oXuq7O4Ze 3R6ZCAdiwrPhh9y34UXNYTRpFtfyNtQ0yRtd6eXGl4nU85RvJOoBaDZ+1HoA1jqWL8EpbcIT6P6rP tx85O5TfMNpnwtJKGr5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgLPe-00000004dq9-06QH; Tue, 20 Aug 2024 09:44:26 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgLLv-00000004cf7-2xc9 for linux-riscv@bombadil.infradead.org; Tue, 20 Aug 2024 09:40:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ZY/iGek7oJwLxPJ1JKwoSRK1o1gPKN3vGl9eBXs8wms=; b=pLoBlWRRlcQt9wm5n+dQNZtbTb 1WUJhIIZgCN4HUSk940NEdrcIh9mfPLpfHPe6DxIUtJdtkwwr9K/CQRYENHQb16zCPxCDU/2I8z6p vbbYrMUAPhM/YRMrP3AruLuVDSIpTpuzDE7jS6BK3kOj7RCm0Ajr6sReAOpvTTjj7XaAPdPTBxFOr rWw07VMJgsgeIorT5t/6SBaXRr5dFPnF434bkYP2p37pHb7lAJeaNQWXDcOXysf1S9mTAiEI1XbqG 5WnuHPn+IiZOFR5rugTLcqkQJiitML1gYzAi4ZC2Ew4CPW7C6xyc+HIAeWLwmbNQNVBhDScORrpBR wru4PQBg==; Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgLLs-00000009IbW-2WrS for linux-riscv@lists.infradead.org; Tue, 20 Aug 2024 09:40:34 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a7b2dbd81e3so727851166b.1 for ; Tue, 20 Aug 2024 02:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724146828; x=1724751628; darn=lists.infradead.org; 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=ZY/iGek7oJwLxPJ1JKwoSRK1o1gPKN3vGl9eBXs8wms=; b=Wla9F86sJ8X1NZTDRXrPrS4ygzmMb5v/M5D+OfT5i8UsBENoHACKLlwcNtErmYofHq MME564KlnVhrCCl86icHhr8P2862QZLhXrdRbzoB2mALaNePYzRasS4yI6SeSq2Nkm/i Us+K1THY9BFrMy+XzydM6i4mlc541qqZLqK1qUYUB2eazBhNc3DGpjZobsy90/a8L4Tt L81puT49ZkHIJLWNZwTnIMl5iUD+me5pS0w0tQC8+CQkTMKo7y5MuyGstucOUk2lOy54 T95J8nuqljziBdxSkWFoHZP4pwnf/R17ejbRkDG5Mp3iq7qFMPGEzy9warWX9JXZEbK1 VVZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724146828; x=1724751628; 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=ZY/iGek7oJwLxPJ1JKwoSRK1o1gPKN3vGl9eBXs8wms=; b=ij7PI1zFot7IRL614wJU3Z7k2dvHdryLtzTSumT29Ku0HPAZykg0OqfG09eSQrJNsP KqHIBUf8ewtbZdTWnEucCdw99rl0UxA95zXrtg5C4axfbVCvZ4Q2ah9VEus6ABj1R/O2 VpLMUWho2OHjIe8hRdTUNS1WSeoOCeTSpWLrRamaXNHOthBA7A9HyUH/lUU7wGIel41l 8391X9Pd7BiIrvxeyL8iFDa4xUnISpQnswyFhXLhzyK1/QlHp2LO4++fIkmSHx/uEXpn l1VJx9L3lsmEAip7Cs40K/IIK7dBToh0ABJLv3Ynh4YdG5Y+iiA6KeqBAegGORQ8h3tb pHWw== X-Forwarded-Encrypted: i=1; AJvYcCX9hNjZl8Dw0DZ9MQywk9h7R7XMAXaaN3WckJxX0i9oA0KStjwN5X8KR/5tbVEuGuQs5c+OuV1XA8MGFA==@lists.infradead.org X-Gm-Message-State: AOJu0Yx11z/ckO0jmCa6MqLwts7iYeWcnVDkUMrsYjTjmEWyeaLDNI4E 4ihzA5LgIWuYwv71x+UrgaejEs2zKTf7ADF/x62+8o1Xi4ZXpIALGUSruKJwSv8= X-Google-Smtp-Source: AGHT+IG+nLIH5fnCkD0hF9cIx7+KS2wkkUp+2yCqq4ti9srWQVHwWsENFCJzq2xptsWju6FvoZxRiQ== X-Received: by 2002:a17:907:70a:b0:a83:a85b:ed40 with SMTP id a640c23a62f3a-a83a85bedb0mr774398566b.6.1724146828420; Tue, 20 Aug 2024 02:40:28 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a83838d023dsm733613366b.64.2024.08.20.02.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 02:40:27 -0700 (PDT) From: Krzysztof Kozlowski To: Anup Patel , "Rafael J. Wysocki" , Daniel Lezcano , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Cameron Subject: [PATCH v2 2/2] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop Date: Tue, 20 Aug 2024 11:40:23 +0200 Message-ID: <20240820094023.61155-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820094023.61155-1-krzysztof.kozlowski@linaro.org> References: <20240820094023.61155-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240820_104032_824229_162D7202 X-CRM114-Status: GOOD ( 11.79 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Use scoped for_each_child_of_node_scoped() when iterating over device nodes to make code a bit simpler. Reviewed-by: Jonathan Cameron Signed-off-by: Krzysztof Kozlowski Reviewed-by: Anup Patel --- Changes in v2: 1. None, only Rb tag. Other patches from the set were applied. --- drivers/cpuidle/cpuidle-riscv-sbi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c index 5bb3401220d2..d228b4d18d56 100644 --- a/drivers/cpuidle/cpuidle-riscv-sbi.c +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c @@ -448,7 +448,6 @@ static void sbi_pd_remove(void) static int sbi_genpd_probe(struct device_node *np) { - struct device_node *node; int ret = 0, pd_count = 0; if (!np) @@ -458,13 +457,13 @@ static int sbi_genpd_probe(struct device_node *np) * Parse child nodes for the "#power-domain-cells" property and * initialize a genpd/genpd-of-provider pair when it's found. */ - for_each_child_of_node(np, node) { + for_each_child_of_node_scoped(np, node) { if (!of_property_present(node, "#power-domain-cells")) continue; ret = sbi_pd_init(node); if (ret) - goto put_node; + goto remove_pd; pd_count++; } @@ -480,8 +479,6 @@ static int sbi_genpd_probe(struct device_node *np) return 0; -put_node: - of_node_put(node); remove_pd: sbi_pd_remove(); pr_err("failed to create CPU PM domains ret=%d\n", ret);