From nobody Tue Sep 29 00:32:58 2026 Received: from mail-pz2-f0.google.com (mail-pz2-f0.google.com [74.125.228.0]) (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 3AD3944BC92 for ; Fri, 14 Aug 2026 08:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.0 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695303; cv=none; b=bk5x/hp07t1ySj6ZJY1/v91waWgyeWbBQ2MZj8UFokNEv1Ck/stbWUcZUY4utbGiqzHuhD2FGmQuD2jSvLvyBWxt+6a1QFAkhrZsaeKdJCd6A115N6vUe74N5RqdV6CFfIHbrIdoPtb38d89t9esRjOg4qTcyEctUaY3MWdq+1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695303; c=relaxed/simple; bh=rFFNpVYOrMT3Qp2yvuqi8mrntpoQOyo34lqRocpDQdw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=isAJd4qFI4J5dbxE2yGLWhmNPDDeoMXPGT3LNYRPGprbQan+9C9cQW18BfXZiVW7+BROfD+a+J72WVba6RXDYRpuU0Vm2W7S91U9V+U168zSyZR8u+qvldnn8/lEpvlYLO1gY6mWmyi+BL+bL8x9Dwx68niNCI1Ag0dX1iZL0q8= 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=hOkQEXn2; arc=none smtp.client-ip=74.125.228.0 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="hOkQEXn2" Received: by mail-pz2-f0.google.com with SMTP id 41be03b00d2f7-c96739a46acso352037a12.1 for ; Fri, 14 Aug 2026 01:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786695296; x=1787300096; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=0Dek3piBTzvrC20sVx/LLDc7oP2Vk+2MRJebwHoj0TY=; b=hOkQEXn2eJCIIKBnnfZLhAOBM5dMr4bOITz7gf+/4lYU8HXtj7wml792SrGUyvl9t2 K8Mbx6cnL76tKXSYTxwnEjN3/SdBS94PXwu5oUnN3lxe7Pjrds77Kq4UTQ/Y2MWOXd7J MJIJP6F9NjSLI2F/LTFAKWpVgm7zW735Whu4eLsXF/4g3Z2R2ZwQy21BK2yH4XlPOgB8 ZAFbNmknHJa1ONGyd6+ANd6dHRZOjxtmhx85Ryz10UP+OmMtO7PSgAygCQZfcykd7Kxk IoMSQxkeTj/lwakBn4DZ37zqnRAONj5wYs4vXkzGccp6sICzTlWQ+vvsmiDtJw8nvBPb 33Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786695296; x=1787300096; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=0Dek3piBTzvrC20sVx/LLDc7oP2Vk+2MRJebwHoj0TY=; b=c/lwG/MGKR3L1+KDPvtI2qLFl6ZT3kHtTCZwHl7o+Nyj1G9JCZb3jkuE/uSNp9YwPK o1kQFgtdql67OO+IYoHoBH4oPGz+pjCqlXDxOEjCieuuW+xz1RlrnDVt3/IqM8A5m2kV mfWIwnlpwEf/FFWoRcGQAbKQOLnMTxLQXtujHyx8dgBaufaEjMyY2WQ2/+E+KJEYJxHY w6VH7MXy2OKP5Tn1MbyvqBcu9X3/2mBKvWa/OhKHy4anlf41vQYNjd1pp0bATGRQy6VU RD1/e8cqTWtMsohFGGD15ctNujuCOxBfENGQ0OSAY7R+q/r2tofnr0pQvjigb+Zw9dDV TMbg== X-Forwarded-Encrypted: i=1; AHgh+RodPYtYTjrs9QQp/gd+67RpJNyHny0GBVKUUQHfO0qKGHqQ0o3ZmbjWvGNtzMY1KKNc7J1W8X9dumSbjUE=@vger.kernel.org X-Gm-Message-State: AOJu0YxT+tmZBh60RjCdqs1hltttkW57Lb0vL45srMPirlP1HeOIBg9p 46MH7bejbvvGWgjzA+cdo5pQsgOQKCPJH2bbNfX23Xwd3+Zlt3i1IQGd X-Gm-Gg: AR+sD13boQ/JY9gtLIctva8bkd0RRmS1qoicMXCSr9tpQAEnLE1QDUGpCjbilw2qp/i hsPeLI9lxD/CQvgQSOaURmKlYbwa9KVDevYDGSy9IKrkmFdpoLDk4gyqC0P6MssSoU4dK6d80P1 FAznApaGS1KArLMz5eIU77OCY/rAc5VrLdh2XIHXORhpLiAS7LtzGfUBHGn8wVtKXYCKXRrnHwN JQESuHA+qcokpnoTn/oWzBtmu4Qvw4ahtsi73+1RE0Q64wxwojXjGLIwq2klJarA4RA91QLPyI1 XmT/Qz7F163U6T7oW28HYnhwD/g8jUwPFmCCXVdJOsUQ2V/Ys5LMOtQ6q0PyLZ5UWJN8b5GF3L6 bY7WZApz3Kv5F47pKpOVIzG+I7bXrkfpC+wrjbZq9K/y+tE0ETFFa5+SO1032h4VpilhuLvHkdZ GCG5DNWJjPq7x42ewIKhEL6QyIFX8dBkEjF/Nz/wk+KtrJ0MiVBNeAuvtwGb71MPmt1WuMJSYPR W5CDwM80xU= X-Received: by 2002:a05:6a00:6c8f:b0:847:8449:2ba6 with SMTP id d2e1a72fcca58-84fddf90cc4mr4930621b3a.8.1786695296460; Fri, 14 Aug 2026 01:14:56 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8517cfeb39esm149986b3a.4.2026.08.14.01.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 01:14:55 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] of: reserved_mem: skip init for regions whose early reservation failed Date: Fri, 14 Aug 2026 16:14:41 +0800 Message-ID: <20260814081443.1061046-2-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260814081443.1061046-1-chenwandun1@gmail.com> References: <20260814081443.1061046-1-chenwandun1@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" From: Wandun Chen __reserved_mem_reserve_reg() discards the error from early_init_dt_reserve_memory() and returns 0 unconditionally, so the caller counts the node in total_reserved_mem_cnt and the late scan initializes it without checking whether the early reservation actually succeeded. A region whose reservation failed is then handed to a device assuming the memory is protected. Propagate the error so failed reservations are no longer counted, and record the failed nodes so fdt_scan_reserved_mem_late() can skip them. Recording the failed nodes explicitly is necessary because fdt_scan_reserved_mem_late() rescans the DT independently. It cannot tell from memblock whether early reservation succeeded. The failed-node array is bounded by MAX_RESERVED_REGIONS, the number of static regions is not bounded by it, so on overflow the extra nodes fall back to being initialized, which is the current behavior. Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory= regions are processed") Signed-off-by: Wandun Chen --- drivers/of/of_reserved_mem.c | 49 ++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 8c9d6395d6a3..f20747725de4 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -32,6 +32,19 @@ static struct reserved_mem *reserved_mem __refdata =3D r= eserved_mem_array; static int total_reserved_mem_cnt =3D MAX_RESERVED_REGIONS; static int reserved_mem_count; =20 +static int reserve_failed_nodes[MAX_RESERVED_REGIONS] __initdata; +static int reserve_failed_nodes_cnt __initdata; + +static bool __init reserved_mem_node_reserve_failed(int node) +{ + int i; + + for (i =3D 0; i < reserve_failed_nodes_cnt; i++) + if (reserve_failed_nodes[i] =3D=3D node) + return true; + return false; +} + static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t siz= e, phys_addr_t align, phys_addr_t start, phys_addr_t end, bool nomap, phys_addr_t *res_base) @@ -167,14 +180,19 @@ static int __init __reserved_mem_reserve_reg(unsigned= long node, base =3D b; size =3D s; =20 - if (size && early_init_dt_reserve_memory(base, size, nomap) =3D=3D 0) { - fdt_fixup_reserved_mem_node(node, base, size); - pr_debug("Reserved memory: reserved region for node '%s': base %pa, size= %lu MiB\n", - uname, &base, (unsigned long)(size / SZ_1M)); - } else { + if (!size) + return -EINVAL; + + err =3D early_init_dt_reserve_memory(base, size, nomap); + if (err) { pr_err("Reserved memory: failed to reserve memory for node '%s': base %p= a, size %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); + return err; } + + fdt_fixup_reserved_mem_node(node, base, size); + pr_debug("Reserved memory: reserved region for node '%s': base %pa, size = %lu MiB\n", + uname, &base, (unsigned long)(size / SZ_1M)); return 0; } =20 @@ -306,10 +324,14 @@ void __init fdt_scan_reserved_mem_late(void) base =3D b; size =3D s; =20 - if (size) { - uname =3D fdt_get_name(fdt, child, NULL); - fdt_init_reserved_mem_node(child, uname, base, size); - } + if (!size) + continue; + + if (reserved_mem_node_reserve_failed(child)) + continue; + + uname =3D fdt_get_name(fdt, child, NULL); + fdt_init_reserved_mem_node(child, uname, base, size); } =20 /* check for overlapping reserved regions */ @@ -357,8 +379,15 @@ int __init fdt_scan_reserved_mem(void) uname =3D fdt_get_name(fdt, child, NULL); =20 err =3D __reserved_mem_reserve_reg(child, uname); - if (!err) + if (!err) { count++; + } else if (err !=3D -ENOENT) { + if (reserve_failed_nodes_cnt < MAX_RESERVED_REGIONS) + reserve_failed_nodes[reserve_failed_nodes_cnt++] =3D child; + else + pr_err("too many failed regions, '%s' reservation failed\n", + uname); + } =20 /* * Save the nodes for the dynamically-placed regions --=20 2.43.0 From nobody Tue Sep 29 00:32:58 2026 Received: from mail-pz2-f1.google.com (mail-pz2-f1.google.com [74.125.228.1]) (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 73ED5442FBB for ; Fri, 14 Aug 2026 08:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695309; cv=none; b=r2VwzKL4R8NLh9rb8QjnOAKT9olxAWlpBCQmizXIV/QcyA6VhnFnhzAM3ygZrhT7FIyGxqFL7JwpAtoeKIm1IdWVnhr6kgXS8uqD75rSG3m4oGnPUg04LTyUyX4yoqYtj79OIk7kHXkx42E8VD01jP3EA0dJ+l1X6Cx3W+dN1Fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695309; c=relaxed/simple; bh=wotXsZluvcxyn6s2nKRlu6uhtEVLn0t+kaHmUzK7NDs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PDlRKYvhe/aPyPFWs4AxD9qnRZTO1vcY/tUG11OEZnwrrruoq0wAR1/b+iXMEvXsrHdPEMdXgNyY/ReXZ775rAtdo7vP99+sZ5Cy41lq9DMLkeyT3AXfkYb7/9Zqc/bz04SkLh7Wqz8blrWMQ6ywsj1eaQxf/KC2xHGejoftdSw= 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=Tfsz22an; arc=none smtp.client-ip=74.125.228.1 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="Tfsz22an" Received: by mail-pz2-f1.google.com with SMTP id 41be03b00d2f7-cbb818e57c9so290810a12.0 for ; Fri, 14 Aug 2026 01:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786695301; x=1787300101; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=9unLO4ZeP6CWngyT8QczSGq/LrcwFa5DIFx/EN1Kd3o=; b=Tfsz22anceE3TzFbF35fTeAcpBH2JhwzU4hKFxu+ruMPFEbTcGaUx0hqm8GnwI8b/Y EK4qoh+BF524bhfrtLgZ7vWDugkM5fO038m7FSHCXMawNHQEUUSriwQbBbN4oUbdrtYk Gjlx+luBbPmzw+fHgshIvy/sZax8qCLQmZp6AvT1S7R3Jze/hQHITXsXZKJa5B1IOeG/ F5FaNAeCXoXnRUOGPrWeuo4BvKmYUV+bf3AI4YgNA8XVssWVcmbieqEWQn+eS/mB5OHy nVccuf7KxR4tRVGaDBU1npRmP5d5EWxkZLjsr7ZIbbqZMcBZN4hD/s86tEWPQ1NSsshY f1Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786695301; x=1787300101; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=9unLO4ZeP6CWngyT8QczSGq/LrcwFa5DIFx/EN1Kd3o=; b=T8MNF1IG6j8fv1ggttN2Y76zPt9uTw9X+lKPDLOIEO95xc3mx25TuO+hRyMO/bkZ/0 aRCgSu6sFT8q2cDa4wlqK4m4OeE1xFexXzw5g6v9zDeKLJDxR9ZC9FUpVR2IrhHgN9rP 7m2ef98XCoRNFGyKgEbqgrPsDxVOSbLbXugI2QokbseQg0IWNOl46p4brrUqxui81Vyx 6E42JOZ17fCbUsEd37pK8wEaPV/doKxO6WePGTY519urd0M1wWCXZFeQTELN8BHdCK1V FoWzcM10A6FM67mSaldH+DWOsEOfECmY/1OeQ8WEkDdqzGWhdSBvVdZ0mLkL6fPI50LB WMMw== X-Forwarded-Encrypted: i=1; AHgh+Rov26hLfpTChazA8eOYLAREtQeD99+jDXguQJnm6r5Z7uqc7HcudrNGy3gZZRDlPP8jvtjwvC1f0GN8cRc=@vger.kernel.org X-Gm-Message-State: AOJu0YzbB38DUnjVQhccKCLcsodTb/dcHny6h8xWR/bsN8G11q4jQoRi zrbHTveIMOwigtNa/0MAuurhNd9jkLee43Pghxt+p4LAUbovqMSNxc5p+1ajyBCewq7hBg== X-Gm-Gg: AR+sD10cvebez0beMvxq7KoOpZAp9m7LtL4XasPHwZ2p68P9zP/ev3gGQk/GBadymfW ru0CjTcD2Am1JD534C9Q1ah8kdP+Iu6hX86m97aoNpW1+58oKYo7E2/nAQj5rIPtkZ374+c+tdp oUuoAIizLqd0jquqHmWk5EezTfNbK3i8DrqDiuZhFtqOPMrRyj2xU19YohlhUWU0VMGw8xs94RQ CbmTZmSLpwEME2dgkxrGeqmvPy5ZNuqLXOn/RWfU71WDWnnoIUsP5+tzsYNnkeG5kZ+vRzPieAm 2WVMHH3EAvB32OJkZ+b4BPv+iduI230eZ88Mu+mzrtcL8HdAfNkDyoL5irjpImsgPw994Z27MMk /2G4B/YOTafOfDo8N/gxj2uQFID3VmXWlKDoDFS7xXhqiYCuMY04L4oDp3kfqhmBikeAMrcIaLC 8rrywHdv9rE1QNZm+pMshPIpkzBPWMlYekSxUivgLMbguVGXAmC/59MyIKzsl5ru4AREiDpBRaK 41qWPg9tmA= X-Received: by 2002:a05:6a00:6c9d:b0:84f:dc19:b77d with SMTP id d2e1a72fcca58-84fddffa59amr4492658b3a.12.1786695300745; Fri, 14 Aug 2026 01:15:00 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8517cfeb39esm149986b3a.4.2026.08.14.01.14.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 01:14:59 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] of: reserved_mem: reject statically placed regions overlapping existing reservations Date: Fri, 14 Aug 2026 16:14:42 +0800 Message-ID: <20260814081443.1061046-3-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260814081443.1061046-1-chenwandun1@gmail.com> References: <20260814081443.1061046-1-chenwandun1@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" From: Wandun Chen memblock_reserve() permits overlapping reservations, so a statically placed region whose 'reg' overlaps an existing one is accepted. The overlapping memory may then be used by two regions concurrently, corrupting data; and if the region's driver init later fails, memblock_phys_free() returns the overlap to the buddy allocator, corrupting that memory. Reject the overlap up front. Dynamically allocated regions are unaffected, as they are allocated from free memory and so cannot overlap an existing reservation. Sashiko found this issue in [1]. Fixes: d0b8ed47e83a ("of: reserved_mem: fix reserve memory leak") Signed-off-by: Wandun Chen Link: https://lore.kernel.org/all/20260806100605.2C2C01F000E9@smtp.kernel.o= rg/ [1] --- drivers/of/of_reserved_mem.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index f20747725de4..67cb60616fc6 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -146,6 +146,15 @@ static int __init early_init_dt_reserve_memory(phys_ad= dr_t base, =20 return memblock_mark_nomap(base, size); } + + if (memblock_is_region_reserved(base, size)) { + phys_addr_t end =3D base + size; + + pr_err("Reserved memory: [%pa-%pa] overlaps an existing reservation, ign= oring\n", + &base, &end); + return -EBUSY; + } + return memblock_reserve(base, size); } =20 --=20 2.43.0 From nobody Tue Sep 29 00:32:58 2026 Received: from mail-pz2-f0.google.com (mail-pz2-f0.google.com [74.125.228.0]) (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 B50C844A708 for ; Fri, 14 Aug 2026 08:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.0 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695313; cv=none; b=qpGsJdJFbdHFDG2NjU7/h6LSwFrBrm7p1tbfk+Qeg7nwb2gPCbPCSDc+bCWeu36OaRi6usoRJ/FujEXd9eT9/DAByShwEUPvRmaVF0FlFhzzq50Q//7FKg6isIrArXQs1hkGjsjnkTzLp2Dqz1EDG0UhMALnW/sOiLpBFeQKjMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695313; c=relaxed/simple; bh=aSEEaJv/2lAIxCCuT2cdazWa/Ajc5fX3gFyJrjyqtKE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YOGoJ8Lzl02yx8ycfaMp8BUchk8yLW6xfIlX/DbLJ1N2KiectIvUllQZhozMtHggogi7AEjwa+9oej1QsHpoIIHCWwjLVMl5Xj07hC2drQDK3+jINjoUFLYlAaXVHdN1VFSavHENQx7KQciqsZIpkBta4z5ZVZM/OkMpTOQ4l5Y= 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=RORxvn8G; arc=none smtp.client-ip=74.125.228.0 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="RORxvn8G" Received: by mail-pz2-f0.google.com with SMTP id 41be03b00d2f7-ca24d39d8a4so390499a12.1 for ; Fri, 14 Aug 2026 01:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786695305; x=1787300105; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=wjrvAKO/KlFzs77oHO3Q4F1Bx7OPbaNI+ITdVO/CFaw=; b=RORxvn8GuCBDZPfrniy50aGi/B+SCFoMljXoPizKeBnsJVxzSlciXky2YVoNq9kmjj lc4kBEUtk+OPYB8DbUKTen2qyVTjOq4J14zBjtn1Ewb/BvG2eaWPnEIwVItrX+hVxhsH M4cTkg4lVccpPmJFNLOgK0eWd94MOabwyvWvPLZGuTlxvE0fmaWwD5ba8tHW7LK+MAZN QMoC/XYa3RPY9YGvZYNUy9aDNVVzmTJOPWwgUrcsUJq6tLchVdADk+e/GHTzYfXKMceT bmIq5rzQSnEcOBzmhrKs6mHNg9MdTfH87YuBTDXCR6eCoKaif7jj79Tg+xqWMGuCaoED 27gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786695305; x=1787300105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=wjrvAKO/KlFzs77oHO3Q4F1Bx7OPbaNI+ITdVO/CFaw=; b=LyxeMPc48mk7s35tUIws7/1p7x8rinzH9Xge5ZfEd7NTFGT/U+bUKvQkmFmayRgZxV v4GnqXKpPqG/bzkWTrfUlKdSaIAJT4l40vGVMQsKHjpz4Cr2JcnJiZsbn51fwq8fHBZF vLX/sfnZ+PzKnyBd/A76/BqM/ndIe0qELSMhgYAdqS1BRGyKhgMalsZfc9oIs8qSLp3Z 4j4QvU2CLZE+AB9/IdCOxlw7neCor8Gvd6M8QDuGhFttJi6V39/6CArLfa4c20EEBkMi LPpafC4S1L/+Cp04Q9uwtzYwz695lUvELgfT+U3rC4vFKaPxtf2cqGMZmlBbGAWEu2V6 zdfg== X-Forwarded-Encrypted: i=1; AHgh+RqvDUAGLwKd3XloTOAawzNj0lXRgw3gOphuRT65wKABVur3lBCvhUCSPxiIIGLDXYK+cmbEU2vz1zId3hk=@vger.kernel.org X-Gm-Message-State: AOJu0YzcSQ9et1RlKJ1noKYfnqwWIWjFTvCr6miM4uQLTlsZ/SEKREfn cC/ncVO8MOnMXY8i8yksh0lvoQ9pc2nqiCwUei4mMWes943zOKyWCJ8YELqTCxDYcha6Fw== X-Gm-Gg: AR+sD12IqM+4bJdKgxLWows+PIdbRyyGJkPe/w/IvNz0URRBELLWa1Nxhl0GkM7y6MJ pKalP2hpfo6rAGtPHDIwyPDFn3lVtJgzayBsuZFP4yGuDMFkAjECOQMr8T9HgobtiU6l1mksqek qRP+GVfoK19Bj0OcNXoK3vYLoElaRh35vDIkChnx4H5d4Jdv5k+MvBTgMGHsZTFKCuXZZviPcG/ RyoiTBbJMGauvMQGAHdllqAVbFJBWR+UqXD+dfUpPxXJ+wwXK3MKhkzG+4nYuTsnHZAwjHYRyvT yGQm1p5cX7tmEHlGfc8MeG9xJX6ukTQ4z6uf/1QfxzTTVmB7of5xKv5rGMF5+PPxAM0XYcQyMW7 8ONwcCmpcYqfDGfOriOM6yXGzVLA2bY4EWd3h6kHodgU6UeeoGHen/GUXmIkRum34qeUP8LNUOq vHCEUSq8q7fZLcC6co2WktZcJ5rVjfR8e6yj39sgFGslyevQqEMUBa5OdAp8gml1LMQ9GnhGVlO pEktDSlELc= X-Received: by 2002:a05:6a00:2e20:b0:83e:b443:965e with SMTP id d2e1a72fcca58-84fddfa8bddmr3868914b3a.3.1786695305262; Fri, 14 Aug 2026 01:15:05 -0700 (PDT) Received: from intel.company.local ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8517cfeb39esm149986b3a.4.2026.08.14.01.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 01:15:04 -0700 (PDT) From: Wandun Chen To: robh@kernel.org, saravanak@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] of: reserved_mem: release dynamically allocated no-map region on init failure Date: Fri, 14 Aug 2026 16:14:43 +0800 Message-ID: <20260814081443.1061046-4-chenwandun1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260814081443.1061046-1-chenwandun1@gmail.com> References: <20260814081443.1061046-1-chenwandun1@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" From: Wandun Chen Dynamically reserved-memory regions are added to memblock.reserved by memblock_phys_alloc_range() during __reserved_mem_alloc_size(). When a reserved-memory region's driver initialization fails, fdt_init_reserved_mem_node() cleans up the reservation. For no-map regions it only calls memblock_clear_nomap(), but leaves the entry in memblock.reserved untouched, so the memory is never returned to the buddy allocator. Fix it by freeing the region on init failure when it was dynamically allocated. Sashiko found this issue in [1]. Fixes: 7b25995f5319 ("of: of_reserved_mem: mark nomap memory instead of rem= oving") Signed-off-by: Wandun Chen Link: https://lore.kernel.org/all/20260806100605.2C2C01F000E9@smtp.kernel.o= rg/ [1] --- drivers/of/of_reserved_mem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 67cb60616fc6..d09c29184acf 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -125,7 +125,8 @@ static int __init alloc_reserved_mem_array(void) } =20 static void fdt_init_reserved_mem_node(unsigned long node, const char *una= me, - phys_addr_t base, phys_addr_t size); + phys_addr_t base, phys_addr_t size, + bool dynamic); static int fdt_validate_reserved_mem_node(unsigned long node, phys_addr_t *align); static int fdt_fixup_reserved_mem_node(unsigned long node, @@ -340,7 +341,7 @@ void __init fdt_scan_reserved_mem_late(void) continue; =20 uname =3D fdt_get_name(fdt, child, NULL); - fdt_init_reserved_mem_node(child, uname, base, size); + fdt_init_reserved_mem_node(child, uname, base, size, false); } =20 /* check for overlapping reserved regions */ @@ -556,7 +557,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam } =20 fdt_fixup_reserved_mem_node(node, base, size); - fdt_init_reserved_mem_node(node, uname, base, size); + fdt_init_reserved_mem_node(node, uname, base, size, true); =20 return 0; } @@ -671,7 +672,8 @@ static int __init __reserved_mem_init_node(struct reser= ved_mem *rmem, * reserved_mem array to allow of_reserved_mem_lookup() to find it. */ static void __init fdt_init_reserved_mem_node(unsigned long node, const ch= ar *uname, - phys_addr_t base, phys_addr_t size) + phys_addr_t base, phys_addr_t size, + bool dynamic) { int err =3D 0; bool nomap; @@ -697,7 +699,8 @@ static void __init fdt_init_reserved_mem_node(unsigned = long node, const char *un =20 if (nomap) memblock_clear_nomap(rmem->base, rmem->size); - else + + if (dynamic || !nomap) memblock_phys_free(rmem->base, rmem->size); return; } else { --=20 2.43.0