[04/25] raw/ifpga: replace snprintf with strlcpy

Message ID 20230601150106.18375-5-stephen@networkplumber.org (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series replace snprintf with strlcpy |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger June 1, 2023, 3 p.m. UTC
  Suggested by devtools/cocci/strlcpy-with-header.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/raw/ifpga/afu_pmd_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Xu, Rosen June 2, 2023, 6:04 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, June 1, 2023 11:01 PM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Xu, Rosen
> <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>
> Subject: [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy
> 
> Suggested by devtools/cocci/strlcpy-with-header.cocci
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/raw/ifpga/afu_pmd_core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/afu_pmd_core.c
> b/drivers/raw/ifpga/afu_pmd_core.c
> index 3ab1f47ac1a4..e969897dbe7d 100644
> --- a/drivers/raw/ifpga/afu_pmd_core.c
> +++ b/drivers/raw/ifpga/afu_pmd_core.c
> @@ -16,6 +16,7 @@
>  #include <rte_malloc.h>
>  #include <rte_memzone.h>
>  #include <rte_rawdev_pmd.h>
> +#include <rte_string_fns.h>
> 
>  #include "afu_pmd_core.h"
> 
> @@ -225,7 +226,7 @@ static int afu_shared_data_alloc(const char *name,
>  		return -EINVAL;
> 
>  	/* name format is afu_?|??:??.? which is unique */
> -	snprintf(mz_name, sizeof(mz_name), "%s", name);
> +	strlcpy(mz_name, name, sizeof(mz_name));
> 
>  	mz = rte_memzone_lookup(mz_name);
>  	if (!mz) {
> --
> 2.39.2

Reviewed-by: Rosen Xu <rosen.xu@intel.com>
  

Patch

diff --git a/drivers/raw/ifpga/afu_pmd_core.c b/drivers/raw/ifpga/afu_pmd_core.c
index 3ab1f47ac1a4..e969897dbe7d 100644
--- a/drivers/raw/ifpga/afu_pmd_core.c
+++ b/drivers/raw/ifpga/afu_pmd_core.c
@@ -16,6 +16,7 @@ 
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_rawdev_pmd.h>
+#include <rte_string_fns.h>
 
 #include "afu_pmd_core.h"
 
@@ -225,7 +226,7 @@  static int afu_shared_data_alloc(const char *name,
 		return -EINVAL;
 
 	/* name format is afu_?|??:??.? which is unique */
-	snprintf(mz_name, sizeof(mz_name), "%s", name);
+	strlcpy(mz_name, name, sizeof(mz_name));
 
 	mz = rte_memzone_lookup(mz_name);
 	if (!mz) {