mm, cma: fix 32-bit warning
Subsystems (2)
PATCH 1/2 mm, cma: fix 32-bit warning
From: Arnd Bergmann <[email protected]>
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.
--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/cma.c +1 -1
@@ -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);
Signature · 1 line
2.39.5
PATCH 2/2 mm, cma: use literal printf format string
From: Arnd Bergmann <[email protected]>
Using a variable string as a printf format can be a security issue that clang warns about when extra warnings are enabled:
mm/cma.c:239:37: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
239 | snprintf(cma->name, CMA_MAX_NAME, name);
| ^~~~
This one does not appear to be a security issue since the string is not user controlled, but it's better to avoid the warning. Use "%s" as the format instead and just pass the name as the argument.
--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/cma.c +1 -1
@@ -236,7 +236,7 @@ static int __init cma_new_area(const char *name, phys_addr_t size, cma_area_count++;if (name) -snprintf (cma->name,CMA_MAX_NAME , name); +snprintf (cma->name,CMA_MAX_NAME ,"%s" , name);else snprintf (cma->name,CMA_MAX_NAME ,"cma%d\n" , cma_area_count);
Signature · 1 line
2.39.5
Re: [PATCH 2/2] mm, cma: use literal printf format string
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Using a variable string as a printf format can be a security issue that clang warns about when extra warnings are enabled:
mm/cma.c:239:37: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
239 |snprintf(cma->name, CMA_MAX_NAME, name);
| ^~~~
Quoted 9 lines
This one does not appear to be a security issue since the string is not user controlled, but it's better to avoid the warning. Use "%s" as the format instead and just pass the name as the argument.
Signed-off-by Arnd Bergmann <[email protected]>--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
LGTM. Reviewed-by: Zi Yan <[email protected]>
Best Regards,
Yan, Zi
Re: [PATCH 2/2] mm, cma: use literal printf format string
In reply to Arnd BergmannQuoted 23 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Using a variable string as a printf format can be a security issue that clang warns about when extra warnings are enabled:
mm/cma.c:239:37: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
239 |snprintf(cma->name, CMA_MAX_NAME, name);
| ^~~~This one does not appear to be a security issue since the string is not user controlled, but it's better to avoid the warning. Use "%s" as the format instead and just pass the name as the argument.
Signed-off-by Arnd Bergmann <[email protected]>--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/cma.c +0
-0
mm/cma.c static int __init cma_new_area(const char *name, phys_addr_t size, · line 242
Quoted 8 lines
mm/cma.c +1
-1@@ -236,7 +236,7 @@ static int __init cma_new_area(const char *name, phys_addr_t size, cma_area_count++;if (name) -snprintf (cma->name,CMA_MAX_NAME , name); +snprintf (cma->name,CMA_MAX_NAME ,"%s" , name);else snprintf (cma->name,CMA_MAX_NAME ,"cma%d\n" , cma_area_count);
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 2/2] mm, cma: use literal printf format string
In reply to Arnd BergmannQuoted 33 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Using a variable string as a printf format can be a security issue that clang warns about when extra warnings are enabled:
mm/cma.c:239:37: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
239 |snprintf(cma->name, CMA_MAX_NAME, name);
| ^~~~This one does not appear to be a security issue since the string is not user controlled, but it's better to avoid the warning. Use "%s" as the format instead and just pass the name as the argument.
Signed-off-by Arnd Bergmann <[email protected]>--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/cma.c +1
-2@@ -236,7 +236,7 @@ static int __init cma_new_area(const char *name, phys_addr_t size, cma_area_count++;if (name) -snprintf (cma->name,CMA_MAX_NAME , name); +snprintf (cma->name,CMA_MAX_NAME ,"%s" , name);else snprintf (cma->name,CMA_MAX_NAME ,"cma%d\n" , cma_area_count); --
Quoted 2 lines
2.39.5
Yes, thanks - not sure why I didn't use "%s" there.
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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)| ~~~~~ ^ ~~~~~
Quoted 7 lines
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 <[email protected]>--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
LGTM. Reviewed-by: Zi Yan <[email protected]>
Best Regards,
Yan, Zi
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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
Signature · 3 lines
Cheers, David / dhildenb
Quoted 32 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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 <[email protected]>--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/cma.c +1
-2@@ -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); --
Quoted 2 lines
2.39.5
Thanks for fixing these nits in my patch series - which, btw, needs more reviews, if anyone's reading this - please :)