[PATCH v2] selftests/mqueue: fix 5 warnings about signed/unsigned mismatches

John Hubbard posted 1 patch 1 week, 4 days ago
tools/testing/selftests/mqueue/mq_perf_tests.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
[PATCH v2] selftests/mqueue: fix 5 warnings about signed/unsigned mismatches
Posted by John Hubbard 1 week, 4 days ago
When building with clang, via:

    make LLVM=1 -C tools/testing/selftest

...clang warns about several cases of using a signed integer for the
priority argument to mq_receive(3), which expects an unsigned int.

Fix this by declaring the type as unsigned int in all cases.

Also, both input and output priority are unsigned, per the man pages, so
let's change the type of both priorities throughout, even though clang
did not warn about the prio_out variable.

Also, add an argument name to test->func(), in order to address another
warning from clang.

Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 tools/testing/selftests/mqueue/mq_perf_tests.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
index 5c16159d0bcd..9380c656581f 100644
--- a/tools/testing/selftests/mqueue/mq_perf_tests.c
+++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
@@ -323,7 +323,8 @@ void *fake_cont_thread(void *arg)
 void *cont_thread(void *arg)
 {
 	char buff[MSG_SIZE];
-	int i, priority;
+	int i;
+	unsigned int priority;
 
 	for (i = 0; i < num_cpus_to_pin; i++)
 		if (cpu_threads[i] == pthread_self())
@@ -373,27 +374,27 @@ void *cont_thread(void *arg)
 
 struct test {
 	char *desc;
-	void (*func)(int *);
+	void (*func)(unsigned int *prio);
 };
 
-void const_prio(int *prio)
+void const_prio(unsigned int *prio)
 {
 	return;
 }
 
-void inc_prio(int *prio)
+void inc_prio(unsigned int *prio)
 {
 	if (++*prio == mq_prio_max)
 		*prio = 0;
 }
 
-void dec_prio(int *prio)
+void dec_prio(unsigned int *prio)
 {
 	if (--*prio < 0)
 		*prio = mq_prio_max - 1;
 }
 
-void random_prio(int *prio)
+void random_prio(unsigned int *prio)
 {
 	*prio = random() % mq_prio_max;
 }
@@ -425,7 +426,7 @@ struct test test2[] = {
 void *perf_test_thread(void *arg)
 {
 	char buff[MSG_SIZE];
-	int prio_out, prio_in;
+	unsigned int prio_out, prio_in;
 	int i;
 	clockid_t clock;
 	pthread_t *t;

base-commit: 45db3ab70092637967967bfd8e6144017638563c
prerequisite-patch-id: b901ece2a5b78503e2fb5480f20e304d36a0ea27
-- 
2.45.0
Re: [PATCH v2] selftests/mqueue: fix 5 warnings about signed/unsigned mismatches
Posted by Muhammad Usama Anjum 1 week, 2 days ago
On 5/9/24 1:00 AM, John Hubbard wrote:
> When building with clang, via:
> 
>     make LLVM=1 -C tools/testing/selftest
> 
> ...clang warns about several cases of using a signed integer for the
> priority argument to mq_receive(3), which expects an unsigned int.
> 
> Fix this by declaring the type as unsigned int in all cases.
> 
> Also, both input and output priority are unsigned, per the man pages, so
> let's change the type of both priorities throughout, even though clang
> did not warn about the prio_out variable.
> 
> Also, add an argument name to test->func(), in order to address another
> warning from clang.
> 
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
LGTM
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  tools/testing/selftests/mqueue/mq_perf_tests.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
> index 5c16159d0bcd..9380c656581f 100644
> --- a/tools/testing/selftests/mqueue/mq_perf_tests.c
> +++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
> @@ -323,7 +323,8 @@ void *fake_cont_thread(void *arg)
>  void *cont_thread(void *arg)
>  {
>  	char buff[MSG_SIZE];
> -	int i, priority;
> +	int i;
> +	unsigned int priority;
>  
>  	for (i = 0; i < num_cpus_to_pin; i++)
>  		if (cpu_threads[i] == pthread_self())
> @@ -373,27 +374,27 @@ void *cont_thread(void *arg)
>  
>  struct test {
>  	char *desc;
> -	void (*func)(int *);
> +	void (*func)(unsigned int *prio);
>  };
>  
> -void const_prio(int *prio)
> +void const_prio(unsigned int *prio)
>  {
>  	return;
>  }
>  
> -void inc_prio(int *prio)
> +void inc_prio(unsigned int *prio)
>  {
>  	if (++*prio == mq_prio_max)
>  		*prio = 0;
>  }
>  
> -void dec_prio(int *prio)
> +void dec_prio(unsigned int *prio)
>  {
>  	if (--*prio < 0)
>  		*prio = mq_prio_max - 1;
>  }
>  
> -void random_prio(int *prio)
> +void random_prio(unsigned int *prio)
>  {
>  	*prio = random() % mq_prio_max;
>  }
> @@ -425,7 +426,7 @@ struct test test2[] = {
>  void *perf_test_thread(void *arg)
>  {
>  	char buff[MSG_SIZE];
> -	int prio_out, prio_in;
> +	unsigned int prio_out, prio_in;
>  	int i;
>  	clockid_t clock;
>  	pthread_t *t;
> 
> base-commit: 45db3ab70092637967967bfd8e6144017638563c
> prerequisite-patch-id: b901ece2a5b78503e2fb5480f20e304d36a0ea27

-- 
BR,
Muhammad Usama Anjum
Re: [PATCH v2] selftests/mqueue: fix 5 warnings about signed/unsigned mismatches
Posted by Ryan Roberts 1 week, 3 days ago
On 08/05/2024 21:00, John Hubbard wrote:
> When building with clang, via:
> 
>     make LLVM=1 -C tools/testing/selftest
> 
> ...clang warns about several cases of using a signed integer for the
> priority argument to mq_receive(3), which expects an unsigned int.
> 
> Fix this by declaring the type as unsigned int in all cases.
> 
> Also, both input and output priority are unsigned, per the man pages, so
> let's change the type of both priorities throughout, even though clang
> did not warn about the prio_out variable.
> 
> Also, add an argument name to test->func(), in order to address another
> warning from clang.
> 
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>

> ---
>  tools/testing/selftests/mqueue/mq_perf_tests.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
> index 5c16159d0bcd..9380c656581f 100644
> --- a/tools/testing/selftests/mqueue/mq_perf_tests.c
> +++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
> @@ -323,7 +323,8 @@ void *fake_cont_thread(void *arg)
>  void *cont_thread(void *arg)
>  {
>  	char buff[MSG_SIZE];
> -	int i, priority;
> +	int i;
> +	unsigned int priority;
>  
>  	for (i = 0; i < num_cpus_to_pin; i++)
>  		if (cpu_threads[i] == pthread_self())
> @@ -373,27 +374,27 @@ void *cont_thread(void *arg)
>  
>  struct test {
>  	char *desc;
> -	void (*func)(int *);
> +	void (*func)(unsigned int *prio);
>  };
>  
> -void const_prio(int *prio)
> +void const_prio(unsigned int *prio)
>  {
>  	return;
>  }
>  
> -void inc_prio(int *prio)
> +void inc_prio(unsigned int *prio)
>  {
>  	if (++*prio == mq_prio_max)
>  		*prio = 0;
>  }
>  
> -void dec_prio(int *prio)
> +void dec_prio(unsigned int *prio)
>  {
>  	if (--*prio < 0)
>  		*prio = mq_prio_max - 1;
>  }
>  
> -void random_prio(int *prio)
> +void random_prio(unsigned int *prio)
>  {
>  	*prio = random() % mq_prio_max;
>  }
> @@ -425,7 +426,7 @@ struct test test2[] = {
>  void *perf_test_thread(void *arg)
>  {
>  	char buff[MSG_SIZE];
> -	int prio_out, prio_in;
> +	unsigned int prio_out, prio_in;
>  	int i;
>  	clockid_t clock;
>  	pthread_t *t;
> 
> base-commit: 45db3ab70092637967967bfd8e6144017638563c
> prerequisite-patch-id: b901ece2a5b78503e2fb5480f20e304d36a0ea27