From patchwork Wed Oct 30 06:44:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13855986 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 2F0C5D7497A for ; Wed, 30 Oct 2024 06:44:34 +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:Cc:To:In-Reply-To:References:Message-Id :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=DU/+4X/gJA8HKPmUGvU6ke3dHix8eL/Ec9Hxcp0HqZk=; b=xMPkM8fe3Ofmaj CeANHHTnDJgcD0ZHVKfbGOvyzWGfEMhYoAv00Qdn0yYUQGdR/GPn4YOd2oTpMBmv6dnROOrXlNMI8 NL2NtqEGps//cdH7wusHRlJXiNTIcLi9QIRJwbYtr8IAmpdDbgDAWFLltyY+wDpRK1hhHUVlHuRYq OOaoYHVORzekqKz6HuWJPDZ0VK9G/r90+zRJW1iVBBsdXsTlzmidjRgNTbUteOCy3QOAxmTKgPkD8 239czt30pWhq7cPgABEnpKlA83xLqzmEF4fuYJsCq2g53TJYCxGc/OO745Z9MqJNJwr9m7FEBjEaG 0apyU1Yor9I55ydU1T3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t62RQ-0000000H0gg-1Q0R; Wed, 30 Oct 2024 06:44:28 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t62RL-0000000H0ev-2MkX for linux-riscv@lists.infradead.org; Wed, 30 Oct 2024 06:44:24 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-539f4d8ef66so8164112e87.1 for ; Tue, 29 Oct 2024 23:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730270662; x=1730875462; 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=S8LuPiSu7wFtVCRkCbuWOFPZfKo40h92poaJRDjY0b8=; b=nZHuuetGkwmUTCdhfkTZR2b8V9V5YOT6HzeNHW38YkzVdOdyVyi/khMI5SToRkLe+m Enkw77uHCAuL7cR1hFhqjP0of6PTCpNITe9vzf97zrtmKooZM8BcfbqB6pnHXu0ZrZJ8 2MzqQzbMvj0vEhOk/iM9keolcxZx1SfLi1N/vFOC80vMRuiBMf8PtFCItYpjomLxfWwD yQWdxF/R7BkYSWueSE2s1vZqoWwG+pCG6kK/rVOYm5xFngRHnY7VF782GPx3kAu5gNgI ouCCBKytwVW0MaUsX/UzbEh5qLtsl8x4Z6/tSO9++rkCu81leCHQTQq4pAGZS/8HdKOg kydA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730270662; x=1730875462; 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=S8LuPiSu7wFtVCRkCbuWOFPZfKo40h92poaJRDjY0b8=; b=VKfYK4woX33VcOvFXRNAWHEA5kdSPvmmC+eYFqVlIUuIoLDkJ5c1tjjEL+MWw/fJYw 8jXadyvI3zMR/bg+FpnwzyLu05ZnQrVzQWfd/cYYmI1sSuuex5HXO0jG/SQZReXctyOE 9XAYyPJ1UK1Qx0L6dd0plwfNY3P9RWReKs1feCLwr9/uct5JkSWWQBF+qpJq/B7e3FIs VlDS1MMyfMOt+n1yy3h3Ct5YzQPj47kPLFA4cBuV6WtD3HvFsm9EK7s+PoauSGc5kxh0 IYxhgIarXaaW2oiETJvIAfDHsLr3DkIs9nkL8AqcIH2Ou5xcGvDJEYv3WhrxZIC1nOxj 1YYw== X-Forwarded-Encrypted: i=1; AJvYcCXvv+8Jkxf+T3/s45Ya5+mTV2AKtlhSWrSaeu0a261x/8HelznAOJS2lv1LsDzhMkId0d4Tr6cZEpFJIg==@lists.infradead.org X-Gm-Message-State: AOJu0Yz2B1dpnq4h29/h7Hncxpk1t/xBMhCVTtzSvNLj/V+cz0bFn1ut HvXViTj6ehMBKmpVVz3Xjfs9xMLdG+e8ohAosJ+qJQayiQoFycYv X-Google-Smtp-Source: AGHT+IGWhVQIhV4BdDIT9PkTI8qrQQX12NQPVSDcsmyAO931TnpfZkEuwVFFDyI12BadGeJMbiXo2g== X-Received: by 2002:a05:6512:3caa:b0:539:e88f:23a3 with SMTP id 2adb3069b0e04-53b34ca488fmr6256607e87.60.1730270661384; Tue, 29 Oct 2024 23:44:21 -0700 (PDT) Received: from [127.0.1.1] ([213.208.157.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd9ca704sm11249655e9.41.2024.10.29.23.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 23:44:21 -0700 (PDT) From: Javier Carrasco Date: Wed, 30 Oct 2024 07:44:09 +0100 Subject: [PATCH 1/2] cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu MIME-Version: 1.0 Message-Id: <20241030-cpuidle-riscv-sbi-cleanup-v1-1-5e08a22c9409@gmail.com> References: <20241030-cpuidle-riscv-sbi-cleanup-v1-0-5e08a22c9409@gmail.com> In-Reply-To: <20241030-cpuidle-riscv-sbi-cleanup-v1-0-5e08a22c9409@gmail.com> To: Anup Patel , "Rafael J. Wysocki" , Daniel Lezcano , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra Cc: Palmer Dabbelt , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Javier Carrasco , stable@vger.kernel.org X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1730270658; l=1134; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=BckDlgNxXN37WM9rRTU+h45QD44ycxfdprrjTJEpleg=; b=ujl2h06lGh4YP2Y79CiPlMHPbox7pBxEij20AzVxtyPJO6YkpF6IXkkR1VQPlWKQticw+fNHm BmWt+LqTvfWA8Vjuu0X/60D+gHiHeI69Qr32rb1foKW4ivVqq8FVgUK X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_234423_638448_E11524E9 X-CRM114-Status: GOOD ( 11.05 ) 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 The 'np' device_node is initialized via of_cpu_device_node_get(), which requires explicit calls to of_node_put() when it is no longer required to avoid leaking the resource. Add the missing calls to of_node_put(np) in all execution paths. Cc: stable@vger.kernel.org Fixes: 6abf32f1d9c5 ("cpuidle: Add RISC-V SBI CPU idle driver") Signed-off-by: Javier Carrasco --- drivers/cpuidle/cpuidle-riscv-sbi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c index 14462c092039..2b3aec09b895 100644 --- a/drivers/cpuidle/cpuidle-riscv-sbi.c +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c @@ -513,11 +513,14 @@ static int sbi_cpuidle_probe(struct platform_device *pdev) if (np && of_property_present(np, "power-domains") && of_property_present(np, "power-domain-names")) { + of_node_put(np); continue; } else { sbi_cpuidle_use_osi = false; + of_node_put(np); break; } + of_node_put(np); } /* Populate generic power domains from DT nodes */ From patchwork Wed Oct 30 06:44:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13855985 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 66859D74977 for ; Wed, 30 Oct 2024 06:44:33 +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:Cc:To:In-Reply-To:References:Message-Id :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=+/wjct+QjANbv2SpcV8a5r1+fNqelH8uLyWhGpvv8qw=; b=gpaO2P1ANd5CfX QtjGjmrzBtr7bkZ62COm+rnH79lbd5+Q2bX8jaTFPkvcr3ISJUuFWjG1hAnvV4NR0QQsgyd3b900A ZYghbZKOpRfTxyC/4tXZKiJ+lS12jFwjymsRh3fRx7Ti52YJb4r/byNd0qv+Z7QG2N7xEdiXyjilk /cbNl4f7cmQkop8Q0IaQ50GSYqrC1hmoFpx186ovlAV6uHygyfCGxs5WOqVA4mjtvJ1Yb/VYst+uY 0h0V78Fat8zINjkLewVUbdZ1EZIOHVe4bYK+WkWcQrqa5056/+RXfIvBKDREkl2FDT6Bn0+M8TTxe jYL7I+WeyPfNMFX1FnpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t62RR-0000000H0h0-091u; Wed, 30 Oct 2024 06:44:29 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t62RN-0000000H0fQ-1KMV for linux-riscv@lists.infradead.org; Wed, 30 Oct 2024 06:44:27 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-43168d9c6c9so61514745e9.3 for ; Tue, 29 Oct 2024 23:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730270663; x=1730875463; 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=xthRcNHrX1KA8pnYHsJC/36HOWII/OJyqHZyYAZYrXA=; b=SCopHxT3jgcXvnYrIZe9p97ZpuxCws6KGvy99R1J5S+3f5ZhdPhWBvu1H1OhQ6qkcl oDSRTvxwLoh8aW/oMwidnpp4IR91WClmQKibwmHvxgbd/hZnQbzdl3msl6ABVkIY75Bx 2NKi0bLKt0gSb2layIobVyPzIZuL1zENwqdmCd6nlyd9mJC7ycZ2JkPuMe8cJHqCQm9U r6SUivK8x8BtAA03hLIPFor87rOFKMQse4C0MYisVPaVKTw//sUXvDF9NasQDOXrxOA8 IfTNW/GAjjz0KVfhEeAjS6m0gfQFF6eReS62zQNTQMgK1ZxVvGhAFYfMWeAVOP7amFR+ pqhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730270663; x=1730875463; 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=xthRcNHrX1KA8pnYHsJC/36HOWII/OJyqHZyYAZYrXA=; b=cihGPiE/3k80aVa2rabvtr0nwfgTTz8o/8VdD6qi6x4BtUsaErkrQKW/kZYhTeT7Jt WUhQw6btZRtitnIqk4fOa7Y1Xavd9IYGf1wJaKe26LiCPF5XMz79bpi6iGf5XtgwLA0j qpSIe6tITIyDMsl2GLwdWzWUy2JtMxIRsTCQWCb8cLofN+YnxvvPPx0vB+Bt1qp83a5C A7+0FcWcHDdYxSJLWvl54xodzCsaForv0Dy16taoFo7SIF9Y7UWizH2TznQE4Zn5k03A dh3+YhqWgzReoNSa17UoSGHwBUJLcFs3l0OaibG0LXnTbLSBwuIF2c43WzYktiCgBSe1 hg2Q== X-Forwarded-Encrypted: i=1; AJvYcCU/iaUnFw+hHI1EAD6dDhidr1vehtD4ndU3Qg0MhcbtcV6108QTmmWknyxiq2c5nvMtWpj05j3OSS7mbw==@lists.infradead.org X-Gm-Message-State: AOJu0Yyl6jj+MpHAk0Kqzp72p9imljOXwKMSoZowhb36BgdBUqlkwsxS 4kcwLOyUCa402lqeulxI2ON2jM45cdE4QRudcADDbwAjs3X2mj3s X-Google-Smtp-Source: AGHT+IHQ1NHOTA/Y5PIyYKQkbEKei8UPfqq6CzosOO568i/CJvp0+diEhs8+E3HO+oAewO52R20TBQ== X-Received: by 2002:a05:600c:3b86:b0:430:5356:ac92 with SMTP id 5b1f17b1804b1-4319ac7642emr125927235e9.7.1730270662983; Tue, 29 Oct 2024 23:44:22 -0700 (PDT) Received: from [127.0.1.1] ([213.208.157.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd9ca704sm11249655e9.41.2024.10.29.23.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 23:44:22 -0700 (PDT) From: Javier Carrasco Date: Wed, 30 Oct 2024 07:44:10 +0100 Subject: [PATCH 2/2] cpuidle: riscv-sbi: use cleanup attribute for np in for_each_possible_cpu MIME-Version: 1.0 Message-Id: <20241030-cpuidle-riscv-sbi-cleanup-v1-2-5e08a22c9409@gmail.com> References: <20241030-cpuidle-riscv-sbi-cleanup-v1-0-5e08a22c9409@gmail.com> In-Reply-To: <20241030-cpuidle-riscv-sbi-cleanup-v1-0-5e08a22c9409@gmail.com> To: Anup Patel , "Rafael J. Wysocki" , Daniel Lezcano , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra Cc: Palmer Dabbelt , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1730270658; l=1323; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=m1T9HiX7+i3wBf2xZSXfSq8sq++p65LRzFdeJzf9CJM=; b=FHS7yNAJhB0v5GNqH1PLbBsfTbP5beoCMPpMWfQ6NgPppVeYQ2SabddKJWpbSascpojP1A6CL NqbpY1ha6EuCDToUI3DaeH4JLkvR6jBIP9xAYthV0M5/f7YLsBJ9iQf X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_234425_409120_74340557 X-CRM114-Status: GOOD ( 11.46 ) 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 Simplify the code and make it more robust against new execution paths in the loop by means of the cleanup attribute. Signed-off-by: Javier Carrasco --- drivers/cpuidle/cpuidle-riscv-sbi.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c index 2b3aec09b895..3a78d6b7598b 100644 --- a/drivers/cpuidle/cpuidle-riscv-sbi.c +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c @@ -504,23 +504,21 @@ static int sbi_cpuidle_probe(struct platform_device *pdev) int cpu, ret; struct cpuidle_driver *drv; struct cpuidle_device *dev; - struct device_node *np, *pds_node; + struct device_node *pds_node; /* Detect OSI support based on CPU DT nodes */ sbi_cpuidle_use_osi = true; for_each_possible_cpu(cpu) { - np = of_cpu_device_node_get(cpu); + struct device_node *np __free(device_node) = + of_cpu_device_node_get(cpu); if (np && of_property_present(np, "power-domains") && of_property_present(np, "power-domain-names")) { - of_node_put(np); continue; } else { sbi_cpuidle_use_osi = false; - of_node_put(np); break; } - of_node_put(np); } /* Populate generic power domains from DT nodes */