[v1,01/13] common/mlx5: replace strsep with strtok_r

Message ID 20200820145028.4090-1-ophirmu@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series [v1,01/13] common/mlx5: replace strsep with strtok_r |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ophir Munk Aug. 20, 2020, 2:50 p.m. UTC
  From: Ophir Munk <ophirmu@mellanox.com>

strsep() is a non-standardized API (by C or POSIX) and thus it is
non-portable between different operating systems. Replace it with
strtok_r() which is standardized by the C standard, and hence also by
POSIX.
The replacement occurs in the code that extracts individual PCI class
names (e.g. class=net:vdpa:foo:bar).

Signed-off-by: Ophir Munk <ophirmu@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
---
 drivers/common/mlx5/mlx5_common_pci.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
  

Comments

Raslan Darawsheh Aug. 27, 2020, 9:53 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Ophir Munk <ophirmu@mellanox.com>
> Sent: Tuesday, August 25, 2020 12:30 PM
> To: dev@dpdk.org
> Cc: Raslan Darawsheh <rasland@mellanox.com>; Ophir Munk
> <ophirmu@mellanox.com>; Matan Azrad <matan@mellanox.com>; Ophir
> Munk <ophirmu@nvidia.com>
> Subject: [PATCH v2 00/13] mlx5 PMD multi OS support - part #4
> 
> From: Ophir Munk <ophirmu@nvidia.com>
> 
> This patch series is part of preparing mlx5 PMD to compile and run under
> multiple OSs. Part #4
> 
> v1: initial version
> v2: checkpatch fixes
> 
> Ophir Munk (13):
>   common/mlx5: replace strsep with strtok_r
>   common/mlx5: replace Linux __bexx types with rte
>   net/mlx5: rename mlx5 enumeration REG_NONE
>   net/mlx5: move mlx5_get_ifname prototype under Linux
>   net/mlx5: fix removal of unused inclusion files
>   net/mlx5: remove Netlink dependency in shared code
>   net/mlx5: fix unused utility macros
>   net/mlx5: call meter detach only if DR is supported
>   net/mlx5: add ICMP protocol number definition
>   net/mlx5: remove more DV dependencies
>   net/mlx5: remove ibv_* dependency in Rx/Tx objects
>   net/mlx5: separate VLAN strip modification
>   linux/mlx5: refactor VLAN
> 
>  drivers/common/mlx5/linux/mlx5_common_os.h | 111
> +++++++++++++++++++
>  drivers/common/mlx5/mlx5_common_pci.c      |  14 +--
>  drivers/common/mlx5/mlx5_prm.h             |  16 +--
>  drivers/net/mlx5/Makefile                  |   1 +
>  drivers/net/mlx5/linux/meson.build         |   1 +
>  drivers/net/mlx5/linux/mlx5_os.c           |  18 ++++
>  drivers/net/mlx5/linux/mlx5_os.h           |   6 ++
>  drivers/net/mlx5/linux/mlx5_verbs.c        |  28 +++++
>  drivers/net/mlx5/linux/mlx5_vlan_os.c      | 168
> +++++++++++++++++++++++++++++
>  drivers/net/mlx5/mlx5.c                    |  23 ++--
>  drivers/net/mlx5/mlx5.h                    |  30 +++---
>  drivers/net/mlx5/mlx5_devx.c               |  48 +++++++++
>  drivers/net/mlx5/mlx5_devx.h               |  12 +++
>  drivers/net/mlx5/mlx5_flow.c               |  29 +++--
>  drivers/net/mlx5/mlx5_flow_dv.c            |   8 +-
>  drivers/net/mlx5/mlx5_flow_meter.c         |   4 +
>  drivers/net/mlx5/mlx5_mac.c                |   2 -
>  drivers/net/mlx5/mlx5_rxq.c                |  18 ++--
>  drivers/net/mlx5/mlx5_rxtx.h               |  24 ++---
>  drivers/net/mlx5/mlx5_trigger.c            |   3 +-
>  drivers/net/mlx5/mlx5_txpp.c               |  38 ++++---
>  drivers/net/mlx5/mlx5_txq.c                |  19 ++--
>  drivers/net/mlx5/mlx5_utils.h              |   4 -
>  drivers/net/mlx5/mlx5_vlan.c               | 161 +--------------------------
>  24 files changed, 527 insertions(+), 259 deletions(-)
>  create mode 100644 drivers/net/mlx5/linux/mlx5_vlan_os.c
>  create mode 100644 drivers/net/mlx5/mlx5_devx.c
>  create mode 100644 drivers/net/mlx5/mlx5_devx.h
> 
> --
> 2.8.4

Series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c
index d4ff039..02417c6 100644
--- a/drivers/common/mlx5/mlx5_common_pci.c
+++ b/drivers/common/mlx5/mlx5_common_pci.c
@@ -72,6 +72,7 @@  bus_cmdline_options_handler(__rte_unused const char *key,
 	int class_val;
 	char *found;
 	char *nstr;
+	char *refstr = NULL;
 
 	*ret = 0;
 	nstr = strdup(class_names);
@@ -80,21 +81,22 @@  bus_cmdline_options_handler(__rte_unused const char *key,
 		return *ret;
 	}
 	nstr_org = nstr;
-	while (nstr) {
+	found = strtok_r(nstr, ":", &refstr);
+	if (!found)
+		goto err;
+	do {
 		/* Extract each individual class name. Multiple
 		 * class key,value is supplied as class=net:vdpa:foo:bar.
 		 */
-		found = strsep(&nstr, ":");
-		if (!found)
-			continue;
-		/* Check if its a valid class. */
 		class_val = class_name_to_value(found);
+		/* Check if its a valid class. */
 		if (class_val < 0) {
 			*ret = -EINVAL;
 			goto err;
 		}
 		*ret |= class_val;
-	}
+		found = strtok_r(NULL, ":", &refstr);
+	} while (found);
 err:
 	free(nstr_org);
 	if (*ret < 0)