From nobody Sun Feb 8 09:10:48 2026 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 3FA662FB62A for ; Sat, 15 Nov 2025 13:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214599; cv=none; b=tV+iyXNyXsHLXUlTSU0n7P0efae3ac8ZuLY/AQbVZh7895rrFV97pL+9BOG5YpM1PaifUlKUqK9QGT7mvc/QEUBWIqvhQ+PqWLO3SiebzxCEW4sGyq7DzSvHUNNBYs6q5nHkHsI/KFD9ZvOWRol48pRH4lMbKWYMMcRADpr/fMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763214599; c=relaxed/simple; bh=K/Q+XUVIKKsLqxQRg9fWMCwmkkmfKYaeE5QXe1gNLgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pa0FV1FgjW1k2mkNesU0pJzw4A793Y8iIXjiYbtWHGdtuZskthpMTq3b+7P9lW5H4JdPcPaMPRU+OZUTbf8YEIRjf+GolCdPsQvY2IgGq387cM1AWKpgp6rxmLlxrt4PLOU/9GmHJGEw1v/tqZYn36e1Eny6K7LkffbfgKEkDo0= 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=Z2urmUtA; arc=none smtp.client-ip=91.218.175.184 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="Z2urmUtA" 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=1763214595; 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=5q3dAmTTGvh2D1uCjxlq4hOfI5Qlfk0JDHPgJGUEfUI=; b=Z2urmUtAbikyTUIdKpQ9l7gWq64hHiJbagbrB452bWnGar9uOK5cvtbkSvlqO8FaNTrM/d BraN3N0iPjS10oIp/qVCN7JjzDf/0OZhwszr2Rkdqy2saXhCfP0I/M4whlYeSH4hU8CdLM 9t8k6D1yj5TsK3SoSKIdpQ7zMXvQuMM= 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 8/8] of/reserved_mem: Simplify the logic of __reserved_mem_alloc_size() Date: Sat, 15 Nov 2025 21:47:53 +0800 Message-ID: <20251115134753.179931-9-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" Use the existing helper functions to simplify the logic of __reserved_mem_alloc_size() Signed-off-by: Yuntao Wang --- drivers/of/of_reserved_mem.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 0ceb096c17e6..5619ec917858 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -385,10 +385,9 @@ static int __init __reserved_mem_alloc_in_range(phys_a= ddr_t size, */ static int __init __reserved_mem_alloc_size(unsigned long node, const char= *uname) { - int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); phys_addr_t start =3D 0, end =3D 0; phys_addr_t base =3D 0, align =3D 0, size; - int len; + int i, len; const __be32 *prop; bool nomap; int ret; @@ -422,19 +421,15 @@ static int __init __reserved_mem_alloc_size(unsigned = long node, const char *unam && !nomap) align =3D max_t(phys_addr_t, align, CMA_MIN_ALIGNMENT_BYTES); =20 - prop =3D of_get_flat_dt_prop(node, "alloc-ranges", &len); + prop =3D of_flat_dt_get_addr_size_prop(node, "alloc-ranges", &len); if (prop) { + for (i =3D 0; i < len; i++) { + u64 b, s; =20 - if (len % t_len !=3D 0) { - pr_err("invalid alloc-ranges property in '%s', skipping node.\n", - uname); - return -EINVAL; - } + of_flat_dt_read_addr_size(prop, i, &b, &s); =20 - while (len > 0) { - start =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - end =3D start + dt_mem_next_cell(dt_root_size_cells, - &prop); + start =3D b; + end =3D b + s; =20 base =3D 0; ret =3D __reserved_mem_alloc_in_range(size, align, @@ -445,9 +440,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam (unsigned long)(size / SZ_1M)); break; } - len -=3D t_len; } - } else { ret =3D early_init_dt_alloc_reserved_memory_arch(size, align, 0, 0, nomap, &base); --=20 2.51.0