diff mbox series

rt-tests: cyclictest: Remove warnings due different signedness in comparison

Message ID 20230808225500.292257-1-ezulian@redhat.com
State Superseded
Headers show
Series rt-tests: cyclictest: Remove warnings due different signedness in comparison | expand

Commit Message

Eder Zulian Aug. 8, 2023, 10:55 p.m. UTC
Type casting used to remove compiler warnings due to comparison of integer expressions of different signedness.

Signed-off-by: Eder Zulian <ezulian@redhat.com>
---
 src/cyclictest/cyclictest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

John Kacur Aug. 9, 2023, 6:42 p.m. UTC | #1
On Wed, 9 Aug 2023, Eder Zulian wrote:

> Type casting used to remove compiler warnings due to comparison of integer expressions of different signedness.
> 
> Signed-off-by: Eder Zulian <ezulian@redhat.com>
> ---
>  src/cyclictest/cyclictest.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index 7b0f80f..3b47d53 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -317,8 +317,8 @@ static int raise_soft_prio(int policy, const struct sched_param *param)
>  		return err;
>  	}
>  
> -	soft_max = (rlim.rlim_cur == RLIM_INFINITY) ? policy_max : rlim.rlim_cur;
> -	hard_max = (rlim.rlim_max == RLIM_INFINITY) ? policy_max : rlim.rlim_max;
> +	soft_max = (rlim.rlim_cur == RLIM_INFINITY) ? (unsigned)policy_max : rlim.rlim_cur;
> +	hard_max = (rlim.rlim_max == RLIM_INFINITY) ? (unsigned)policy_max : rlim.rlim_max;
>  
>  	if (prio > soft_max && prio <= hard_max) {
>  		rlim.rlim_cur = prio;
> -- 
> 2.39.3
> 
> 
Although we are not as strict as the kernel, we try to follow most of 
their coding rules, and I usually run checkkpatch on patches.

../linux/scripts/checkpatch.pl eder2.patch 
WARNING: Possible unwrapped commit description (prefer a maximum 75 chars 
per line)
#8: 
Type casting used to remove compiler warnings due to comparison of integer 
expressions of different signedness.

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
#25: FILE: src/cyclictest/cyclictest.c:320:
+	soft_max = (rlim.rlim_cur == RLIM_INFINITY) ? (unsigned)policy_max 
: rlim.rlim_cur;

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
#26: FILE: src/cyclictest/cyclictest.c:321:
+	hard_max = (rlim.rlim_max == RLIM_INFINITY) ? (unsigned)policy_max 
: rlim.rlim_max;

total: 0 errors, 3 warnings, 10 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or 
--fix-inplace.

eder2.patch has style problems, please review.

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.

-------
The cast is fine in this case, we can't just use an unsigned int
because sched_get_priority_max could return an error. So, just fix
the unwrapped line in your commit message and make the cast
unsigned int

and then I'll apply it.

Thanks

John
diff mbox series

Patch

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 7b0f80f..3b47d53 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -317,8 +317,8 @@  static int raise_soft_prio(int policy, const struct sched_param *param)
 		return err;
 	}
 
-	soft_max = (rlim.rlim_cur == RLIM_INFINITY) ? policy_max : rlim.rlim_cur;
-	hard_max = (rlim.rlim_max == RLIM_INFINITY) ? policy_max : rlim.rlim_max;
+	soft_max = (rlim.rlim_cur == RLIM_INFINITY) ? (unsigned)policy_max : rlim.rlim_cur;
+	hard_max = (rlim.rlim_max == RLIM_INFINITY) ? (unsigned)policy_max : rlim.rlim_max;
 
 	if (prio > soft_max && prio <= hard_max) {
 		rlim.rlim_cur = prio;