From nobody Sun Feb 8 06:05:37 2026 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 9481934572F for ; Thu, 13 Nov 2025 15:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049159; cv=none; b=Ig9u7JQueYUBQIda7zVF9yNCsiqzLDHNkfrBuUUhImDf9PGJGPAoNGb9gCcNtjkjYFxMge4BTdJHWok8WYug9XmTjmp+d2j8tVPzwcbOYDKWfdtOKIQOnlhbedEiF0liRaGXTixD4G8+O9g/uvJpU/sn8SnZlyGUWmOCZYIYq4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763049159; c=relaxed/simple; bh=7tr+1d/3tzMsJWc39iUs0JefrX9nWMAO5RdM4bye1Ho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uvbF9R/qrsxsj9u5DQl5CCJf6eT7lgVcLF5UDOTGScDQHRVKwucajbhURq9PRyWIqIddLQKlF2LbIGK3wkWWxx3L3W/SAGZM1z8dtkYIVcg5zU80b/FtI0rqE0Zc+OHxRLGK3grCm6WkkKHDMZMskpeLDCD1wnRm4HSKGWN+IkA= 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=OcD67eL2; arc=none smtp.client-ip=95.215.58.189 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="OcD67eL2" 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=1763049155; 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=0aseI6OseIhLle9z0TIJUXBxDfgB+PP1F776zvPg86w=; b=OcD67eL2D/fAb4UMXMVkT6oVR3dO6NqfPBh9x9n2VWLudSuJ8LJtILV8E1mVu1deFE5hkB 0e+gUUGEzz6JfQd493Rj5TfsMU70llFU8um92qpiSNYmCnjN4VGZUY27EQGjpOeSoI4Fhl +73bhc3zZ0xb0X5MykYdR3uU+h4O6Gw= 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 3/7] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Date: Thu, 13 Nov 2025 23:51:00 +0800 Message-ID: <20251113155104.226617-4-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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The len value is in bytes, while `dt_root_addr_cells + dt_root_size_cells` is in cells (4 bytes per cell). Modulo calculation between them is incorrect, the units must be converted first. Use helper functions to simplify the code and fix this issue. Fixes: fb319e77a0e7 ("of: fdt: Add memory for devices by DT property "linux= ,usable-memory-range"") Fixes: 2af2b50acf9b9c38 ("of: fdt: Add generic support for handling usable = memory range property") Fixes: 8f579b1c4e347b23 ("arm64: limit memory regions based on DT property,= usable-memory-range") Signed-off-by: Yuntao Wang --- drivers/of/fdt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 80b7236efdc6..d0caaab42aa7 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -884,7 +884,7 @@ static unsigned long chosen_node_offset =3D -FDT_ERR_NO= TFOUND; void __init early_init_dt_check_for_usable_mem_range(void) { struct memblock_region rgn[MAX_USABLE_RANGES] =3D {0}; - const __be32 *prop, *endp; + const __be32 *prop; int len, i; unsigned long node =3D chosen_node_offset; =20 @@ -893,14 +893,14 @@ void __init early_init_dt_check_for_usable_mem_range(= void) =20 pr_debug("Looking for usable-memory-range property... "); =20 - prop =3D of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); - if (!prop || (len % (dt_root_addr_cells + dt_root_size_cells))) + prop =3D of_fdt_get_addr_size_prop(node, "linux,usable-memory-range", &le= n); + if (!prop) return; =20 - endp =3D prop + (len / sizeof(__be32)); - for (i =3D 0; i < MAX_USABLE_RANGES && prop < endp; i++) { - rgn[i].base =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - rgn[i].size =3D dt_mem_next_cell(dt_root_size_cells, &prop); + len =3D min(len, MAX_USABLE_RANGES); + + for (i =3D 0; i < len; i++) { + of_fdt_read_addr_size(prop, &rgn[i].base, &rgn[i].size); =20 pr_debug("cap_mem_regions[%d]: base=3D%pa, size=3D%pa\n", i, &rgn[i].base, &rgn[i].size); --=20 2.51.0