Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] treewide: remove unnecessary invalid range checks in memblock iteration loops
@ 2026-06-21 14:59 Sang-Heon Jeon
  2026-06-21 14:59 ` [PATCH 3/6] riscv: remove unreachable invalid range check in create_linear_mapping_page_table() Sang-Heon Jeon
  2026-06-21 14:59 ` [PATCH 4/6] riscv: remove unreachable invalid range check in kasan_init() Sang-Heon Jeon
  0 siblings, 2 replies; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-06-21 14:59 UTC (permalink / raw)
  To: Albert Ou, Andrew Morton, Andrey Ryabinin, Catalin Marinas,
	Huacai Chen, Mike Rapoport, Muchun Song, Oscar Salvador,
	Palmer Dabbelt, Paul Walmsley, Will Deacon
  Cc: Sang-Heon Jeon, Alexander Potapenko, Alexandre Ghiti,
	Andrey Konovalov, David Hildenbrand, Dmitry Vyukov, kasan-dev,
	linux-arm-kernel, linux-mm, linux-riscv, loongarch,
	Vincenzo Frascino, WANG Xuerui

The memblock API guarantees that for_each_mem_range() and
for_each_mem_pfn_range() never return an invalid range, meaning start is
always less than end.

Several memblock callers still have unnecessary invalid range checks in
their loop bodies, so remove them.

Patches 1-4 cover for_each_mem_range() callers. memblock never stores a
zero-size region, so the range it returns always has start < end. Some
callers apply __va() or __phys_to_virt() before comparing, but these keep
start < end too, so the check is unreachable.

Patches 5-6 cover for_each_mem_pfn_range() callers. __next_mem_pfn_range()
skips any region that contains no whole page, so it only ever returns
start_pfn < end_pfn and the check is unnecessary.

For reference, commit 36ca7f4be809 ("arm64: mm: Remove bogus stop
condition from map_mem() loop") did a similar cleanup in arm64 map_mem().

All these checks are in different trees, so I split the change into one
patch per arch/subsystem. The patches are independent and can be applied
separately.

Sang-Heon Jeon (6):
  arm64: mm: remove unreachable invalid range check in
    kasan_init_shadow()
  LoongArch: remove unreachable invalid range check in kasan_init()
  riscv: remove unreachable invalid range check in
    create_linear_mapping_page_table()
  riscv: remove unreachable invalid range check in kasan_init()
  mm: remove unnecessary empty range check in
    early_calculate_totalpages()
  mm/hugetlb: remove unnecessary empty range check in
    hugetlb_bootmem_set_nodes()

 arch/arm64/mm/kasan_init.c     | 3 ---
 arch/loongarch/mm/kasan_init.c | 3 ---
 arch/riscv/mm/init.c           | 2 --
 arch/riscv/mm/kasan_init.c     | 3 ---
 mm/hugetlb.c                   | 3 +--
 mm/mm_init.c                   | 3 +--
 6 files changed, 2 insertions(+), 15 deletions(-)

-- 
2.43.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/6] riscv: remove unreachable invalid range check in create_linear_mapping_page_table()
  2026-06-21 14:59 [PATCH 0/6] treewide: remove unnecessary invalid range checks in memblock iteration loops Sang-Heon Jeon
@ 2026-06-21 14:59 ` Sang-Heon Jeon
  2026-06-22  5:10   ` Charlie Jenkins
  2026-06-21 14:59 ` [PATCH 4/6] riscv: remove unreachable invalid range check in kasan_init() Sang-Heon Jeon
  1 sibling, 1 reply; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-06-21 14:59 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: Sang-Heon Jeon, Alexandre Ghiti, linux-riscv

create_linear_mapping_page_table() iterates memblock regions with
for_each_mem_range() and breaks the loop when start >= end.
for_each_mem_range() never returns an invalid range, so start < end always.

Therefore the start >= end check is unreachable, so remove it.

No functional change.

Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
 arch/riscv/mm/init.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 5b1b3c88b4d1..eb93c2ac05a6 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -1229,8 +1229,6 @@ static void __init create_linear_mapping_page_table(void)
 
 	/* Map all memory banks in the linear mapping */
 	for_each_mem_range(i, &start, &end) {
-		if (start >= end)
-			break;
 		if (start <= __pa(PAGE_OFFSET) &&
 		    __pa(PAGE_OFFSET) < end)
 			start = __pa(PAGE_OFFSET);
-- 
2.43.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/6] riscv: remove unreachable invalid range check in kasan_init()
  2026-06-21 14:59 [PATCH 0/6] treewide: remove unnecessary invalid range checks in memblock iteration loops Sang-Heon Jeon
  2026-06-21 14:59 ` [PATCH 3/6] riscv: remove unreachable invalid range check in create_linear_mapping_page_table() Sang-Heon Jeon
@ 2026-06-21 14:59 ` Sang-Heon Jeon
  2026-06-22  5:11   ` Charlie Jenkins
  1 sibling, 1 reply; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-06-21 14:59 UTC (permalink / raw)
  To: Andrey Ryabinin, Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: Sang-Heon Jeon, Alexander Potapenko, Alexandre Ghiti,
	Andrey Konovalov, Dmitry Vyukov, kasan-dev, linux-riscv,
	Vincenzo Frascino

kasan_init() populates the linear mapping shadow with for_each_mem_range()
and breaks the loop when start >= end. for_each_mem_range() never returns
an invalid range, so start < end always.

Therefore the start >= end check is unreachable, so remove it.

No functional change.

Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
 arch/riscv/mm/kasan_init.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
index c4a2a9e5586e..1f3aa9611187 100644
--- a/arch/riscv/mm/kasan_init.c
+++ b/arch/riscv/mm/kasan_init.c
@@ -512,9 +512,6 @@ void __init kasan_init(void)
 		void *start = (void *)__va(p_start);
 		void *end = (void *)__va(p_end);
 
-		if (start >= end)
-			break;
-
 		kasan_populate(kasan_mem_to_shadow(start), kasan_mem_to_shadow(end));
 	}
 
-- 
2.43.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/6] riscv: remove unreachable invalid range check in create_linear_mapping_page_table()
  2026-06-21 14:59 ` [PATCH 3/6] riscv: remove unreachable invalid range check in create_linear_mapping_page_table() Sang-Heon Jeon
@ 2026-06-22  5:10   ` Charlie Jenkins
  0 siblings, 0 replies; 5+ messages in thread
From: Charlie Jenkins @ 2026-06-22  5:10 UTC (permalink / raw)
  To: Sang-Heon Jeon
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	linux-riscv

On Sun, Jun 21, 2026 at 11:59:13PM +0900, Sang-Heon Jeon wrote:
> create_linear_mapping_page_table() iterates memblock regions with
> for_each_mem_range() and breaks the loop when start >= end.
> for_each_mem_range() never returns an invalid range, so start < end always.
> 
> Therefore the start >= end check is unreachable, so remove it.
> 
> No functional change.
> 
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>

Reviewed-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Tested-by: Charlie Jenkins <thecharlesjenkins@gmail.com>

> ---
>  arch/riscv/mm/init.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 5b1b3c88b4d1..eb93c2ac05a6 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -1229,8 +1229,6 @@ static void __init create_linear_mapping_page_table(void)
>  
>  	/* Map all memory banks in the linear mapping */
>  	for_each_mem_range(i, &start, &end) {
> -		if (start >= end)
> -			break;
>  		if (start <= __pa(PAGE_OFFSET) &&
>  		    __pa(PAGE_OFFSET) < end)
>  			start = __pa(PAGE_OFFSET);
> -- 
> 2.43.0
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/6] riscv: remove unreachable invalid range check in kasan_init()
  2026-06-21 14:59 ` [PATCH 4/6] riscv: remove unreachable invalid range check in kasan_init() Sang-Heon Jeon
@ 2026-06-22  5:11   ` Charlie Jenkins
  0 siblings, 0 replies; 5+ messages in thread
From: Charlie Jenkins @ 2026-06-22  5:11 UTC (permalink / raw)
  To: Sang-Heon Jeon
  Cc: Andrey Ryabinin, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexander Potapenko, Alexandre Ghiti, Andrey Konovalov,
	Dmitry Vyukov, kasan-dev, linux-riscv, Vincenzo Frascino

On Sun, Jun 21, 2026 at 11:59:14PM +0900, Sang-Heon Jeon wrote:
> kasan_init() populates the linear mapping shadow with for_each_mem_range()
> and breaks the loop when start >= end. for_each_mem_range() never returns
> an invalid range, so start < end always.
> 
> Therefore the start >= end check is unreachable, so remove it.
> 
> No functional change.
> 
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>

Reviewed-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Tested-by: Charlie Jenkins <thecharlesjenkins@gmail.com>

> ---
>  arch/riscv/mm/kasan_init.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
> index c4a2a9e5586e..1f3aa9611187 100644
> --- a/arch/riscv/mm/kasan_init.c
> +++ b/arch/riscv/mm/kasan_init.c
> @@ -512,9 +512,6 @@ void __init kasan_init(void)
>  		void *start = (void *)__va(p_start);
>  		void *end = (void *)__va(p_end);
>  
> -		if (start >= end)
> -			break;
> -
>  		kasan_populate(kasan_mem_to_shadow(start), kasan_mem_to_shadow(end));
>  	}
>  
> -- 
> 2.43.0
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-22  5:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-21 14:59 [PATCH 0/6] treewide: remove unnecessary invalid range checks in memblock iteration loops Sang-Heon Jeon
2026-06-21 14:59 ` [PATCH 3/6] riscv: remove unreachable invalid range check in create_linear_mapping_page_table() Sang-Heon Jeon
2026-06-22  5:10   ` Charlie Jenkins
2026-06-21 14:59 ` [PATCH 4/6] riscv: remove unreachable invalid range check in kasan_init() Sang-Heon Jeon
2026-06-22  5:11   ` Charlie Jenkins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox