diff mbox series

[1/2] mm, cma: fix 32-bit warning

Message ID 20250224141120.1240534-1-arnd@kernel.org (mailing list archive)
State New
Headers show
Series [1/2] mm, cma: fix 32-bit warning | expand

Commit Message

Arnd Bergmann Feb. 24, 2025, 2:07 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

clang warns about certain always-true conditions, like this one on 32-bit
builds:

mm/cma.c:420:13: error: result of comparison of constant 4294967296 with expression of type 'phys_addr_t' (aka 'unsigned int') is always true [-Werror,-Wtautological-constant-out-of-range-compare]
  420 |                 if (start < SZ_4G)
      |                     ~~~~~ ^ ~~~~~

Replace this one with an equivalent expression that does not cause a warning.

Fixes: 4765deffa0f7 ("mm, cma: support multiple contiguous ranges, if requested")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 mm/cma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Zi Yan Feb. 24, 2025, 2:26 p.m. UTC | #1
On 24 Feb 2025, at 9:07, Arnd Bergmann wrote:

> From: Arnd Bergmann <arnd@arndb.de>
>
> clang warns about certain always-true conditions, like this one on 32-bit
> builds:
>
> mm/cma.c:420:13: error: result of comparison of constant 4294967296 with expression of type 'phys_addr_t' (aka 'unsigned int') is always true [-Werror,-Wtautological-constant-out-of-range-compare]
>   420 |                 if (start < SZ_4G)
>       |                     ~~~~~ ^ ~~~~~
>
> Replace this one with an equivalent expression that does not cause a warning.
>
> Fixes: 4765deffa0f7 ("mm, cma: support multiple contiguous ranges, if requested")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  mm/cma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

LGTM. Reviewed-by: Zi Yan <ziy@nvidia.com>

Best Regards,
Yan, Zi
David Hildenbrand Feb. 24, 2025, 2:36 p.m. UTC | #2
On 24.02.25 15:07, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang warns about certain always-true conditions, like this one on 32-bit
> builds:
> 
> mm/cma.c:420:13: error: result of comparison of constant 4294967296 with expression of type 'phys_addr_t' (aka 'unsigned int') is always true [-Werror,-Wtautological-constant-out-of-range-compare]
>    420 |                 if (start < SZ_4G)
>        |                     ~~~~~ ^ ~~~~~
> 

Hm, so in this case the whole loop is unnecessary.

In any case

Acked-by: David Hildenbrand <david@redhat.com>
Frank van der Linden Feb. 24, 2025, 5 p.m. UTC | #3
On Mon, Feb 24, 2025 at 6:11 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang warns about certain always-true conditions, like this one on 32-bit
> builds:
>
> mm/cma.c:420:13: error: result of comparison of constant 4294967296 with expression of type 'phys_addr_t' (aka 'unsigned int') is always true [-Werror,-Wtautological-constant-out-of-range-compare]
>   420 |                 if (start < SZ_4G)
>       |                     ~~~~~ ^ ~~~~~
>
> Replace this one with an equivalent expression that does not cause a warning.
>
> Fixes: 4765deffa0f7 ("mm, cma: support multiple contiguous ranges, if requested")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  mm/cma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/cma.c b/mm/cma.c
> index 34a4df29af72..ef0206c0f16d 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -417,7 +417,7 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
>          * Create a list of ranges above 4G, largest range first.
>          */
>         for_each_free_mem_range(i, nid, MEMBLOCK_NONE, &start, &end, NULL) {
> -               if (start < SZ_4G)
> +               if (upper_32_bits(start) == 0)
>                         continue;
>
>                 start = ALIGN(start, align);
> --
> 2.39.5
>

Thanks for fixing these nits in my patch series - which, btw, needs
more reviews, if anyone's reading this - please :)

Reviewed-by: Frank van der Linden <fvdl@google.com>
diff mbox series

Patch

diff --git a/mm/cma.c b/mm/cma.c
index 34a4df29af72..ef0206c0f16d 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -417,7 +417,7 @@  int __init cma_declare_contiguous_multi(phys_addr_t total_size,
 	 * Create a list of ranges above 4G, largest range first.
 	 */
 	for_each_free_mem_range(i, nid, MEMBLOCK_NONE, &start, &end, NULL) {
-		if (start < SZ_4G)
+		if (upper_32_bits(start) == 0)
 			continue;
 
 		start = ALIGN(start, align);