Skip to contentSkip to conversation

PCI: dwc: Fix potential truncation in dw_pcie_edma_irq_verify()

PATCH Applied Niklas Cassel 3 participants 5 messages Jan 4, 2025 – Jan 15, 2025

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

PATCH v3 1/1 PCI: dwc: Fix potential truncation in dw_pcie_edma_irq_verify()

Increase the size of the string buffer to avoid potential truncation in dw_pcie_edma_irq_verify().

This fixes the following build warning when compiling with W=1:

drivers/pci/controller/dwc/pcie-designware.c: In function ‘dw_pcie_edma_detect’:
drivers/pci/controller/dwc/pcie-designware.c:989:50: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
989 | snprintf(name, sizeof(name), "dma%d", pci->edma.nr_irqs);
| ^~

---
Changes since v2:
-Simply increase the size of the string buffer instead of chaning the
print format specifier.

 drivers/pci/controller/dwc/pcie-designware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware.c +1 -1
index 3c683b6119c3..145e7f579072 100644
@@ -971,7 +971,7 @@ static int dw_pcie_edma_irq_verify(struct dw_pcie *pci)
 {
 	struct platform_device *pdev = to_platform_device(pci->dev);
 	u16 ch_cnt = pci->edma.ll_wr_cnt + pci->edma.ll_rd_cnt;
-	char name[6];
+	char name[15];
 	int ret;
 
 	if (pci->edma.nr_irqs == 1)
Signature · 1 line
2.47.1
#1 lore raw
Quoted 24 lines · Niklas Cassel

Increase the size of the string buffer to avoid potential truncation in dw_pcie_edma_irq_verify().

This fixes the following build warning when compiling with W=1:

drivers/pci/controller/dwc/pcie-designware.c: In function ‘dw_pcie_edma_detect’:
drivers/pci/controller/dwc/pcie-designware.c:989:50: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
989 | snprintf(name, sizeof(name), "dma%d", pci->edma.nr_irqs);
| ^~

---
Changes since v2:

(quoted diff) +0 -1
-Simply increase the size of the string buffer instead of chaning the
 print format specifier.
 
 drivers/pci/controller/dwc/pcie-designware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware.c +0 -0
index 3c683b6119c3..145e7f579072 100644

drivers/pci/controller/dwc/pcie-designware.c static int dw_pcie_edma_irq_verify(struct dw_pcie *pci) · line 974

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
@@ -971,7 +971,7 @@ static int dw_pcie_edma_irq_verify(struct dw_pcie *pci)
 {
 	struct platform_device *pdev = to_platform_device(pci->dev);
 	u16 ch_cnt = pci->edma.ll_wr_cnt + pci->edma.ll_rd_cnt;
-	char name[6];
+	char name[15];

Isn't 14 big enough to hold INT_MAX + 'dma'? Not a big deal, but asking just for the sake of correctness.

- Mani

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -0
 	int ret;
 
 	if (pci->edma.nr_irqs == 1)
Signature · 1 line
2.47.1
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#2 lore raw
Quoted 20 lines · Manivannan Sadhasivam
Quoted 19 lines · Niklas Cassel

Increase the size of the string buffer to avoid potential truncation in dw_pcie_edma_irq_verify().

This fixes the following build warning when compiling with W=1:

drivers/pci/controller/dwc/pcie-designware.c: In function ‘dw_pcie_edma_detect’:
drivers/pci/controller/dwc/pcie-designware.c:989:50: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
989 | snprintf(name, sizeof(name), "dma%d", pci->edma.nr_irqs);
| ^~

---
Changes since v2:
-Simply increase the size of the string buffer instead of chaning the
print format specifier.

 drivers/pci/controller/dwc/pcie-designware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/pci/controller/dwc/pcie-designware.c static int dw_pcie_edma_irq_verify(struct dw_pcie *pci) · line 974

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
index 3c683b6119c3..145e7f579072 100644
@@ -971,7 +971,7 @@ static int dw_pcie_edma_irq_verify(struct dw_pcie *pci)
 {
 	struct platform_device *pdev = to_platform_device(pci->dev);
 	u16 ch_cnt = pci->edma.ll_wr_cnt + pci->edma.ll_rd_cnt;
-	char name[6];
+	char name[15];

Isn't 14 big enough to hold INT_MAX + 'dma'? Not a big deal, but asking just for the sake of correctness.

We need to be able to hold INT_MIN which is "-2147483648" 11 chars/bytes
+ "dma" 3 chars/bytes + terminating null byte (1 char/byte) = 15.

Kind regards,
Niklas

#3 lore raw
Quoted 35 lines · Niklas Cassel
Quoted 20 lines · Manivannan Sadhasivam
Quoted 19 lines · Niklas Cassel

Increase the size of the string buffer to avoid potential truncation in dw_pcie_edma_irq_verify().

This fixes the following build warning when compiling with W=1:

drivers/pci/controller/dwc/pcie-designware.c: In function ‘dw_pcie_edma_detect’:
drivers/pci/controller/dwc/pcie-designware.c:989:50: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
989 | snprintf(name, sizeof(name), "dma%d", pci->edma.nr_irqs);
| ^~

---
Changes since v2:
-Simply increase the size of the string buffer instead of chaning the
print format specifier.

 drivers/pci/controller/dwc/pcie-designware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/pci/controller/dwc/pcie-designware.c static int dw_pcie_edma_irq_verify(struct dw_pcie *pci) · line 974

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
index 3c683b6119c3..145e7f579072 100644
@@ -971,7 +971,7 @@ static int dw_pcie_edma_irq_verify(struct dw_pcie *pci)
 {
 	struct platform_device *pdev = to_platform_device(pci->dev);
 	u16 ch_cnt = pci->edma.ll_wr_cnt + pci->edma.ll_rd_cnt;
-	char name[6];
+	char name[15];

Isn't 14 big enough to hold INT_MAX + 'dma'? Not a big deal, but asking just for the sake of correctness.

Quoted 3 lines

We need to be able to hold INT_MIN which is "-2147483648" 11 chars/bytes
+ "dma" 3 chars/bytes + terminating null byte (1 char/byte) = 15.

Ah, brain fade (missing the null byte termination).

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#4 lore raw
In reply to Niklas Cassel

Hello,

Quoted 9 lines

Increase the size of the string buffer to avoid potential truncation in dw_pcie_edma_irq_verify().

This fixes the following build warning when compiling with W=1:

drivers/pci/controller/dwc/pcie-designware.c: In function ‘dw_pcie_edma_detect’:
drivers/pci/controller/dwc/pcie-designware.c:989:50: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
989 | snprintf(name, sizeof(name), "dma%d", pci->edma.nr_irqs);
| ^~

Applied to controller/dwc for v6.14, thank you!

Krzysztof