app/testpmd: fix build on signed comparison

Message ID 20240722105229.2628825-1-ferruh.yigit@amd.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series app/testpmd: fix build on signed comparison |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS RETEST #2
ci/iol-unit-arm64-testing success Testing PASS RETEST #2
ci/iol-unit-amd64-testing success Testing PASS RETEST #2
ci/iol-sample-apps-testing success Testing PASS RETEST #2
ci/iol-intel-Performance success Performance Testing PASS RETEST #2

Commit Message

Ferruh Yigit July 22, 2024, 10:52 a.m. UTC
Build error:
.../app/test-pmd/config.c: In function 'icmp_echo_config_setup':
.../app/test-pmd/config.c:5159:30:
   error: comparison between signed and unsigned integer expressions
          [-Werror=sign-compare]
  if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
                              ^
All 'nb_txq', 'nb_fwd_ports' & 'nb_fwd_lcores' are unsigned variables,
but the warning is related to the integer promotion rules of C:
'nb_txq'       -> uint16_t, promoted to 'int'
'nb_fwd_ports' -> uint16_t, promoted to 'int'
(nb_txq * nb_fwd_ports) -> result 'int'
nb_fwd_lcores  -> 'uint32_t'
Ends up comparing 'int' vs 'uint32_t'.

Fixing by adding the casting back which was initially part of the patch.

Fixes: 2bf44dd14fa5 ("app/testpmd: fix lcore ID restriction")
Cc: stable@dpdk.org

Reported-by: Raslan Darawsheh <rasland@nvidia.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Cc: sivaprasad.tummala@amd.com
---
 app/test-pmd/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ferruh Yigit July 22, 2024, 1:26 p.m. UTC | #1
On 7/22/2024 11:52 AM, Ferruh Yigit wrote:
> Build error:
> .../app/test-pmd/config.c: In function 'icmp_echo_config_setup':
> .../app/test-pmd/config.c:5159:30:
>    error: comparison between signed and unsigned integer expressions
>           [-Werror=sign-compare]
>   if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
>                               ^
> All 'nb_txq', 'nb_fwd_ports' & 'nb_fwd_lcores' are unsigned variables,
> but the warning is related to the integer promotion rules of C:
> 'nb_txq'       -> uint16_t, promoted to 'int'
> 'nb_fwd_ports' -> uint16_t, promoted to 'int'
> (nb_txq * nb_fwd_ports) -> result 'int'
> nb_fwd_lcores  -> 'uint32_t'
> Ends up comparing 'int' vs 'uint32_t'.
> 
> Fixing by adding the casting back which was initially part of the patch.
> 
> Fixes: 2bf44dd14fa5 ("app/testpmd: fix lcore ID restriction")
> Cc: stable@dpdk.org
> 
> Reported-by: Raslan Darawsheh <rasland@nvidia.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
>

Hi Raslan, Ali,

If you can test the patch, as I can't reproduce the build error, I can
quickly merge the fix for -rc3.

Thanks,
ferruh
  
Ferruh Yigit July 22, 2024, 4:11 p.m. UTC | #2
On 7/22/2024 11:52 AM, Ferruh Yigit wrote:
> Build error:
> .../app/test-pmd/config.c: In function 'icmp_echo_config_setup':
> .../app/test-pmd/config.c:5159:30:
>    error: comparison between signed and unsigned integer expressions
>           [-Werror=sign-compare]
>   if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
>                               ^
> All 'nb_txq', 'nb_fwd_ports' & 'nb_fwd_lcores' are unsigned variables,
> but the warning is related to the integer promotion rules of C:
> 'nb_txq'       -> uint16_t, promoted to 'int'
> 'nb_fwd_ports' -> uint16_t, promoted to 'int'
> (nb_txq * nb_fwd_ports) -> result 'int'
> nb_fwd_lcores  -> 'uint32_t'
> Ends up comparing 'int' vs 'uint32_t'.
> 
> Fixing by adding the casting back which was initially part of the patch.
> 
> Fixes: 2bf44dd14fa5 ("app/testpmd: fix lcore ID restriction")
> Cc: stable@dpdk.org
> 
> Reported-by: Raslan Darawsheh <rasland@nvidia.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
>

Recheck-request: iol-unit-amd64-testing
  
Ali Alnubani July 22, 2024, 7:21 p.m. UTC | #3
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@amd.com>
> Sent: Monday, July 22, 2024 1:52 PM
> To: Aman Singh <aman.deep.singh@intel.com>; Sivaprasad Tummala
> <sivaprasad.tummala@amd.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Raslan Darawsheh <rasland@nvidia.com>
> Subject: [PATCH] app/testpmd: fix build on signed comparison
> 
> Build error:
> .../app/test-pmd/config.c: In function 'icmp_echo_config_setup':
> .../app/test-pmd/config.c:5159:30:
>    error: comparison between signed and unsigned integer expressions
>           [-Werror=sign-compare]
>   if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
>                               ^
> All 'nb_txq', 'nb_fwd_ports' & 'nb_fwd_lcores' are unsigned variables,
> but the warning is related to the integer promotion rules of C:
> 'nb_txq'       -> uint16_t, promoted to 'int'
> 'nb_fwd_ports' -> uint16_t, promoted to 'int'
> (nb_txq * nb_fwd_ports) -> result 'int'
> nb_fwd_lcores  -> 'uint32_t'
> Ends up comparing 'int' vs 'uint32_t'.
> 
> Fixing by adding the casting back which was initially part of the patch.
> 
> Fixes: 2bf44dd14fa5 ("app/testpmd: fix lcore ID restriction")
> Cc: stable@dpdk.org
> 
> Reported-by: Raslan Darawsheh <rasland@nvidia.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
> ---
> Cc: sivaprasad.tummala@amd.com
> ---

Hi Ferruh,

I tested on openSUSE Leap 15.6 (gcc 7.5.0) with debug build type and can confirm it resolves the build failure.

Tested-by: Ali Alnubani <alialnu@nvidia.com>

Thanks,
Ali
  
Ferruh Yigit July 22, 2024, 9:26 p.m. UTC | #4
On 7/22/2024 8:21 PM, Ali Alnubani wrote:
>> -----Original Message-----
>> From: Ferruh Yigit <ferruh.yigit@amd.com>
>> Sent: Monday, July 22, 2024 1:52 PM
>> To: Aman Singh <aman.deep.singh@intel.com>; Sivaprasad Tummala
>> <sivaprasad.tummala@amd.com>
>> Cc: dev@dpdk.org; stable@dpdk.org; Raslan Darawsheh <rasland@nvidia.com>
>> Subject: [PATCH] app/testpmd: fix build on signed comparison
>>
>> Build error:
>> .../app/test-pmd/config.c: In function 'icmp_echo_config_setup':
>> .../app/test-pmd/config.c:5159:30:
>>    error: comparison between signed and unsigned integer expressions
>>           [-Werror=sign-compare]
>>   if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
>>                               ^
>> All 'nb_txq', 'nb_fwd_ports' & 'nb_fwd_lcores' are unsigned variables,
>> but the warning is related to the integer promotion rules of C:
>> 'nb_txq'       -> uint16_t, promoted to 'int'
>> 'nb_fwd_ports' -> uint16_t, promoted to 'int'
>> (nb_txq * nb_fwd_ports) -> result 'int'
>> nb_fwd_lcores  -> 'uint32_t'
>> Ends up comparing 'int' vs 'uint32_t'.
>>
>> Fixing by adding the casting back which was initially part of the patch.
>>
>> Fixes: 2bf44dd14fa5 ("app/testpmd: fix lcore ID restriction")
>> Cc: stable@dpdk.org
>>
>> Reported-by: Raslan Darawsheh <rasland@nvidia.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
>> ---
>> Cc: sivaprasad.tummala@amd.com
>> ---
> 
> Hi Ferruh,
> 
> I tested on openSUSE Leap 15.6 (gcc 7.5.0) with debug build type and can confirm it resolves the build failure.
> 
> Tested-by: Ali Alnubani <alialnu@nvidia.com>
> 

Thank you.

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 66c3a68c1dc6..6f0beafa271c 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -5156,7 +5156,7 @@  icmp_echo_config_setup(void)
 	lcoreid_t lc_id;
 	uint16_t  sm_id;
 
-	if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
+	if ((lcoreid_t)(nb_txq * nb_fwd_ports) < nb_fwd_lcores)
 		cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
 			(nb_txq * nb_fwd_ports);
 	else