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: 13855982 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A521D0E27; Wed, 30 Oct 2024 06:44:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730270666; cv=none; b=losXVh7JeRVS1BF5QxEyyYiiNiNjpAD9MhAiGQDJfPUzgM/9uABFGjifRrXc5p36426b40RciHtWXlQ+yeU76nr0ZckyUIHl9TePlU7rYhFGC+GbkDPZV14fmdesTrDL2N4SvaeYqiHiBJmbVmxwoW+LWqTeau6wSsizeFA1gKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730270666; c=relaxed/simple; bh=BckDlgNxXN37WM9rRTU+h45QD44ycxfdprrjTJEpleg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YdGVUo9s6gFS2qGiOgEPtgAz7OM2eURmnZttIq74dt/lBK8oUR66+ce9r4Lx/4C/0bUalP4Au8PQb8sDK9m1r3S9YWwGwfahVxlcDZVeBKPWLlVbavfq/58sDVraoK0BnYUKx/rm96yQKQXKiVmMSQp3PDCA6r5Kmlm6vX5N1CU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MVzoA2ds; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MVzoA2ds" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-539d9fffea1so5854498e87.2; 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=vger.kernel.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=MVzoA2dsF99t95Yv/Xz0FeQTqW9DT360JeMgJ0ueDzWvKObrySX+RVu0KW5N/u0gjz V6q/RyLK4kmA1Ryn0AbBtrvk3bH0oH7mpFHG/IncfqMUrbGweiX7ZMKRSkXJHnNibMJE Op0+9OjwyE4MdXoqvz1JDhy1XnRhdYooCBqTltaSjoi/GtoDjrLQ2dcCREjqCo7eQ8vu 2B6u1Fd7O/nEFOxmlz5Ei7ttq2dMDUDKQYoQXwnG6pWpI2IYIMoTQQ9K46fAYg+Mjtb3 JSw+O0+/b8Yg+7ls++lmX2fN+vCYsqFMFeQ4QucnDdGIHj321JrGP4Yrk5/pU5KAhpuX JSug== 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=qtTh+LrOtCOM6NJuFSzjplvI9Tljjq9DMzFTXhMsDbo4Ye/D1CbnQnw4ARpVSJdmmg 2dKYZDLgNKAlL2StFCTq1aj2sgSybS9TPXMJTQMIrZ+UmOQYo50u77YYMz9Ey+brTarw NW+EGla+wQkqYUEvMz9l02gwztbw6J9H7TxFnKognQ36wk7Q56JzDidJWRFi0gPynWIy H7vOkpQ1SN1JQ7et/tKrsID9x1VCuWeN9G9BqpD4oj1eYSUKneiQemcItikvtLgFek3p RWsPv1p7xCAhMCs10ne/1ok78aSUf9WGyNsDXVp+nffW7vn0L1liTeBWziqUcQbhElQZ 2pWA== X-Forwarded-Encrypted: i=1; AJvYcCU1CCwkLJM0JyUFEhtcW7LQbDeGd712csZQpbGU3OcVECstHFu11TH1tEx6EDOuoe3GUHWyA1FJ@vger.kernel.org, AJvYcCU4S4VSmZUlPykf1EAGXwRXacUSZzu6/3EMiWizvTeweftneMwwxirzEHw05Bs2kvvEE4Y0agpzMnc=@vger.kernel.org, AJvYcCXOFmAhv3s/0V+H5pRB2wt6p9PFi+s1R8Vk7x0cMWEB96Il4ktaL111KVB5l7YqMZJ8MlOAdKRu+BygXSs=@vger.kernel.org X-Gm-Message-State: AOJu0YymjZX8evltyg4ZQ/KDE87HFU+kQE/4fFhA18EeTM+kbv5cu2+Q iymxNMM5qLCj0xL77HkJbyE4FkTIxBi5VOrdCEx63gQewOjLAAsVfL4ZNKF2 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 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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= 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: 13855983 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F7B11D63E3; Wed, 30 Oct 2024 06:44:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730270667; cv=none; b=Z09lAA1PkpCjq0NBOgAH0n25LLdWFzuN8htPR9S9XKgtu5QFTGEKrzezsJonMRaglKCmujYuFQi1MX6h1LBcYHs/2GehEPixprY2YPVYvukYqpnbyO/WgOqgjcjgkiJ2dy9+ozDyCsshcOJUZLJpWQK6R5KOm5CkVhHHkLhDWNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730270667; c=relaxed/simple; bh=m1T9HiX7+i3wBf2xZSXfSq8sq++p65LRzFdeJzf9CJM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VaKLL94Ha9pJ++m48fjpY4yzfmvuALGYNV364Qq1qEZEFhUKeX0MK9wOB9FIoJYdz/Fd9QxNAbAi7X39l9GGrWhMO/vyH8PvgxseSbpvIMg5V5dV4umkfeFScmuiVnMz+ICgxWkaG3vuCF/W+KTaA2T2fK+xzku+eFtWjK57U18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CQwzxd/9; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CQwzxd/9" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-431ac30d379so23953925e9.1; 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=vger.kernel.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=CQwzxd/9lw09CzCelITZ3IP3errExT0W/4mfYOSfbU06ldkwUbtx8h+e4twtgGTrMQ DFNuVIg8xyha/Tv08nUJzHzREzw0N9rs5FhNdIgdMcrO9v2WE6hbRRxChb18SUWXdwZS 7oNMQ4kzAqX1J2HeEYVvM+3S0NZMpprQ3uE/qk9OGCQw+4mnVJCsp/ES5ezLrClTOHJF 9/sX1/MASEJ35bAAmK0/0FJC+DoY5isB43xsmH3bhhi2c29Lk6BSerTy7ZRFcgIWkeNm MUjsOg7Rk8NrdF3jkydF1gkcjlFVXkdq4ae0GzkgL/45G7jEbMQP6Dl60HyYEVgpM6Ak 5XwA== 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=FStcK0gfq92wYZb3rvIUPJPyN8KsNbukbiPEpbYmgSn3TtgKDhDFyw8r6NL9EQy9oN BRm1zH9zmBUIHATe03rdMYFNUI8gbfO9xjKZt0VwVV2dW/73DDprVmAuYNdsQrAFEv+T Vok4Cq/dhq688XaJQ330t4znsyHRxzrqsKYSDCzPt1lPV1jIK08a73NfUyKddWVkjtTp OvJrl+cerR3SIghFyzTLI5Qj23lqBO6MdQRtXb4X2OQYfTMNvKcC4yy70fp5wyW0a/bE ZilhYdw3CRLJd3BdoZ/RydR4oyCKqcgNboUIFLVEbbKpqUsruvLVTDKxZqy6HzUAD4GL dOxw== X-Forwarded-Encrypted: i=1; AJvYcCVKhY44o/LCiIr+E6oQBigFm6g9BG+AtVUVDn2/KDcgREagN8rp8U6bOqTTUAd2/IOn2VM4BFXyR3pZFoY=@vger.kernel.org, AJvYcCXhBEA2YNBiFCHLj+FwTFs7nxvw/8qAaxM19dDlC9yZYmYzhtap0oybIkPI/I5XONJWxLB1E+BgQjU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxwp7WGYxUGdE2ZRDNN84FkEGWRBsJoG76k8IpEGPdrqjwOSVng dP9ziXU9x7nFa+l4MCgwXEfyTptjZBEaMXxWpaKFSJD1DY15fQWHkL2EiV8C 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 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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= 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 */