diff mbox series

dmaengine: loongson1-apb-dma: Fix the build warning caused by the size of pdev_irqname

Message ID 20240831-fix-loongson1-dma-v1-1-91376d87695c@gmail.com (mailing list archive)
State Accepted
Commit e0bee4bcdc3238ebcae6e5960544b9e3d0a62abf
Headers show
Series dmaengine: loongson1-apb-dma: Fix the build warning caused by the size of pdev_irqname | expand

Commit Message

Keguang Zhang via B4 Relay Aug. 31, 2024, 9:41 a.m. UTC
From: Keguang Zhang <keguang.zhang@gmail.com>

drivers/dma/loongson1-apb-dma.c: In function 'ls1x_dma_probe':
drivers/dma/loongson1-apb-dma.c:531:42: warning: '%d' directive writing between 1 and 8 bytes into a region of size 2 [-Wformat-overflow=]
  531 |                 sprintf(pdev_irqname, "ch%d", id);
      |                                          ^~
In function 'ls1x_dma_chan_probe',
    inlined from 'ls1x_dma_probe' at drivers/dma/loongson1-apb-dma.c:605:8:
drivers/dma/loongson1-apb-dma.c:531:39: note: directive argument in the range [0, 19522579]
  531 |                 sprintf(pdev_irqname, "ch%d", id);
      |                                       ^~~~~~
drivers/dma/loongson1-apb-dma.c:531:17: note: 'sprintf' output between 4 and 11 bytes into a destination of size 4
  531 |                 sprintf(pdev_irqname, "ch%d", id);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix the array size and use snprintf() instead of sprintf().

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202408302108.xIR18jmD-lkp@intel.com/
Signed-off-by: Keguang Zhang <keguang.zhang@gmail.com>
---
 drivers/dma/loongson1-apb-dma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


---
base-commit: 985bf40edf4343dcb04c33f58b40b4a85c1776d4
change-id: 20240831-fix-loongson1-dma-f78a3c0d0111

Best regards,

Comments

Vinod Koul Sept. 2, 2024, 8:29 a.m. UTC | #1
On Sat, 31 Aug 2024 17:41:09 +0800, Keguang Zhang wrote:
> drivers/dma/loongson1-apb-dma.c: In function 'ls1x_dma_probe':
> drivers/dma/loongson1-apb-dma.c:531:42: warning: '%d' directive writing between 1 and 8 bytes into a region of size 2 [-Wformat-overflow=]
>   531 |                 sprintf(pdev_irqname, "ch%d", id);
>       |                                          ^~
> In function 'ls1x_dma_chan_probe',
>     inlined from 'ls1x_dma_probe' at drivers/dma/loongson1-apb-dma.c:605:8:
> drivers/dma/loongson1-apb-dma.c:531:39: note: directive argument in the range [0, 19522579]
>   531 |                 sprintf(pdev_irqname, "ch%d", id);
>       |                                       ^~~~~~
> drivers/dma/loongson1-apb-dma.c:531:17: note: 'sprintf' output between 4 and 11 bytes into a destination of size 4
>   531 |                 sprintf(pdev_irqname, "ch%d", id);
>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> [...]

Applied, thanks!

[1/1] dmaengine: loongson1-apb-dma: Fix the build warning caused by the size of pdev_irqname
      commit: e0bee4bcdc3238ebcae6e5960544b9e3d0a62abf

Best regards,
diff mbox series

Patch

diff --git a/drivers/dma/loongson1-apb-dma.c b/drivers/dma/loongson1-apb-dma.c
index ca43c67a8203..255fe7eca212 100644
--- a/drivers/dma/loongson1-apb-dma.c
+++ b/drivers/dma/loongson1-apb-dma.c
@@ -526,9 +526,9 @@  static int ls1x_dma_chan_probe(struct platform_device *pdev,
 
 	for (id = 0; id < dma->nr_chans; id++) {
 		struct ls1x_dma_chan *chan = &dma->chan[id];
-		char pdev_irqname[4];
+		char pdev_irqname[16];
 
-		sprintf(pdev_irqname, "ch%d", id);
+		snprintf(pdev_irqname, sizeof(pdev_irqname), "ch%d", id);
 		chan->irq = platform_get_irq_byname(pdev, pdev_irqname);
 		if (chan->irq < 0)
 			return dev_err_probe(&pdev->dev, chan->irq,