"minsize" builds of DPDK with GCC can trigger the following warning
(error with Werror):
../lib/gpudev/gpudev.c: In function 'rte_gpu_attach':
../lib/gpudev/gpudev.c:290:39: warning: 'shared_dev' may be used uninitialized
[-Wmaybe-uninitialized]
290 | rte_atomic_fetch_add_explicit(&dev->mpshared->process_refcnt,
1, rte_memory_order_relaxed);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This can't really happen - shared_dev is initialized in the for loop
before this usage. However, the compiler can't see that gpu_max is
guaranteed to be > 0 in that loop (which it is, as we have returned
earlier if gpus == NULL), and thus assumes the loop may not run any
iterations.
Regardless, NULL-initialize shared_dev at declaration to silence the
warning.
Signed-off-by: Jack Bond-Preston <[email protected]>
Reviewed-by: Wathsala Vithanage <[email protected]>
---
lib/gpudev/gpudev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c
index 4a2335834c..93a30464f0 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -251,7 +251,7 @@ rte_gpu_attach(const char *name)
{
int16_t dev_id;
struct rte_gpu *dev;
- struct rte_gpu_mpshared *shared_dev;
+ struct rte_gpu_mpshared *shared_dev = NULL;
if (rte_eal_process_type() != RTE_PROC_SECONDARY) {
GPU_LOG(ERR, "only secondary process can attach device");
--
2.43.0