From nobody Sun Feb 8 08:22:31 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 6A7D82D739D for ; Sat, 15 Nov 2025 13:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214549; cv=none; b=qI03bGWLWlIoeoLhHGGTKvbCXk7SFIrB1kWuTUl+CLRslId0MZqBFjvXOJW2uo0pLQ1NFy1U7PcQ5Wajyp6vUrE5uMb9WsuNE9zkC8YeTYdONAPgjph3vyycbRI9DOZqTKCnNaubqQN+kq+KU5AEou9k9e6KvcrhjeFBwU42RBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214549; c=relaxed/simple; bh=ZZ/upw8nKT7v3jsEgzyAA289KSD3Fq5t653Jcf0SpvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H7IEIZ5ufsNZFEiwNdwuPPBVwJ6g+DGxrkrbcLEBaf0kQoUwozEQMUbQLZbOZZCz7akHATQBs99Ci4PVfMxIzjO3NsPHIZHEa0G03gbkLHCsIMoLtsxbZOihkACjc/HAinBIwONl1ZDiZqVf3ZW+DE8WnALmI2oALm0EH1zaCEQ= 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=jGf/YTvc; arc=none smtp.client-ip=91.218.175.179 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="jGf/YTvc" 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=1763214544; 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=MY3v9cZNblUfD57tnTGju+AQf3Z40adow3kyHkwe/ps=; b=jGf/YTvccMn+mePMIqYv83allCJeKFRkEl95R/ptEoo346OizqpUg/IYbFQ4ykZr15UqCQ ZgcqPNY7AlaexiblLDEJc/ZUFrQJuC40h0pXaMuvbcq0wTL78nrIeNPGNIIEuBeLUQ1Z+k zF4v/CEHn/NU9jlbu9cXMa5yu0+5oME= 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 v3 3/8] of/fdt: Fix the len check in early_init_dt_check_for_usable_mem_range() Date: Sat, 15 Nov 2025 21:47:48 +0800 Message-ID: <20251115134753.179931-4-yuntao.wang@linux.dev> In-Reply-To: <20251115134753.179931-1-yuntao.wang@linux.dev> References: <20251115134753.179931-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 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index b45f60dccd7c..ea37ba694bcd 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -884,8 +884,9 @@ 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; + u64 base, size; unsigned long node =3D chosen_node_offset; =20 if ((long)node < 0) @@ -893,14 +894,17 @@ 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_flat_dt_get_addr_size_prop(node, "linux,usable-memory-range", + &len); + 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_flat_dt_read_addr_size(prop, i, &base, &size); + rgn[i].base =3D base; + rgn[i].size =3D 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