From nobody Tue Feb 10 01:59:20 2026 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 9606A19007A for ; Fri, 7 Jun 2024 16:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717778039; cv=none; b=JD19MlMzDxyFsVvveA/3UGGGrIKfEkWrKqlmHdoSLk4wnM8I0Oy/qxiiwn+PIdSqccePRucT/B1iJtGo85Goj4W9DrIEya9CY+smDZEtNU2NySLFtG16VNpsicmW0K8vzGNMJHj2EEA/Q+ZRysrb8jZ1UogWNHJiZzsO1dY8tTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717778039; c=relaxed/simple; bh=BNC1Z95f8uiQ8K8aPXBGm6Vdmian+P1RGAxtQhFOi80=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PMO5wUStQ7yQ+Gy8IJLygYxSZnnma1XEwOio9hKm3BT/lX8ltaspgrNbqC8Dt5Lud/v2uMhtdEuQqDEPq4zH8xcpO5lacFI8Qb++Bq/3cdIHXGDkpfkiPGrVMbVfjJDeVY7E7IT5R73/3AytVp9u3AQL8rssBsQ7iLn6tnsdTG4= 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=nhb/g4TH; arc=none smtp.client-ip=209.85.208.177 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="nhb/g4TH" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2eaa80cb573so26993541fa.1 for ; Fri, 07 Jun 2024 09:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717778036; x=1718382836; 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=Ktuw6zxI+M+O56fZozxk8JtRul2b0L3ekJGX5mYuYns=; b=nhb/g4THEEwG08LYa6YucV78tVjnA3PhXnDHqT+TTcX+DRo2gcYm5Kl0NQlNemRP0S f+yR6+tp/ZZFgOzK4gM7ieOAYnPuBj+3NwEFt7TFnFEDaGWbw/RgZe5BxNdrWbwiQDf+ MSRnEGVGd+BhSdYKhlMX3uI78bM9GQRie9DLXAL8KBl2uQBcSYGWQIbNVp/KlnAQXss+ mDPnhF9Ggv5j/lmXBOPwfGvZnL4V6jQZlAAR4TH6I0V3UhuoZ5bHcHPRkE/Bh8IKTEYs jSa6f0fPAgU4B5TIiAtMLPZSIZjReTU4a2CYNL+2eiyKEhNP+2x/PVArbk+MYozUqptI pzyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717778036; x=1718382836; 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=Ktuw6zxI+M+O56fZozxk8JtRul2b0L3ekJGX5mYuYns=; b=bST3xy1pSb7v6y2oR8wTJAja+ubNRXuAuyRsOy9eSeApnTishf9n1sIHFZ4PCPSn1V R32uddmcUSTF6S1dfiIDXs4pfy7zL3pZrobvAKuddGL4F3nAi0s2YXXb/g83jHXf2i7B esr/HTwTq+HvxbEW7ilv/LtkKZrxWoXkDkp2dqZa0nRocKIdduMmsLCPAecZ8a7BfX42 l7HZ2cpON1LPvBKo/mgLWmbd+wa9VRbLknLBUaguFa++gWWWJFPga0eXS5467HVYbwcL 8jYJoDG0enimr8CL7eziUhiXYspeDFJuK/uDIYpcrsxSHkGsNbZcTdjQEyUZnuDPPsL+ aefQ== X-Forwarded-Encrypted: i=1; AJvYcCV5lgnmOcE2rkOTdHiMro6BCbOGNoXYFj+FT4Xz+BMIRO920Hk2oEViv5KS/885W8ZuX5ZMrBGQkTcb+l7YTw8f5WKL6vnbAom2jrZ5 X-Gm-Message-State: AOJu0YyVA2PJXx92YUiv4WZKCM0FMl46/OX7ERaWGO82gL+gGhdQ+J0o KOsBEOt21mRP20ryO6sZhnJL8rmvnJ47tWwZTti3+lkWmv+UPYug X-Google-Smtp-Source: AGHT+IEOYrqwvr0uEqyvOCJYjOz3auyroh/ag3BaxTAiF5HPtxeqBq73ZOyZ01c275WEGA5c+e21lA== X-Received: by 2002:a2e:a443:0:b0:2e9:768a:12ae with SMTP id 38308e7fff4ca-2eadce33be3mr19533271fa.22.1717778035376; Fri, 07 Jun 2024 09:33:55 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:ac9:e686:17a2:25c2:1b0c:3c07]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57aae0cc355sm3032715a12.33.2024.06.07.09.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 09:33:54 -0700 (PDT) From: Vincenzo Mezzela To: gregkh@linuxfoundation.org, rafael@kernel.org, sudeep.holla@arm.com Cc: vincenzo.mezzela@gmail.com, javier.carrasco.cruz@gmail.com, julia.lawall@inria.fr, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org Subject: [PATCH 1/2 v4 RESEND] drivers: arch_topology: Refactor do-while loops Date: Fri, 7 Jun 2024 18:33:49 +0200 Message-Id: <20240607163350.392971-2-vincenzo.mezzela@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607163350.392971-1-vincenzo.mezzela@gmail.com> References: <20240607163350.392971-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. Acked-by: Sudeep Holla Signed-off-by: Vincenzo Mezzela --- 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 c66d070207a0..583f11bd4d2e 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 01:59:20 2026 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.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 8564F19B3F6 for ; Fri, 7 Jun 2024 16:33:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717778040; cv=none; b=q9uFdwEALrO29lna/8UP6BWbxRfZMLKSihbsIIZfXEQmy0zaJvpycAz+6EzodLS05M6CF4IjHdif+Z/AQax2jnABqNgblkzbK0Vg51qiwGPpZViztNEgh+SVJdgQdSz3iDr0RlbYI+CrPR71eQUnt3I8NDM4MlvWbpJk6FpXXww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717778040; c=relaxed/simple; bh=Rw/yQU4SQECgSFkVagrrG+DKRyohNhv3ZOmdBmgXr5U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NiPLrItnNskZYjeDlfep9xhhuR44yYyoVTox5IVyBrZ4F+5K3iOcijSkJNBW4X/FJxpe38jbf/RqvxXziHV8JygpyB869x+FJfC5Ib2Q1q9WPwcRFGIXEG2knnEy6rFtSzAgFZg9TpwT6ZWVFp9s03raMS2cMmBcaAFHpvl2KHM= 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=NbVK9Q/t; arc=none smtp.client-ip=209.85.208.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="NbVK9Q/t" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-57a2f032007so2967699a12.0 for ; Fri, 07 Jun 2024 09:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717778037; x=1718382837; 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=UUlrcyXqHPisdOR1gYbfhNfAfonQ36aa9TUXeHIP7cM=; b=NbVK9Q/txkqfBV24f582PRvun2A+9OLUKzY9lFF57KVYplWbin0+NwuG7EcdAvAxYZ XJyIYjiGITMg2XVvAa3U5G9PDBsfAt+0EcR/3KxlAi6FRBg5bdDNc74YvC5CqkvATs/s aoaJkudOjp+uC1p/X41dgaw53ZH+VB24p2hbWf4rbQe6TLC71m3DpjxcQlzwlHNEnU7p hK7vKHhpht7oI/kk5SV9lJnMjc7sdSVWmhcc0RJGqpM04FDMD4Euhbpf4+jjI7Sa20Bj f2UmrtD1pwDCD4SjNaJhQwwOyRfWcZbgAQzfDdIPVYZUEr1f974xhHSGZSYH/RH1if1D NK9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717778037; x=1718382837; 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=UUlrcyXqHPisdOR1gYbfhNfAfonQ36aa9TUXeHIP7cM=; b=i5EFEjGSKbZSNbCb2TQi9FpLSuvxaxTgDoR10ylC1nocsUm0+/DAr9Bf/8mEKzykw+ zxWxHNep+/sQbLw2LK+W7daEgimzeMhb9Wi+pg6n3DLhGZUx/xFKyWVXJv7rAU9NPjzG ZtrPvzxXLU5Gr+Gl7Heyk6ouM4RxtlmCQ0zRQVrsN8ePgsN/idNQalllBUyLG/904DhG rM9ZJqmZF8Oergkzlo3+MN/pjEVtht78nq64IKgguyscC+yc5SepaY0d3K5hZP3Ccj7h jVHD6/ce+7aH4ph0G30CWQI1FjOiB7guwWyRhqI1IwGHK3WIRNDwwPybtPDiTGzly1Yc eYtA== X-Forwarded-Encrypted: i=1; AJvYcCXPTDsfBPtdSaa+dsSA+KwsZClG/i3/t1SUrau6q/YklgiwWJy9YwFRLBYfP+TLI8rw/eL+5jv0BkObkS8cDDxlIv21W35Qrucs+oaE X-Gm-Message-State: AOJu0YzcvyS/NMrnWBLB/VTY+ienlRW5A37YfOnQ2Ofv+8abpZSn1yfR 4mb5GORKLn3ZwYL3CdZe0nJytb7MNCGJ2m17XqFwCA6SxPffNALt X-Google-Smtp-Source: AGHT+IGR9NKO5efJ0RzKvH1rbvh2TMToeq9ABS5xgp1TI7WnqoMrkOMUR2oOQc3zd8Ub4Qy47Q+OZQ== X-Received: by 2002:a50:bb49:0:b0:57a:2f68:fe7b with SMTP id 4fb4d7f45d1cf-57c509898c8mr1935409a12.31.1717778036833; Fri, 07 Jun 2024 09:33:56 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:ac9:e686:17a2:25c2:1b0c:3c07]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57aae0cc355sm3032715a12.33.2024.06.07.09.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 09:33:56 -0700 (PDT) From: Vincenzo Mezzela To: gregkh@linuxfoundation.org, rafael@kernel.org, sudeep.holla@arm.com Cc: vincenzo.mezzela@gmail.com, javier.carrasco.cruz@gmail.com, julia.lawall@inria.fr, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org Subject: [PATCH 2/2 v4 RESEND] drivers: arch_topology: use __free attribute instead of of_node_put() Date: Fri, 7 Jun 2024 18:33:50 +0200 Message-Id: <20240607163350.392971-3-vincenzo.mezzela@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607163350.392971-1-vincenzo.mezzela@gmail.com> References: <20240607163350.392971-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. Acked-by: Sudeep Holla Suggested-by: Julia Lawall Signed-off-by: Vincenzo Mezzela --- 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 583f11bd4d2e..75fcb75d5515 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