From: Xixin Liu <liuxixin@kylinos.cn>
To: linuxppc-dev@lists.ozlabs.org
Cc: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
chleroy@kernel.org, linux-kernel@vger.kernel.org,
liuxixin@kylinos.cn
Subject: [PATCH v1 2/4] powerpc/powernv: opal-imc: fix debugfs name buffer size
Date: Fri, 07 Aug 2026 11:11:14 +0800 [thread overview]
Message-ID: <prpppc02opali.1786072274.git.liuxixin@kylinos.cn> (raw)
In-Reply-To: <cover.1786072274.git.liuxixin@kylinos.cn>
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 <liuxixin@kylinos.cn>
---
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
next prev parent reply other threads:[~2026-08-07 12:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 3:11 [PATCH v1 0/4] powerpc: assorted fixes (gpci, imc, energy, iommu) Xixin Liu
2026-08-07 3:11 ` [PATCH v1 4/4] powerpc/iommu: fix debugfs name buffer for 64-bit it_index Xixin Liu
2026-08-07 3:11 ` Xixin Liu [this message]
2026-08-07 3:11 ` [PATCH v1 3/4] powerpc/pseries: energy: bound H_BEST_ENERGY cnt and sysfs output Xixin Liu
2026-08-07 3:11 ` [PATCH v1 1/4] powerpc/perf: hv-gpci: bound sysfs hex formatting to PAGE_SIZE Xixin Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=prpppc02opali.1786072274.git.liuxixin@kylinos.cn \
--to=liuxixin@kylinos.cn \
--cc=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox