[PATCH] arm64: hugetlbpage: avoid unused-but-set-parameter warning (gcc-16)

Arnd Bergmann posted 1 patch 3 days, 22 hours ago
arch/arm64/mm/hugetlbpage.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] arm64: hugetlbpage: avoid unused-but-set-parameter warning (gcc-16)
Posted by Arnd Bergmann 3 days, 22 hours ago
From: Arnd Bergmann <arnd@arndb.de>

gcc-16 warns about an instance that older compilers did not:

arch/arm64/mm/hugetlbpage.c: In function 'huge_pte_clear':
arch/arm64/mm/hugetlbpage.c:369:57: error: parameter 'addr' set but not used [-Werror=unused-but-set-parameter=]

The issue here is that __pte_clear() does not actually use its second
argument when CONFIG_ARM64_CONTPTE is disabled.

Reword this to compute the offset each time instead of updating the
argument variable. I checked that the resulting object code is
unchanged.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/arm64/mm/hugetlbpage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index a42c05cf5640..4ad7662e8323 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -374,8 +374,8 @@ void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 
 	ncontig = num_contig_ptes(sz, &pgsize);
 
-	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
-		__pte_clear(mm, addr, ptep);
+	for (i = 0; i < ncontig; i++, ptep++)
+		__pte_clear(mm, addr + pgsize*i, ptep);
 }
 
 pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
-- 
2.39.5
Re: [PATCH] arm64: hugetlbpage: avoid unused-but-set-parameter warning (gcc-16)
Posted by Catalin Marinas 3 days, 20 hours ago
On Tue, Feb 03, 2026 at 05:21:23PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc-16 warns about an instance that older compilers did not:
> 
> arch/arm64/mm/hugetlbpage.c: In function 'huge_pte_clear':
> arch/arm64/mm/hugetlbpage.c:369:57: error: parameter 'addr' set but not used [-Werror=unused-but-set-parameter=]
> 
> The issue here is that __pte_clear() does not actually use its second
> argument when CONFIG_ARM64_CONTPTE is disabled.
> 
> Reword this to compute the offset each time instead of updating the
> argument variable. I checked that the resulting object code is
> unchanged.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  arch/arm64/mm/hugetlbpage.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index a42c05cf5640..4ad7662e8323 100644
> --- a/arch/arm64/mm/hugetlbpage.c
> +++ b/arch/arm64/mm/hugetlbpage.c
> @@ -374,8 +374,8 @@ void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
>  
>  	ncontig = num_contig_ptes(sz, &pgsize);
>  
> -	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
> -		__pte_clear(mm, addr, ptep);
> +	for (i = 0; i < ncontig; i++, ptep++)
> +		__pte_clear(mm, addr + pgsize*i, ptep);

Should we not fix the macro instead? Either with a (void)(addr) or just
turn it into an inline function (still compiling):

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 64d5f1d9cce9..c248b033a472 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -179,8 +179,6 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
 	__pte(__phys_to_pte_val((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot))

 #define pte_none(pte)		(!pte_val(pte))
-#define __pte_clear(mm, addr, ptep) \
-				__set_pte(ptep, __pte(0))
 #define pte_page(pte)		(pfn_to_page(pte_pfn(pte)))

 /*
@@ -1320,6 +1318,12 @@ static inline bool pud_user_accessible_page(pud_t pud)
 /*
  * Atomic pte/pmd modifications.
  */
+static inline void __pte_clear(struct mm_struct *mm,
+			       unsigned long addr, pte_t *ptep)
+{
+	__set_pte(ptep, __pte(0));
+}
+
 static inline int __ptep_test_and_clear_young(struct vm_area_struct *vma,
 					      unsigned long address,
 					      pte_t *ptep)
Re: [PATCH] arm64: hugetlbpage: avoid unused-but-set-parameter warning (gcc-16)
Posted by Arnd Bergmann 3 days, 20 hours ago
On Tue, Feb 3, 2026, at 19:17, Catalin Marinas wrote:
> On Tue, Feb 03, 2026 at 05:21:23PM +0100, Arnd Bergmann wrote:
>>  
>>  	ncontig = num_contig_ptes(sz, &pgsize);
>>  
>> -	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
>> -		__pte_clear(mm, addr, ptep);
>> +	for (i = 0; i < ncontig; i++, ptep++)
>> +		__pte_clear(mm, addr + pgsize*i, ptep);
>
> Should we not fix the macro instead? Either with a (void)(addr) or just
> turn it into an inline function (still compiling):

Good idea, I'll add your inline function to my randconfig setup
instead and will let you know if I run into other problems.

      Arnd