[6/6] baseband/fpga_5gnr: don't use rand()

Message ID 20240301175842.159967-7-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series Coverity related fixes |

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/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Stephen Hemminger March 1, 2024, 5:57 p.m. UTC
  The function rand is very weak and should not be used.
Use the DPDK rte_rand() which is seeded from entropy instead.

Coverity issue: 414987
Fixes: b3d326e438f1 ("baseband/fpga_5gnr_fec: add FPGA mutex")
Cc: hernan.vargas@intel.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Tyler Retzlaff March 1, 2024, 6:11 p.m. UTC | #1
On Fri, Mar 01, 2024 at 09:57:11AM -0800, Stephen Hemminger wrote:
> The function rand is very weak and should not be used.
> Use the DPDK rte_rand() which is seeded from entropy instead.
> 
> Coverity issue: 414987
> Fixes: b3d326e438f1 ("baseband/fpga_5gnr_fec: add FPGA mutex")
> Cc: hernan.vargas@intel.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---

Reviewed-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  
Chautru, Nicolas March 2, 2024, 1:07 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Friday, March 1, 2024 9:57 AM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Vargas, Hernan
> <hernan.vargas@intel.com>; Chautru, Nicolas <nicolas.chautru@intel.com>
> Subject: [PATCH 6/6] baseband/fpga_5gnr: don't use rand()
> 
> The function rand is very weak and should not be used.
> Use the DPDK rte_rand() which is seeded from entropy instead.
> 
> Coverity issue: 414987
> Fixes: b3d326e438f1 ("baseband/fpga_5gnr_fec: add FPGA mutex")
> Cc: hernan.vargas@intel.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Acked-by: Nicolas Chautru <nicolas.chautru@intel.com>

> ---
>  drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
> b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
> index efc1d3a7725b..9b253cde280d 100644
> --- a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
> +++ b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
> @@ -14,6 +14,7 @@
>  #include <bus_pci_driver.h>
>  #include <rte_byteorder.h>
>  #include <rte_cycles.h>
> +#include <rte_random.h>
> 
>  #include <rte_bbdev.h>
>  #include <rte_bbdev_pmd.h>
> @@ -1990,7 +1991,7 @@ fpga_5gnr_mutex_acquisition(struct
> fpga_5gnr_queue *q)  {
>  	uint32_t mutex_ctrl, mutex_read, cnt = 0;
>  	/* Assign a unique id for the duration of the DDR access */
> -	q->ddr_mutex_uuid = rand();
> +	q->ddr_mutex_uuid = rte_rand();
>  	/* Request and wait for acquisition of the mutex */
>  	mutex_ctrl = (q->ddr_mutex_uuid << 16) + 1;
>  	do {
> --
> 2.43.0
  

Patch

diff --git a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
index efc1d3a7725b..9b253cde280d 100644
--- a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
+++ b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
@@ -14,6 +14,7 @@ 
 #include <bus_pci_driver.h>
 #include <rte_byteorder.h>
 #include <rte_cycles.h>
+#include <rte_random.h>
 
 #include <rte_bbdev.h>
 #include <rte_bbdev_pmd.h>
@@ -1990,7 +1991,7 @@  fpga_5gnr_mutex_acquisition(struct fpga_5gnr_queue *q)
 {
 	uint32_t mutex_ctrl, mutex_read, cnt = 0;
 	/* Assign a unique id for the duration of the DDR access */
-	q->ddr_mutex_uuid = rand();
+	q->ddr_mutex_uuid = rte_rand();
 	/* Request and wait for acquisition of the mutex */
 	mutex_ctrl = (q->ddr_mutex_uuid << 16) + 1;
 	do {