get_integer_arg() never checks the end pointer and returns -errno, so a
malformed value such as "abc" leaves errno untouched, converts to zero
and is reported as success. It also used base 0, so a leading zero
silently selected octal.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 drivers/crypto/virtio/virtio_user_cryptodev.c | 21 ++-----------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/crypto/virtio/virtio_user_cryptodev.c 
b/drivers/crypto/virtio/virtio_user_cryptodev.c
index 4daa188e1d..9844debeaf 100644
--- a/drivers/crypto/virtio/virtio_user_cryptodev.c
+++ b/drivers/crypto/virtio/virtio_user_cryptodev.c
@@ -345,23 +345,6 @@ get_string_arg(const char *key __rte_unused,
        return 0;
 }
 
-static int
-get_integer_arg(const char *key __rte_unused,
-               const char *value, void *extra_args)
-{
-       uint64_t integer = 0;
-       if (!value || !extra_args)
-               return -EINVAL;
-       errno = 0;
-       integer = strtoull(value, NULL, 0);
-       /* extra_args keeps default value, it should be replaced
-        * only in case of successful parsing of the 'value' arg
-        */
-       if (errno == 0)
-               *(uint64_t *)extra_args = integer;
-       return -errno;
-}
-
 static struct rte_cryptodev *
 virtio_user_cryptodev_alloc(struct rte_vdev_device *vdev)
 {
@@ -432,7 +415,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
 
        if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUES_NUM) == 1) {
                if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUES_NUM,
-                                       &get_integer_arg, &queues) < 0) {
+                                       rte_kvargs_handle_u64, &queues) < 0) {
                        PMD_INIT_LOG(ERR, "error to parse %s",
                                        VIRTIO_USER_ARG_QUEUES_NUM);
                        goto end;
@@ -441,7 +424,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
 
        if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE) == 1) {
                if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE,
-                                       &get_integer_arg, &queue_size) < 0) {
+                                       rte_kvargs_handle_u64, &queue_size) < 
0) {
                        PMD_INIT_LOG(ERR, "error to parse %s",
                                        VIRTIO_USER_ARG_QUEUE_SIZE);
                        goto end;
-- 
2.53.0

Reply via email to