Skip to contentSkip to conversation

iommu/vt-d: Increase buffer size for device name

PATCH Applied Andy Shevchenko 2 participants 2 messages Oct 14, 2024 – Oct 29, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/vt-d: Increase buffer size for device name

GCC is not happy with the current code, e.g.:

.../iommu/intel/dmar.c:1063:9: note: ‘sprintf’ output between 6 and 15 bytes into a destination of size 13
1063 | sprintf(iommu->name, "dmar%d", iommu->seq_id);

When make W=1 is supplied, this prevents kernel building. Fix it by increasing the buffer size for device name and use sizeoF() instead of hard coded constants.

---
 drivers/iommu/intel/dmar.c  | 2 +-
 drivers/iommu/intel/iommu.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/dmar.c +1 -1
index eaf862e8dea1..e16c2b1d7633 100644
@@ -1060,7 +1060,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
 		err = iommu->seq_id;
 		goto error;
 	}
-	sprintf(iommu->name, "dmar%d", iommu->seq_id);
+	snprintf(iommu->name, sizeof(iommu->name), "dmar%d", iommu->seq_id);
 
 	err = map_iommu(iommu, drhd);
 	if (err) {
drivers/iommu/intel/iommu.h +1 -1
index 1497f3112b12..61701c1c22d3 100644
@@ -720,7 +720,7 @@ struct intel_iommu {
 	int		msagaw; /* max sagaw of this iommu */
 	unsigned int	irq, pr_irq, perf_irq;
 	u16		segment;     /* PCI segment# */
-	unsigned char 	name[13];    /* Device Name */
+	unsigned char 	name[16];    /* Device Name */
 
 #ifdef CONFIG_INTEL_IOMMU
 	unsigned long 	*domain_ids; /* bitmap of domains */
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Applied
#1 lore raw
Quoted 9 lines · Andy Shevchenko

GCC is not happy with the current code, e.g.:

.../iommu/intel/dmar.c:1063:9: note: ‘sprintf’ output between 6 and 15 bytes into a destination of size 13
1063 | sprintf(iommu->name, "dmar%d", iommu->seq_id);

When make W=1 is supplied, this prevents kernel building. Fix it by increasing the buffer size for device name and use sizeoF() instead of hard coded constants.

Quoted 5 lines
---
  drivers/iommu/intel/dmar.c  | 2 +-
  drivers/iommu/intel/iommu.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

Queued for v6.13. Thank you!

--
baolu