Skip to contentSkip to conversation

devargs: fix derefrence before null test

PATCH NAK Weiguo Li 2 participants 2 messages Oct 30, 2023

lore
Share & tools
lore

Weiguo Li

author
#0 lore raw

PATCH 1/1 devargs: fix derefrence before null test

Pointer 'da' was dereferenced and then compared to NULL, reorder the code to keep the logic consistent.

Fixes 4969f5914c9e ("devargs: introduce new parsing helper")
---
 .mailmap                            | 2 +-
 lib/eal/common/eal_common_devargs.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
.mailmap +1 -1
index 3f5bab26a8..b4f0ae26b8 100644
@@ -1500,7 +1500,7 @@ Waterman Cao <[email protected]>
 Weichun Chen <[email protected]>
 Wei Dai <[email protected]>
 Weifeng Li <[email protected]>
-Weiguo Li <[email protected]>
+Weiguo Li <[email protected]> <[email protected]>
 Wei Huang <[email protected]>
 Wei Hu <[email protected]>
 Wei Hu (Xavier) <[email protected]>
lib/eal/common/eal_common_devargs.c +3 -1
index fb5d0a293b..8d6c3938eb 100644
@@ -185,11 +185,13 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
 {
 	struct rte_bus *bus = NULL;
 	const char *devname;
-	const size_t maxlen = sizeof(da->name);
 	size_t i;
 
 	if (da == NULL)
 		return -EINVAL;
+
+	const size_t maxlen = sizeof(da->name);
+
 	memset(da, 0, sizeof(*da));
 
 	/* First parse according global device syntax. */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 9 lines · On Mon, 30 Oct 2023 19:45:29 +0800 Weiguo Li <[email protected]> wrote:
(quoted diff) +0 -0

b/lib/eal/common/eal_common_devargs.c index fb5d0a293b..8d6c3938eb 100644 --- a/lib/eal/common/eal_common_devargs.c
+++ b/lib/eal/common/eal_common_devargs.c

lib/eal/common/eal_common_devargs.c +0 -1
@@ -185,11 +185,13 @@ rte_devargs_parse(struct rte_devargs *da, const
 char *dev) {
 	struct rte_bus *bus = NULL;
 	const char *devname;
-	const size_t maxlen = sizeof(da->name);

lib/eal/common/eal_common_devargs.c rte_devargs_parse(struct rte_devargs *da, const · line 197

Quoted 10 lines
lib/eal/common/eal_common_devargs.c +3 -0
 	size_t i;
 
 	if (da == NULL)
 		return -EINVAL;
+
+	const size_t maxlen = sizeof(da->name);
+
 	memset(da, 0, sizeof(*da));
 
 	/* First parse according global device syntax. */

NAK
This patch is not necessary. Doing sizeof() on a NULL structure pointer is allowed. It is valid C.