mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vincenzo Mezzela <vincenzo.mezzela@gmail.com>
To: linux@armlinux.org.uk, robh@kernel.org, rmk+kernel@armlinux.org.uk
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, javier.carrasco.cruz@gmail.com,
	skhan@linuxfoundation.org,
	Vincenzo Mezzela <vincenzo.mezzela@gmail.com>
Subject: [PATCH 1/1] arm: devtree: fix missing device_node cleanup
Date: Fri, 12 Jul 2024 11:44:48 +0200	[thread overview]
Message-ID: <20240712094448.159784-1-vincenzo.mezzela@gmail.com> (raw)

Device node `cpus` is allocated but never released using `of_node_put`.

This patch introduces the __free attribute for `cpus` device_node that
automatically handle the cleanup of the resource by adding a call to
`of_node_put` at the end of the current scope. This enhancement aims to
mitigate memory management issues associated with forgetting to release
the resources.

Signed-off-by: Vincenzo Mezzela <vincenzo.mezzela@gmail.com>
---
 arch/arm/kernel/devtree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index fdb74e64206a..223d66a5fff3 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -70,14 +70,14 @@ void __init arm_dt_init_cpu_maps(void)
 	 * contain a list of MPIDR[23:0] values where MPIDR[31:24] must
 	 * read as 0.
 	 */
-	struct device_node *cpu, *cpus;
 	int found_method = 0;
 	u32 i, j, cpuidx = 1;
 	u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
 
 	u32 tmp_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID };
 	bool bootcpu_valid = false;
-	cpus = of_find_node_by_path("/cpus");
+	struct device_node *cpu;
+	struct device_node *cpus __free(device_node) = of_find_node_by_path("/cpus");
 
 	if (!cpus)
 		return;
-- 
2.43.0


             reply	other threads:[~2024-07-12  9:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12  9:44 Vincenzo Mezzela [this message]
2024-07-12  9:47 ` Javier Carrasco
2024-07-29 10:18   ` vincenzo mezzela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240712094448.159784-1-vincenzo.mezzela@gmail.com \
    --to=vincenzo.mezzela@gmail.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®