From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1C6035503E for ; Thu, 13 Nov 2025 15:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049177; cv=none; b=KWRqJkErsMSzdC+Zmvrz0mZ8RO2haBQKPvUKvfaHPrYDcGb7IYrI6c3kcUk1fbxtLIygZ4KsG11UFIZSW0jRrFBBu0BpIt3Tp3C6HCvZIEyQmEokYq3kQy5yDRvJ9gn1l0QNkliWEdVcf86wPk78+9FUKf8kMIcY7rzBsbsxioo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049177; c=relaxed/simple; bh=fXl+mXM/AgH4+gWKzqK1XQgPchHG6fLIdy11kWGVzq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AkjWZJYNW7394OjtS9o1fZ8AXFO1lM0Y2MK7XLC3j0YgwwQq/KT0YgUNCC7Vu91aWUIov6NqiuOjmRBWpGZdVTRJIy0ZlFoSk4GEJla2A/wSEl7VzqlLaRgJp22v8+x8MLOfI3TOZvAteJz0C4WwVCgWvl3zzapGgqZM/hbWOnY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=U7z4KQXq; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="U7z4KQXq" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763049173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J9UNF6c7GepepH7wr+REukLkpUqCyIFHcXGXKzxLcbU=; b=U7z4KQXqc+YTUJVB7A/GcWVkKVsCw933NyXN+fw7bGYJIyvMts5CS5KtYXgsDci7ks2c7J BqfrkfTGc04oNJotEh9zzUT7ZWE3B9zgcFzd5JfSquhW6UZpopo2dTBATR+VW95vQGACLw 7A9LN0zKX7fFzlKjUrdaCoebdukPCQo= From: Yuntao Wang To: Rob Herring , Saravana Kannan Cc: Geert Uytterhoeven , Catalin Marinas , James Morse , Baoquan He , Zhen Lei , Ard Biesheuvel , Mark Rutland , Geoff Levand , Andrew Morton , Changyuan Lyu , Alexander Graf , "Mike Rapoport (Microsoft)" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH v2 5/7] of/fdt: Simplify the logic of early_init_dt_scan_memory() Date: Thu, 13 Nov 2025 23:51:02 +0800 Message-ID: <20251113155104.226617-6-yuntao.wang@linux.dev> In-Reply-To: <20251113155104.226617-1-yuntao.wang@linux.dev> References: <20251113155104.226617-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Use the existing helper functions to simplify the logic of early_init_dt_scan_memory() Signed-off-by: Yuntao Wang --- drivers/of/fdt.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 4c45a97d6652..b6b059960fc2 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1027,7 +1027,7 @@ int __init early_init_dt_scan_memory(void) fdt_for_each_subnode(node, fdt, 0) { const char *type = of_get_flat_dt_prop(node, "device_type", NULL); - const __be32 *reg, *endp; + const __be32 *reg; int l; bool hotpluggable; @@ -1038,23 +1038,21 @@ int __init early_init_dt_scan_memory(void) if (!of_fdt_device_is_available(fdt, node)) continue; - reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); + reg = of_fdt_get_addr_size_prop(node, "linux,usable-memory", &l); if (reg == NULL) - reg = of_get_flat_dt_prop(node, "reg", &l); + reg = of_fdt_get_addr_size_prop(node, "reg", &l); if (reg == NULL) continue; - endp = reg + (l / sizeof(__be32)); hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL); - pr_debug("memory scan node %s, reg size %d,\n", + pr_debug("memory scan node %s, reg {addr,size} entries %d,\n", fdt_get_name(fdt, node, NULL), l); - while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { + while (l-- > 0) { u64 base, size; - base = dt_mem_next_cell(dt_root_addr_cells, ®); - size = dt_mem_next_cell(dt_root_size_cells, ®); + of_fdt_read_addr_size(reg, &base, &size); if (size == 0) continue; -- 2.51.0