[v2] sched: fix integer handling issue

Message ID 20220223173630.2951400-1-megha.ajmera@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] sched: fix integer handling issue |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Ajmera, Megha Feb. 23, 2022, 5:36 p.m. UTC
  Masking of core mask was incorrect. Instead of using 1U for shifting, it
should be using 1LU as the result is assigned to uint64.

CID 375859: Potentially overflowing expression "1U << app_main_core" with
type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit
arithmetic, and then used in a context that expects an expression of
type "uint64_t" (64 bits, unsigned).

Coverity issue: 375859

Signed-off-by: Megha Ajmera <megha.ajmera@intel.com>
---
 examples/qos_sched/args.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Morten Brørup Feb. 23, 2022, 6:13 p.m. UTC | #1
> From: Megha Ajmera [mailto:megha.ajmera@intel.com]
> Sent: Wednesday, 23 February 2022 18.37
> 
> Masking of core mask was incorrect. Instead of using 1U for shifting,
> it
> should be using 1LU as the result is assigned to uint64.
> 
> CID 375859: Potentially overflowing expression "1U << app_main_core"
> with
> type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit
> arithmetic, and then used in a context that expects an expression of
> type "uint64_t" (64 bits, unsigned).
> 
> Coverity issue: 375859
> 
> Signed-off-by: Megha Ajmera <megha.ajmera@intel.com>
> ---
>  examples/qos_sched/args.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c
> index 10ca7bea61..562d9ca150 100644
> --- a/examples/qos_sched/args.c
> +++ b/examples/qos_sched/args.c
> @@ -427,13 +427,13 @@ app_parse_args(int argc, char **argv)
> 
>  	/* check main core index validity */
>  	for (i = 0; i <= app_main_core; i++) {
> -		if (app_used_core_mask & (1u << app_main_core)) {
> +		if (app_used_core_mask & (RTE_BIT64(app_main_core))) {

No need for parenthesis around RTE_BIT64(app_main_core).

>  			RTE_LOG(ERR, APP, "Main core index is not configured
> properly\n");
>  			app_usage(prgname);
>  			return -1;
>  		}
>  	}
> -	app_used_core_mask |= 1u << app_main_core;
> +	app_used_core_mask |= RTE_BIT64(app_main_core);
> 
>  	if ((app_used_core_mask != app_eal_core_mask()) ||
>  			(app_main_core != rte_get_main_lcore())) {
> --
> 2.25.1
> 

Acked-by: Morten Brørup <mb@smartsharesystems.com>
  
Thomas Monjalon Feb. 24, 2022, 10:51 p.m. UTC | #2
23/02/2022 19:13, Morten Brørup:
> > From: Megha Ajmera [mailto:megha.ajmera@intel.com]
> > Sent: Wednesday, 23 February 2022 18.37
> > 
> > Masking of core mask was incorrect. Instead of using 1U for shifting,
> > it
> > should be using 1LU as the result is assigned to uint64.
> > 
> > CID 375859: Potentially overflowing expression "1U << app_main_core"
> > with
> > type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit
> > arithmetic, and then used in a context that expects an expression of
> > type "uint64_t" (64 bits, unsigned).
> > 
> > Coverity issue: 375859
> > 
> > Signed-off-by: Megha Ajmera <megha.ajmera@intel.com>
> > ---
> > -		if (app_used_core_mask & (1u << app_main_core)) {
> > +		if (app_used_core_mask & (RTE_BIT64(app_main_core))) {
> 
> No need for parenthesis around RTE_BIT64(app_main_core).

Fixed while merging.

> Acked-by: Morten Brørup <mb@smartsharesystems.com>

Applied, thanks.
  

Patch

diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c
index 10ca7bea61..562d9ca150 100644
--- a/examples/qos_sched/args.c
+++ b/examples/qos_sched/args.c
@@ -427,13 +427,13 @@  app_parse_args(int argc, char **argv)
 
 	/* check main core index validity */
 	for (i = 0; i <= app_main_core; i++) {
-		if (app_used_core_mask & (1u << app_main_core)) {
+		if (app_used_core_mask & (RTE_BIT64(app_main_core))) {
 			RTE_LOG(ERR, APP, "Main core index is not configured properly\n");
 			app_usage(prgname);
 			return -1;
 		}
 	}
-	app_used_core_mask |= 1u << app_main_core;
+	app_used_core_mask |= RTE_BIT64(app_main_core);
 
 	if ((app_used_core_mask != app_eal_core_mask()) ||
 			(app_main_core != rte_get_main_lcore())) {