[v9,3/5] net/virtio-user: fix devargs parsing

Message ID 20200406085855.25773-4-i.dyukov@samsung.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio: add link speed devarg |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Ivan Dyukov April 6, 2020, 8:58 a.m. UTC
  strtoull returns 0 if it fails to parse input string. It's ignored
in get_integer_arg.

This patch handles error cases for strtoull function.

Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
---
 drivers/net/virtio/virtio_user_ethdev.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
  

Comments

Maxime Coquelin April 15, 2020, 3:09 p.m. UTC | #1
On 4/6/20 10:58 AM, Ivan Dyukov wrote:
> strtoull returns 0 if it fails to parse input string. It's ignored
> in get_integer_arg.
> 
> This patch handles error cases for strtoull function.

Fixes: ce2eabdd43ec ("net/virtio-user: add virtual device")
Cc: stable@dpdk.org

> 
> Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
> ---
>  drivers/net/virtio/virtio_user_ethdev.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
> index e61af4068..a79f68a36 100644
> --- a/drivers/net/virtio/virtio_user_ethdev.c
> +++ b/drivers/net/virtio/virtio_user_ethdev.c
> @@ -477,12 +477,17 @@ 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;
> -
> -	*(uint64_t *)extra_args = strtoull(value, NULL, 0);
> -
> -	return 0;
> +	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_eth_dev *
> 

I will fix the commit message when applying.

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index e61af4068..a79f68a36 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -477,12 +477,17 @@  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;
-
-	*(uint64_t *)extra_args = strtoull(value, NULL, 0);
-
-	return 0;
+	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_eth_dev *