diff mbox series

clk: zynqmp: Replaced strncpy() with strscpy()

Message ID 20210907090920.2620-1-shubhrajyoti.datta@xilinx.com (mailing list archive)
State Superseded, archived
Headers show
Series clk: zynqmp: Replaced strncpy() with strscpy() | expand

Commit Message

Shubhrajyoti Datta Sept. 7, 2021, 9:09 a.m. UTC
Replaced strncpy() with strscpy() as the clock names are supposed to
be NULL terminated.

Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
---
 drivers/clk/zynqmp/clkc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stephen Boyd Sept. 9, 2021, 9:12 p.m. UTC | #1
Quoting Shubhrajyoti Datta (2021-09-07 02:09:20)
> Replaced strncpy() with strscpy() as the clock names are supposed to

And what if they aren't?

> be NULL terminated.
> 
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> ---
>  drivers/clk/zynqmp/clkc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
> index eb25303eefed..40fbd2517016 100644
> --- a/drivers/clk/zynqmp/clkc.c
> +++ b/drivers/clk/zynqmp/clkc.c
> @@ -163,7 +163,7 @@ static int zynqmp_get_clock_name(u32 clk_id, char *clk_name)
>  
>         ret = zynqmp_is_valid_clock(clk_id);
>         if (ret == 1) {
> -               strncpy(clk_name, clock[clk_id].clk_name, MAX_NAME_LEN);
> +               strscpy(clk_name, clock[clk_id].clk_name, MAX_NAME_LEN);
>                 return 0;
>         }
>  
> @@ -712,7 +712,7 @@ static void zynqmp_get_clock_info(void)
>                 zynqmp_pm_clock_get_name(clock[i].clk_id, &name);
>                 if (!strcmp(name.name, RESERVED_CLK_NAME))
>                         continue;
> -               strncpy(clock[i].clk_name, name.name, MAX_NAME_LEN);
> +               strscpy(clock[i].clk_name, name.name, MAX_NAME_LEN);
>         }
>  
>         /* Get topology of all clock */
> -- 
> 2.17.1
>
Shubhrajyoti Datta Oct. 5, 2021, 11:37 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Boyd <sboyd@kernel.org>
> Sent: Friday, September 10, 2021 2:43 AM
> To: Shubhrajyoti Datta <shubhraj@xilinx.com>; linux-clk@vger.kernel.org
> Cc: git-dev <git-dev@xilinx.com>; Michal Simek <michals@xilinx.com>
> Subject: Re: [PATCH] clk: zynqmp: Replaced strncpy() with strscpy()
> 
> Quoting Shubhrajyoti Datta (2021-09-07 02:09:20)
> > Replaced strncpy() with strscpy() as the clock names are supposed to
> 
> And what if they aren't?

That is taken care in 
https://www.spinics.net/lists/linux-clk/msg60505.html
where we are affixing null.
> 
> > be NULL terminated.
> >
diff mbox series

Patch

diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
index eb25303eefed..40fbd2517016 100644
--- a/drivers/clk/zynqmp/clkc.c
+++ b/drivers/clk/zynqmp/clkc.c
@@ -163,7 +163,7 @@  static int zynqmp_get_clock_name(u32 clk_id, char *clk_name)
 
 	ret = zynqmp_is_valid_clock(clk_id);
 	if (ret == 1) {
-		strncpy(clk_name, clock[clk_id].clk_name, MAX_NAME_LEN);
+		strscpy(clk_name, clock[clk_id].clk_name, MAX_NAME_LEN);
 		return 0;
 	}
 
@@ -712,7 +712,7 @@  static void zynqmp_get_clock_info(void)
 		zynqmp_pm_clock_get_name(clock[i].clk_id, &name);
 		if (!strcmp(name.name, RESERVED_CLK_NAME))
 			continue;
-		strncpy(clock[i].clk_name, name.name, MAX_NAME_LEN);
+		strscpy(clock[i].clk_name, name.name, MAX_NAME_LEN);
 	}
 
 	/* Get topology of all clock */