Skip to contentSkip to conversation

kvargs: fix processing a null list

PATCH In review Thomas Monjalon 2 participants 3 messages Oct 23, 2018 – Oct 24, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvargs: fix processing a null list

In the doxygen description of rte_kvargs_process(), it is said:
If *kvlist* is NULL function does nothing.
It has been added by mistake here instead of rte_kvargs_free(). Anyway, null list should be correctly handled in both functions.

Comments are fixed in both functions and NULL handling is added to rte_kvargs_process().

Fixes c34af7424e09 ("kvargs: fix freeing behaviour for null")
---
 lib/librte_kvargs/rte_kvargs.c | 3 +++
 lib/librte_kvargs/rte_kvargs.h | 7 +++----
 2 files changed, 6 insertions(+), 4 deletions(-)
lib/librte_kvargs/rte_kvargs.c +3 -0
index 427bfd5e5..f371bc5a0 100644
@@ -138,6 +138,9 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,
 	bool match = false;
 	unsigned i;
 
+	if (kvlist == NULL)
+		return 0;
+
 	for (i = 0; i < kvlist->count; i++) {
 		pair = &kvlist->pairs[i];
 		if (key_match == NULL || strcmp(pair->key, key_match) == 0) {
lib/librte_kvargs/rte_kvargs.h +3 -4
index c7378b4e9..c7a97a8eb 100644
@@ -110,7 +110,7 @@ struct rte_kvargs *rte_kvargs_parse_delim(const char *args,
  * rte_kvargs_parse().
  *
  * @param kvlist
- *   The rte_kvargs structure
+ *   The rte_kvargs structure. No error if NULL.
  */
 void rte_kvargs_free(struct rte_kvargs *kvlist);
 
@@ -119,11 +119,10 @@ void rte_kvargs_free(struct rte_kvargs *kvlist);
  *
  * For each key/value association that matches the given key, calls the
  * handler function with the for a given arg_name passing the value on the
- * dictionary for that key and a given extra argument. If *kvlist* is NULL
- * function does nothing.
+ * dictionary for that key and a given extra argument.
  *
  * @param kvlist
- *   The rte_kvargs structure
+ *   The rte_kvargs structure. No error if NULL.
  * @param key_match
  *   The key on which the handler should be called, or NULL to process handler
  *   on all associations
Signature · 1 line
2.19.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Thomas Monjalon

In the doxygen description of rte_kvargs_process(), it is said:
If *kvlist* is NULL function does nothing.
It has been added by mistake here instead of rte_kvargs_free(). Anyway, null list should be correctly handled in both functions.

Quoted 7 lines

Comments are fixed in both functions and NULL handling is added to rte_kvargs_process().

Fixes c34af7424e09 ("kvargs: fix freeing behaviour for null")

lib/librte_kvargs/rte_kvargs.h void rte_kvargs_free(struct rte_kvargs *kvlist); · line 122

Quoted 7 lines
lib/librte_kvargs/rte_kvargs.h +1 -2
@@ -119,11 +119,10 @@ void rte_kvargs_free(struct rte_kvargs *kvlist);
  *
  * For each key/value association that matches the given key, calls the
  * handler function with the for a given arg_name passing the value on the
- * dictionary for that key and a given extra argument. If *kvlist* is NULL
- * function does nothing.
+ * dictionary for that key and a given extra argument.

It looks the rest of the api documentation is perfectible :) I'll send a fix in another patch.

Thanks,
Olivier

author Applied
#2 lore raw

24/10/2018 11:34, Olivier Matz:

Quoted 9 lines · Thomas Monjalon
Quoted 8 lines

In the doxygen description of rte_kvargs_process(), it is said:
If *kvlist* is NULL function does nothing.
It has been added by mistake here instead of rte_kvargs_free(). Anyway, null list should be correctly handled in both functions.

Comments are fixed in both functions and NULL handling is added to rte_kvargs_process().

Quoted 6 lines
Quoted 4 lines
Fixes c34af7424e09 ("kvargs: fix freeing behaviour for null")

Applied

Quoted 10 lines

lib/librte_kvargs/rte_kvargs.h void rte_kvargs_free(struct rte_kvargs *kvlist); · line 122

Quoted 7 lines
lib/librte_kvargs/rte_kvargs.h +1 -2
@@ -119,11 +119,10 @@ void rte_kvargs_free(struct rte_kvargs *kvlist);
  *
  * For each key/value association that matches the given key, calls the
  * handler function with the for a given arg_name passing the value on the
- * dictionary for that key and a given extra argument. If *kvlist* is NULL
- * function does nothing.
+ * dictionary for that key and a given extra argument.

It looks the rest of the api documentation is perfectible :) I'll send a fix in another patch.

Yes please :)