diff mbox series

[8/8] xilinx: zynqmp: Remove one static variable

Message ID 71e724c400e2a517a70a31870403d1ecfc7e9a25.1596626630.git.michal.simek@xilinx.com
State New
Delegated to: Michal Simek
Headers show
Series xilinx: zynqmp: Silicon name cleanup | expand

Commit Message

Michal Simek Aug. 5, 2020, 11:23 a.m. UTC
There is no reason to have name variable saved in BSS section when it
doesn't need to be really used. That's why remove static from variable
definition and use strdup() to duplicate string with exact size from malloc
area instead.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 board/xilinx/zynqmp/zynqmp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Michal Simek Aug. 19, 2020, 7:38 a.m. UTC | #1
st 5. 8. 2020 v 13:24 odesílatel Michal Simek <michal.simek@xilinx.com> napsal:
>
> There is no reason to have name variable saved in BSS section when it
> doesn't need to be really used. That's why remove static from variable
> definition and use strdup() to duplicate string with exact size from malloc
> area instead.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
>  board/xilinx/zynqmp/zynqmp.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
> index 383125087255..e8ea3c5a4975 100644
> --- a/board/xilinx/zynqmp/zynqmp.c
> +++ b/board/xilinx/zynqmp/zynqmp.c
> @@ -155,7 +155,7 @@ static char *zynqmp_get_silicon_idcode_name(void)
>  {
>         u32 i;
>         u32 idcode, idcode2;
> -       static char name[ZYNQMP_VERSION_SIZE];
> +       char name[ZYNQMP_VERSION_SIZE];
>         u32 ret_payload[PAYLOAD_ARG_CNT];
>
>         xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
> @@ -183,7 +183,7 @@ static char *zynqmp_get_silicon_idcode_name(void)
>                 return "unknown";
>
>         /* Add device prefix to the name */
> -       strncat(name, "zu", 2);
> +       strncpy(name, "zu", ZYNQMP_VERSION_SIZE);
>         strncat(&name[2], simple_itoa(zynqmp_devices[i].device), 2);
>
>         if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EV) {
> @@ -233,7 +233,7 @@ static char *zynqmp_get_silicon_idcode_name(void)
>                 debug("Variant not identified\n");
>         }
>
> -       return name;
> +       return strdup(name);
>  }
>  #endif
>
> --
> 2.27.0
>

This patch depends on 6/8 that's why please ignore it too.

Thanks,
Michal
diff mbox series

Patch

diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 383125087255..e8ea3c5a4975 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -155,7 +155,7 @@  static char *zynqmp_get_silicon_idcode_name(void)
 {
 	u32 i;
 	u32 idcode, idcode2;
-	static char name[ZYNQMP_VERSION_SIZE];
+	char name[ZYNQMP_VERSION_SIZE];
 	u32 ret_payload[PAYLOAD_ARG_CNT];
 
 	xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
@@ -183,7 +183,7 @@  static char *zynqmp_get_silicon_idcode_name(void)
 		return "unknown";
 
 	/* Add device prefix to the name */
-	strncat(name, "zu", 2);
+	strncpy(name, "zu", ZYNQMP_VERSION_SIZE);
 	strncat(&name[2], simple_itoa(zynqmp_devices[i].device), 2);
 
 	if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EV) {
@@ -233,7 +233,7 @@  static char *zynqmp_get_silicon_idcode_name(void)
 		debug("Variant not identified\n");
 	}
 
-	return name;
+	return strdup(name);
 }
 #endif