The Linux Kernel Mailing List
 help / color / mirror / Atom feed
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 4/4] powerpc/iommu: fix debugfs name buffer for 64-bit it_index
Date: Fri, 07 Aug 2026 11:11:14 +0800	[thread overview]
Message-ID: <prpppc04iommu.1786072274.git.liuxixin@kylinos.cn> (raw)
In-Reply-To: <cover.1786072274.git.liuxixin@kylinos.cn>

iommu debugfs names sprintf() "%08lx" into char name[10]. The "8" in
%08lx is a minimum width, so a 64-bit it_index can need up to 16 hex
digits plus NUL.

Size the buffer for an unsigned long and use snprintf.

Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index ee1b5cb557c9..e8f48aef7832 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -53,10 +53,11 @@
 
 static void iommu_debugfs_add(struct iommu_table *tbl)
 {
-	char name[10];
+	/* unsigned long hex + NUL; %08lx is a minimum width only */
+	char name[2 * sizeof(unsigned long) + 1];
 	struct dentry *liobn_entry;
 
-	sprintf(name, "%08lx", tbl->it_index);
+	snprintf(name, sizeof(name), "%08lx", tbl->it_index);
 	liobn_entry = debugfs_create_dir(name, iommu_debugfs_dir);
 
 	debugfs_create_file_unsafe("weight", 0400, liobn_entry, tbl, &iommu_debugfs_fops_weight);
@@ -70,9 +71,9 @@
 
 static void iommu_debugfs_del(struct iommu_table *tbl)
 {
-	char name[10];
+	char name[2 * sizeof(unsigned long) + 1];
 
-	sprintf(name, "%08lx", tbl->it_index);
+	snprintf(name, sizeof(name), "%08lx", tbl->it_index);
 	debugfs_lookup_and_remove(name, iommu_debugfs_dir);
 }
 #else
-- 
2.43.0


  reply	other threads:[~2026-08-07  3:31 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 ` Xixin Liu [this message]
2026-08-07  3:11 ` [PATCH v1 1/4] powerpc/perf: hv-gpci: bound sysfs hex formatting to PAGE_SIZE Xixin Liu
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 2/4] powerpc/powernv: opal-imc: fix debugfs name buffer 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=prpppc04iommu.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