diff mbox series

[v2,2/3] selftests/futex: don't pass a const char* to asprintf(3)

Message ID 20240529022938.129624-3-jhubbard@nvidia.com (mailing list archive)
State Accepted
Commit 4bf15b1c657d22d1d70173e43264e4606dfe75ff
Headers show
Series selftests/futex: clang-inspired fixes | expand

Commit Message

John Hubbard May 29, 2024, 2:29 a.m. UTC
When building with clang, via:

    make LLVM=1 -C tools/testing/selftests

...clang issues a warning, because test_name is passed into asprintf(3),
which then changes it.

Fix this by simply removing the const qualifier. This is a local
automatic variable in a very short function, so there is not much need
to use the compiler to enforce const-ness at this scope.

[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c49f@valentinobst.de/

Fixes: f17d8a87ecb5 ("selftests: fuxex: Report a unique test name per run of futex_requeue_pi")
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 tools/testing/selftests/futex/functional/futex_requeue_pi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Shuah Khan May 30, 2024, 7:04 p.m. UTC | #1
On 5/28/24 20:29, John Hubbard wrote:
> When building with clang, via:
> 
>      make LLVM=1 -C tools/testing/selftests
> 
> ...clang issues a warning, because test_name is passed into asprintf(3),
> which then changes it.

Please include the warning in the commit log.

> 
> Fix this by simply removing the const qualifier. This is a local
> automatic variable in a very short function, so there is not much need
> to use the compiler to enforce const-ness at this scope.
> 
> [1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c49f@valentinobst.de/
> 
> Fixes: f17d8a87ecb5 ("selftests: fuxex: Report a unique test name per run of futex_requeue_pi")
> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---
>   tools/testing/selftests/futex/functional/futex_requeue_pi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> index 7f3ca5c78df1..215c6cb539b4 100644
> --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> @@ -360,7 +360,7 @@ int unit_test(int broadcast, long lock, int third_party_owner, long timeout_ns)
>   
>   int main(int argc, char *argv[])
>   {
> -	const char *test_name;
> +	char *test_name;
>   	int c, ret;
>   
>   	while ((c = getopt(argc, argv, "bchlot:v:")) != -1) {

thanks,
-- Shuah
John Hubbard May 30, 2024, 7:16 p.m. UTC | #2
On 5/30/24 12:04 PM, Shuah Khan wrote:
> On 5/28/24 20:29, John Hubbard wrote:
>> When building with clang, via:
>>
>>      make LLVM=1 -C tools/testing/selftests
>>
>> ...clang issues a warning, because test_name is passed into asprintf(3),
>> which then changes it.
> 
> Please include the warning in the commit log.

Ah, OK, the warning is:

futex_requeue_pi.c:403:17: warning: passing 'const char **' to parameter
of type 'char **' discards qualifiers in nested pointer types
[-Wincompatible-pointer-types-discards-qualifiers]


Please let me know if you'd prefer a v3, or if you'd rather fix it
up, whatever seems easiest for you.


thanks,
Shuah Khan May 30, 2024, 9:13 p.m. UTC | #3
On 5/30/24 13:16, John Hubbard wrote:
> On 5/30/24 12:04 PM, Shuah Khan wrote:
>> On 5/28/24 20:29, John Hubbard wrote:
>>> When building with clang, via:
>>>
>>>      make LLVM=1 -C tools/testing/selftests
>>>
>>> ...clang issues a warning, because test_name is passed into asprintf(3),
>>> which then changes it.
>>
>> Please include the warning in the commit log.
> 
> Ah, OK, the warning is:
> 
> futex_requeue_pi.c:403:17: warning: passing 'const char **' to parameter
> of type 'char **' discards qualifiers in nested pointer types
> [-Wincompatible-pointer-types-discards-qualifiers]
> 
> 
> Please let me know if you'd prefer a v3, or if you'd rather fix it
> up, whatever seems easiest for you.
> 

Yes please send me v3.

thanks,
-- Shuah
John Hubbard May 30, 2024, 9:15 p.m. UTC | #4
On 5/30/24 2:13 PM, Shuah Khan wrote:
> On 5/30/24 13:16, John Hubbard wrote:
>> On 5/30/24 12:04 PM, Shuah Khan wrote:
>>> On 5/28/24 20:29, John Hubbard wrote:
>>>> When building with clang, via:
>>>>
>>>>      make LLVM=1 -C tools/testing/selftests
>>>>
>>>> ...clang issues a warning, because test_name is passed into 
>>>> asprintf(3),
>>>> which then changes it.
>>>
>>> Please include the warning in the commit log.
>>
>> Ah, OK, the warning is:
>>
>> futex_requeue_pi.c:403:17: warning: passing 'const char **' to parameter
>> of type 'char **' discards qualifiers in nested pointer types
>> [-Wincompatible-pointer-types-discards-qualifiers]
>>
>>
>> Please let me know if you'd prefer a v3, or if you'd rather fix it
>> up, whatever seems easiest for you.
>>
> 
> Yes please send me v3.
> 

OK, coming soon, hopefully a bit later today, in fact.

thanks,
diff mbox series

Patch

diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
index 7f3ca5c78df1..215c6cb539b4 100644
--- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
+++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
@@ -360,7 +360,7 @@  int unit_test(int broadcast, long lock, int third_party_owner, long timeout_ns)
 
 int main(int argc, char *argv[])
 {
-	const char *test_name;
+	char *test_name;
 	int c, ret;
 
 	while ((c = getopt(argc, argv, "bchlot:v:")) != -1) {