Commit Graph

12 Commits

Author SHA1 Message Date
Bruce Richardson
0615355ffa kvargs: make pointers in string arrays const
Change the parameters of functions from const char *valid[] to
const char * const valid[]. This additional const is needed to
allow us to fix some checkpatch warnings, as well as being good
programming practice.

For the checkpatch warnings, if we have a set of command line
args that we want to check defined as:
	static const char *args[] = { "arg1", "arg2", NULL };
	kvlist = rte_kvargs_parse(params, args);

checkpatch will complain:
	WARNING:STATIC_CONST_CHAR_ARRAY: static const char *
	array should probably be static const char * const

Adding the additional const to the definition of the args
will then trigger a compiler error in the absence of this
change to the kvargs library, as we lose the const in the
call to kvargs_parse.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
2017-01-13 19:28:26 +01:00
David Marchand
c7985de0a7 remove unneeded tests for NULL when freeing
free() already handles NULL pointer.

Signed-off-by: David Marchand <david.marchand@6wind.com>
2016-01-27 15:34:48 +01:00
Pawel Wodkowski
c34af7424e kvargs: fix freeing behaviour for null
By convention free() functions should ignore NULL parameter. This patch
add this behaviour for rte_kvargs_free().

Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
2015-03-04 11:19:37 +01:00
Min Cao
1122f06c42 kvargs: fix build with gcc 4.5.1
GCC 4.5.1 warns about an uninitialized pointer:
	error: 'ctx1' may be used uninitialized in this function

Signed-off-by: Min Cao <min.cao@intel.com>
Acked-by: Jijiang Liu <jijiang.liu@intel.com>
Tested-by: Waterman Cao <waterman.cao@intel.com>
2014-06-17 19:01:59 +02:00
Olivier Matz
38a901702f kvargs: make the NULL key to match all entries
In rte_kvargs_process() and rte_kvargs_count(), if the key_match
argument is NULL, process all entries.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:14 +01:00
Olivier Matz
95418a30be kvargs: add the key in handler pameters
This argument can be useful when rte_kvargs_process() is called with
key=NULL, in this case the handler is invoked for all entries of the
kvlist.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:14 +01:00
Olivier Matz
d24839b318 kvargs: be strict when matching a key
When we match a key in is_valid_key() and rte_kvargs_process(), do a
strict comparison (strcmp()) instead of using strstr(s1, s2) which tries
a find s1 in s2. This old behavior could lead to unexpected match, for
instance "cola" match "chocolate".

Surprisingly, no patch was needed on rte_kvargs_count() as it already
used strcmp().

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:14 +01:00
Olivier Matz
ac15c81315 kvargs: simpler parsing and allow duplicated keys
Remove the rte_kvargs_add_pair() function whose only role was to check
if a key is duplicated. Having duplicated keys is now allowed by kvargs
API.

Also replace rte_strsplit() by more a standard function strtok_r() that
is easier to understand for people already knowing the libc. It also
avoids useless calls to strnlen(). The delimiters macros become strings
instead of chars due to the strtok_r() API.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:14 +01:00
Olivier Matz
ef8e5447e3 kvargs: rework API to fix memory leak
Before the patch, a call to rte_kvargs_tokenize() resulted in a call to
strdup() to allocate a modifiable copy of the argument string. This
string was never freed, excepted in the error cases of
rte_kvargs_tokenize() where rte_free() was wrongly called instead of
free(). In other cases, freeing this string was impossible as the
pointer not saved.

This patch introduces rte_kvargs_free() in order to free the structure
properly. The pointer to the duplicated string is now kept in the
rte_kvargs structure. A call to rte_kvargs_parse() directly allocates
the structure, making rte_kvargs_init() useless.

The only drawback of this API change is that a key/value associations
cannot be added to an existing kvlist. But it's not used today, and
there is not obvious use case for that.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:14 +01:00
Olivier Matz
03b611b713 kvargs: remove useless size field
This value was not very useful as the size of the table is fixed (equals
RTE_KVARGS_MAX).

By the way, the memset in the initialization function was wrong (size
too short). Even if it was not really an issue since we rely on the
"count" field, it is now fixed by this patch.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:14 +01:00
Olivier Matz
991543e815 kvargs: remove driver name in arguments
Now that rte_kvargs is a generic library, there is no need to have an argument
for the driver name in rte_kvargs_tokenize() and rte_kvargs_parse()
prototypes. This argument was only used to log the driver name in case of
error. Instead, we can add a log in init function of pmd_pcap and pmd_ring.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:14 +01:00
Olivier Matz
e1a00536c8 kvargs: add a new library to parse key/value arguments
Copy the code from rte_eth_pcap_arg_parser.[ch], without any functional
modifications, only:
- rename functions and structure
- restyle (indentation)
- add comments (doxygen style)
- add "const" or "static" attributes, remove unneeded "inline"

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2014-02-26 11:01:13 +01:00