From nobody Tue Feb 10 05:26:07 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 6AFB01474B2 for ; Mon, 13 May 2024 08:13:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587996; cv=none; b=R0zA2g0TPz7VUq7joUSO6xuRBksnD4WtnJjAhmWguC0uK9lofeypyl6ma1+gWna3D7fQBHhiMIc8KORkRSGsRTxxBKHUzTznczr3TFEYIOsrObdOmqZ+B8g4ifrWvbBNLkyy//drKFtDj3gAmmHTfYj5/TFHnCd1TQB2Qz6pqKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587996; c=relaxed/simple; bh=Na3kXLkRn57AYhgOBHgrLyZdlf9VwDpzCo459lFXX8E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sbcuKhGTZoUvJa7A6+0EWb7w3bo+j4Eb1UO2ezB0f9KhPi/MeyRbu6KDi52TUCBN4PwY5nh3jFYiV/BLxVTGlFt4K5zAXbia3ZH/605mn0N8L4QjDqYHwQJEn1xnQ0QC1rWRIjRUY9QRUFHyUofBjrsGKQSP7r7A2RqRTSukJVA= 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=W9ftQ4qj; arc=none smtp.client-ip=209.85.128.52 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="W9ftQ4qj" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-41ff5e3d86aso18213165e9.1 for ; Mon, 13 May 2024 01:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715587993; x=1716192793; darn=vger.kernel.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=zLJtQN7Bc5zh6oDDzuNRzBN4QxI3AOSG3b/sB8YLz6M=; b=W9ftQ4qj4y+NJ9x4+z62Wl/LS45zIoQbtdPxyVPHbNz661qn5WeI5FstpJH4gK4fSX S+1/mnUsqYdlxhXZB16zylZAa7mQe3aZ4nFgaPPgwed9d9DB95wNN7dWRhIPAWv2tXGq 273nb5lKTK5QYd1iAHu3CvcPS1n7/AHSArBsUXCq/HNRFE1w2OTw4O3KbZnlOtQ/obn+ q/NlDqnFp1N+tF5Rw6T8XA1GL0UlY8KPTUGIDBP9FM20Mklm3DFyG2P+tv7te8lnclLK Ls2EClG/oQ6aSVOb4p7J06AH4sZKeRldn+NRieAgt4bxsf5ZK/FYpLMFT51i6wZT1Nfp lfPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715587993; x=1716192793; 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=zLJtQN7Bc5zh6oDDzuNRzBN4QxI3AOSG3b/sB8YLz6M=; b=CQOpMuY4nVQj29GC954xRi3PFL2JpbayCqhRCN/rIvARrkEJXZUlWzrWN3I5jYFy7q JvzD8VQLRMkjin4rtI+goQyXoXT51hJc8cWH+krnxR+/NOcr5/WTAbSSl2t7NB76UEJy DYzSaUer+jkwh2Rn0Ig1ivVCDLBtXZPttAkF2Vy/7EMIf7al3LzscdRwojyC0l+GabvR ADJ22u1znYnLaBHcu88+3tffMKQONc1a4wgOfqo8hgGvidlDMXchtfswLVWp34pO4dhW JZHlzvr/4VUZtKSUzkkSJFIDRZGKMoMEAK1KXzsL4Fdi1WhdxrmhAbs/DVj0fCa09BSo GBWQ== X-Forwarded-Encrypted: i=1; AJvYcCXwgIHZZj4kGBXtvvq+VCfXw0j418x5Kh0lJOIWcKVdWR8pLt3nYX3YR0Ef0LIAs9qhEwLADJCECCD9yljU5Hv5zXXs8jAWikucw7zn X-Gm-Message-State: AOJu0Yx9U63OJj04k3a+aA8FTFh8Hli+6WWLqup95fNLJqWNrnDovWQ1 M/egODaOiGS39W5K4oRxeHLB0bkYg2OBtTNM1KkC0FXNEV3SpLMi X-Google-Smtp-Source: AGHT+IEff/OUcRTtaHMDUkIg3FlBxHKlEVq2xT3oVi1BqZHgzE8YwBVHHRU+ACmnKhc/MU/T+/bM/A== X-Received: by 2002:a05:600c:314e:b0:41a:bdaf:8c78 with SMTP id 5b1f17b1804b1-41fea931891mr65664035e9.8.1715587992498; Mon, 13 May 2024 01:13:12 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:ac9:e686:c88b:6249:b2f4:9ae2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b8a77f8sm10399563f8f.54.2024.05.13.01.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:13:12 -0700 (PDT) From: Vincenzo Mezzela To: sudeep.holla@arm.com Cc: vincenzo.mezzela@gmail.com, gregkh@linuxfoundation.org, javier.carrasco.cruz@gmail.com, julia.lawall@inria.fr, linux-kernel@vger.kernel.org, rafael@kernel.org, skhan@linuxfoundation.org Subject: [PATCH 1/2 v4] drivers: arch_topology: Refactor do-while loops Date: Mon, 13 May 2024 10:13:03 +0200 Message-Id: <20240513081304.499915-2-vincenzo.mezzela@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240513081304.499915-1-vincenzo.mezzela@gmail.com> References: <20240501094313.407820-1-vincenzo.mezzela@gmail.com> <20240513081304.499915-1-vincenzo.mezzela@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor do-while loops to move break condition within the loop's scope. This modification is in preparation to move the declaration of the device_node directly within the loop and take advantage of the automatic cleanup feature provided by the __free(device_node) attribute. Signed-off-by: Vincenzo Mezzela Acked-by: Sudeep Holla --- drivers/base/arch_topology.c | 107 ++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 024b78a0cfc1..0115011b7a99 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -543,23 +543,24 @@ static int __init parse_core(struct device_node *core= , int package_id, do { snprintf(name, sizeof(name), "thread%d", i); t =3D of_get_child_by_name(core, name); - if (t) { - leaf =3D false; - cpu =3D get_cpu_for_node(t); - if (cpu >=3D 0) { - cpu_topology[cpu].package_id =3D package_id; - cpu_topology[cpu].cluster_id =3D cluster_id; - cpu_topology[cpu].core_id =3D core_id; - cpu_topology[cpu].thread_id =3D i; - } else if (cpu !=3D -ENODEV) { - pr_err("%pOF: Can't get CPU for thread\n", t); - of_node_put(t); - return -EINVAL; - } + if (!t) + break; + + leaf =3D false; + cpu =3D get_cpu_for_node(t); + if (cpu >=3D 0) { + cpu_topology[cpu].package_id =3D package_id; + cpu_topology[cpu].cluster_id =3D cluster_id; + cpu_topology[cpu].core_id =3D core_id; + cpu_topology[cpu].thread_id =3D i; + } else if (cpu !=3D -ENODEV) { + pr_err("%pOF: Can't get CPU for thread\n", t); of_node_put(t); + return -EINVAL; } + of_node_put(t); i++; - } while (t); + } while (1); =20 cpu =3D get_cpu_for_node(core); if (cpu >=3D 0) { @@ -599,48 +600,48 @@ static int __init parse_cluster(struct device_node *c= luster, int package_id, do { snprintf(name, sizeof(name), "cluster%d", i); c =3D of_get_child_by_name(cluster, name); - if (c) { - leaf =3D false; - ret =3D parse_cluster(c, package_id, i, depth + 1); - if (depth > 0) - pr_warn("Topology for clusters of clusters not yet supported\n"); - of_node_put(c); - if (ret !=3D 0) - return ret; - } + if (!c) + break; + + leaf =3D false; + ret =3D parse_cluster(c, package_id, i, depth + 1); + if (depth > 0) + pr_warn("Topology for clusters of clusters not yet supported\n"); + of_node_put(c); + if (ret !=3D 0) + return ret; i++; - } while (c); + } while (1); =20 /* Now check for cores */ i =3D 0; do { snprintf(name, sizeof(name), "core%d", i); c =3D of_get_child_by_name(cluster, name); - if (c) { - has_cores =3D true; - - if (depth =3D=3D 0) { - pr_err("%pOF: cpu-map children should be clusters\n", - c); - of_node_put(c); - return -EINVAL; - } + if (!c) + break; =20 - if (leaf) { - ret =3D parse_core(c, package_id, cluster_id, - core_id++); - } else { - pr_err("%pOF: Non-leaf cluster with core %s\n", - cluster, name); - ret =3D -EINVAL; - } + has_cores =3D true; =20 + if (depth =3D=3D 0) { + pr_err("%pOF: cpu-map children should be clusters\n", c); of_node_put(c); - if (ret !=3D 0) - return ret; + return -EINVAL; } + + if (leaf) { + ret =3D parse_core(c, package_id, cluster_id, core_id++); + } else { + pr_err("%pOF: Non-leaf cluster with core %s\n", + cluster, name); + ret =3D -EINVAL; + } + + of_node_put(c); + if (ret !=3D 0) + return ret; i++; - } while (c); + } while (1); =20 if (leaf && !has_cores) pr_warn("%pOF: empty cluster\n", cluster); @@ -658,15 +659,17 @@ static int __init parse_socket(struct device_node *so= cket) do { snprintf(name, sizeof(name), "socket%d", package_id); c =3D of_get_child_by_name(socket, name); - if (c) { - has_socket =3D true; - ret =3D parse_cluster(c, package_id, -1, 0); - of_node_put(c); - if (ret !=3D 0) - return ret; - } + if (!c) + break; + + has_socket =3D true; + ret =3D parse_cluster(c, package_id, -1, 0); + of_node_put(c); + if (ret !=3D 0) + return ret; + package_id++; - } while (c); + } while (1); =20 if (!has_socket) ret =3D parse_cluster(socket, 0, -1, 0); --=20 2.34.1 From nobody Tue Feb 10 05:26:07 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.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 40151147C63 for ; Mon, 13 May 2024 08:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587998; cv=none; b=tKWRhZ9wSSaMHv9OH6/Sl7Wh2w5x2vB1Dy28RSw1oieFlFDuy4Q4JOeGiZb6v4fO6XsQHp3mlhjyAzloYn2n3z3bLUz09SCB2JzLC6oHMBf/VOcBPgK2K6rvwEEgBalpod8ullk93fZN6vX+EnG+63HvVaJjuvr/BCBdvpVMmf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587998; c=relaxed/simple; bh=8rQNnlpHNwSiby7H2KfOJ545BmEBEQbSDs3gFqf7ryE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bnI76sie5DpsfWocuzQAJ3rltHyNX4z/Z5scxxo1lZUgej+1BW8rvjsOlIXBanDFQcrh16gDhZd9HlB2YaknG9gv8C8LoJR6mq5nXtHENy1iioRuxwk9u6W3nbdUBH6OjC00dcpraOFYkLXtkglzN7fTiO5pJMY3u1+4Oz9yR6A= 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=Tx5o+0Uv; arc=none smtp.client-ip=209.85.128.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="Tx5o+0Uv" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4200ee78f33so13396005e9.3 for ; Mon, 13 May 2024 01:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715587995; x=1716192795; darn=vger.kernel.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=KjI2GIzbNeY5mYmEJBzlwq8aj+x1UHEKf/2QoRMS7Cs=; b=Tx5o+0UvrfIe/CofrsmD/lehG7oTjpJtTWWSlzySl7G/CygVmhWepYMiCkTHSVbYDj Kl4fhlzkv6T9ByUwTK8aBQ5AHoYLsgrZ1frgggBpv3K2fx40iO+5QLJbFcoFEB8L8iST cpxkLYyiTkJTOE3EOSOa5CiTfg0YsvgT9vNbtB9NS4cwImnOd46jwUnTzH4Vyp61IJtr 7xggBl5OPhGjeHquS+nx7xB7vFR/DKWBymjJb8NmIWKblc54eqmwRSD6l1/ZD1IjZG4O CyGrUDe71qZ3P+jjFweP5OHNf7zcblIH6jsTpXunW7a3hZPXh46XLWMLwzwqXR2/6E4g 0uwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715587995; x=1716192795; 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=KjI2GIzbNeY5mYmEJBzlwq8aj+x1UHEKf/2QoRMS7Cs=; b=nBO7wJKgoUMxP/wWcdP/9twy6v8TpMuWQ15eIoXSeFJhs+Q8DjIsKq9P0UsdMS0bkh nMd8GSd3syaDCv7hfGOMn+XiqcygGSF2MU8bmFMBBrT/sYkplJSp/+ANGA3BMoclmC8r nZHsF46NNPmtGsVr9XjMu1DlbpJo1jEQJjYVFW1WYjL9m15vDW86MvVzAdSLsB362Pvs AYKKw9SZIFYFyCNXCh4wYNye77V4fwpxPpbVaRmhjMVJcduJu1jlEjpf6+W4SyfPij1O 7kwtYDgrV1Wq67vHaTV+04W01uVP+QVk6YpUG/JgaI1ICLT5wBgf2EqiU2FDhD36zExT dCiQ== X-Forwarded-Encrypted: i=1; AJvYcCWpiIMaSJgK1Vw86yEvbDMVvH8ExsqX4nKSCSW1RgBs3dgU3rNwoGhTL8sYZxMdhV8e/Hr5qOYvIC9KbEagEwxDlLqQMJunkHqaxKgx X-Gm-Message-State: AOJu0YzPKWCyaMtkSu51tsg0yofuVlOhvSl4b71abo47V3XILd7HhbDy bdarj6v1vcxHFUR6Ew0p/+TLJijw5VZ+nvWFo7xc3O0Qsze+AaqWFMgLNG5f/UY= X-Google-Smtp-Source: AGHT+IGTEXWrUQ7VGUcVeKG0+Ho7vHvmqvLjvCgT6L/7ToRERkrjvg7sB944hy/FRrFnxQ2sXbBaag== X-Received: by 2002:a05:600c:4fc9:b0:41c:1434:f571 with SMTP id 5b1f17b1804b1-41feac59deemr67598535e9.37.1715587994435; Mon, 13 May 2024 01:13:14 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:ac9:e686:c88b:6249:b2f4:9ae2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b8a77f8sm10399563f8f.54.2024.05.13.01.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:13:14 -0700 (PDT) From: Vincenzo Mezzela To: sudeep.holla@arm.com Cc: vincenzo.mezzela@gmail.com, gregkh@linuxfoundation.org, javier.carrasco.cruz@gmail.com, julia.lawall@inria.fr, linux-kernel@vger.kernel.org, rafael@kernel.org, skhan@linuxfoundation.org Subject: [PATCH 2/2 v4] drivers: arch_topology: use __free attribute instead of of_node_put() Date: Mon, 13 May 2024 10:13:04 +0200 Message-Id: <20240513081304.499915-3-vincenzo.mezzela@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240513081304.499915-1-vincenzo.mezzela@gmail.com> References: <20240501094313.407820-1-vincenzo.mezzela@gmail.com> <20240513081304.499915-1-vincenzo.mezzela@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the __free attribute for scope-based resource management. Resources allocated with __free are automatically released at the end of the scope. This enhancement aims to mitigate memory management issues associated with forgetting to release resources by utilizing __free instead of of_node_put(). The declaration of the device_node used within the do-while loops is moved directly within the loop so that the resource is automatically freed at the end of each iteration. Suggested-by: Julia Lawall Signed-off-by: Vincenzo Mezzela Acked-by: Sudeep Holla --- drivers/base/arch_topology.c | 56 +++++++++++++++++------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 0115011b7a99..93c9f0499694 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include @@ -513,10 +514,10 @@ core_initcall(free_raw_capacity); */ static int __init get_cpu_for_node(struct device_node *node) { - struct device_node *cpu_node; int cpu; + struct device_node *cpu_node __free(device_node) =3D + of_parse_phandle(node, "cpu", 0); =20 - cpu_node =3D of_parse_phandle(node, "cpu", 0); if (!cpu_node) return -1; =20 @@ -527,7 +528,6 @@ static int __init get_cpu_for_node(struct device_node *= node) pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n", cpu_node, cpumask_pr_args(cpu_possible_mask)); =20 - of_node_put(cpu_node); return cpu; } =20 @@ -538,11 +538,12 @@ static int __init parse_core(struct device_node *core= , int package_id, bool leaf =3D true; int i =3D 0; int cpu; - struct device_node *t; =20 do { snprintf(name, sizeof(name), "thread%d", i); - t =3D of_get_child_by_name(core, name); + struct device_node *t __free(device_node) =3D + of_get_child_by_name(core, name); + if (!t) break; =20 @@ -555,10 +556,8 @@ static int __init parse_core(struct device_node *core,= int package_id, cpu_topology[cpu].thread_id =3D i; } else if (cpu !=3D -ENODEV) { pr_err("%pOF: Can't get CPU for thread\n", t); - of_node_put(t); return -EINVAL; } - of_node_put(t); i++; } while (1); =20 @@ -587,7 +586,6 @@ static int __init parse_cluster(struct device_node *clu= ster, int package_id, char name[20]; bool leaf =3D true; bool has_cores =3D false; - struct device_node *c; int core_id =3D 0; int i, ret; =20 @@ -599,7 +597,9 @@ static int __init parse_cluster(struct device_node *clu= ster, int package_id, i =3D 0; do { snprintf(name, sizeof(name), "cluster%d", i); - c =3D of_get_child_by_name(cluster, name); + struct device_node *c __free(device_node) =3D + of_get_child_by_name(cluster, name); + if (!c) break; =20 @@ -607,7 +607,6 @@ static int __init parse_cluster(struct device_node *clu= ster, int package_id, ret =3D parse_cluster(c, package_id, i, depth + 1); if (depth > 0) pr_warn("Topology for clusters of clusters not yet supported\n"); - of_node_put(c); if (ret !=3D 0) return ret; i++; @@ -617,7 +616,9 @@ static int __init parse_cluster(struct device_node *clu= ster, int package_id, i =3D 0; do { snprintf(name, sizeof(name), "core%d", i); - c =3D of_get_child_by_name(cluster, name); + struct device_node *c __free(device_node) =3D + of_get_child_by_name(cluster, name); + if (!c) break; =20 @@ -625,21 +626,19 @@ static int __init parse_cluster(struct device_node *c= luster, int package_id, =20 if (depth =3D=3D 0) { pr_err("%pOF: cpu-map children should be clusters\n", c); - of_node_put(c); return -EINVAL; } =20 if (leaf) { ret =3D parse_core(c, package_id, cluster_id, core_id++); + if (ret !=3D 0) + return ret; } else { pr_err("%pOF: Non-leaf cluster with core %s\n", cluster, name); - ret =3D -EINVAL; + return -EINVAL; } =20 - of_node_put(c); - if (ret !=3D 0) - return ret; i++; } while (1); =20 @@ -652,19 +651,19 @@ static int __init parse_cluster(struct device_node *c= luster, int package_id, static int __init parse_socket(struct device_node *socket) { char name[20]; - struct device_node *c; bool has_socket =3D false; int package_id =3D 0, ret; =20 do { snprintf(name, sizeof(name), "socket%d", package_id); - c =3D of_get_child_by_name(socket, name); + struct device_node *c __free(device_node) =3D + of_get_child_by_name(socket, name); + if (!c) break; =20 has_socket =3D true; ret =3D parse_cluster(c, package_id, -1, 0); - of_node_put(c); if (ret !=3D 0) return ret; =20 @@ -679,11 +678,11 @@ static int __init parse_socket(struct device_node *so= cket) =20 static int __init parse_dt_topology(void) { - struct device_node *cn, *map; int ret =3D 0; int cpu; + struct device_node *cn __free(device_node) =3D + of_find_node_by_path("/cpus"); =20 - cn =3D of_find_node_by_path("/cpus"); if (!cn) { pr_err("No CPU information found in DT\n"); return 0; @@ -693,13 +692,15 @@ static int __init parse_dt_topology(void) * When topology is provided cpu-map is essentially a root * cluster with restricted subnodes. */ - map =3D of_get_child_by_name(cn, "cpu-map"); + struct device_node *map __free(device_node) =3D + of_get_child_by_name(cn, "cpu-map"); + if (!map) - goto out; + return ret; =20 ret =3D parse_socket(map); if (ret !=3D 0) - goto out_map; + return ret; =20 topology_normalize_cpu_scale(); =20 @@ -709,14 +710,9 @@ static int __init parse_dt_topology(void) */ for_each_possible_cpu(cpu) if (cpu_topology[cpu].package_id < 0) { - ret =3D -EINVAL; - break; + return -EINVAL; } =20 -out_map: - of_node_put(map); -out: - of_node_put(cn); return ret; } #endif --=20 2.34.1