[PATCH v1 2/4] powerpc/powernv: opal-imc: fix debugfs name buffer size

Xixin Liu <[email protected]>
Newsgroups org.ozlabs.lists.linuxppc-dev,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
char mode[16]/cmd[16] are too small for sprintf("imc_mode_%d") /
sprintf("imc_cmd_%d") when id is a full u32 (up to 20 bytes including NUL).

id comes from DT "chip-id" as u32. Enlarge the buffers and use snprintf.

Signed-off-by: Xixin Liu <[email protected]>
---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index b3fd5c648dea..77de53d47cb6 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -51,7 +51,8 @@
 				    struct imc_pmu *pmu_ptr)
 {
 	static u64 loc, *imc_mode_addr, *imc_cmd_addr;
-	char mode[16], cmd[16];
+	/* "imc_mode_" / "imc_cmd_" + max u32 decimal + NUL */
+	char mode[20], cmd[20];
 	u32 cb_offset;
 	struct imc_mem_info *ptr = pmu_ptr->mem_info;
 
@@ -63,12 +64,12 @@
 	while (ptr->vbase != NULL) {
 		loc = (u64)(ptr->vbase) + cb_offset;
 		imc_mode_addr = (u64 *)(loc + IMC_CNTL_BLK_MODE_OFFSET);
-		sprintf(mode, "imc_mode_%d", (u32)(ptr->id));
+		snprintf(mode, sizeof(mode), "imc_mode_%u", ptr->id);
 		imc_debugfs_create_x64(mode, 0600, imc_debugfs_parent,
 				       imc_mode_addr);
 
 		imc_cmd_addr = (u64 *)(loc + IMC_CNTL_BLK_CMD_OFFSET);
-		sprintf(cmd, "imc_cmd_%d", (u32)(ptr->id));
+		snprintf(cmd, sizeof(cmd), "imc_cmd_%u", ptr->id);
 		imc_debugfs_create_x64(cmd, 0600, imc_debugfs_parent,
 				       imc_cmd_addr);
 		ptr++;
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.