Skip to content

Commit c4d6dcb

Browse files
prabhakarladvinodkoul
authored andcommitted
dmaengine: sh: rz-dmac: Avoid format-overflow warning
The max channel count for RZ DMAC is 16, hence use u8 instead of unsigned int and make the pdev_irqname string long enough to avoid the warning. This fixes the below issue: drivers/dma/sh/rz-dmac.c: In function ‘rz_dmac_probe’: drivers/dma/sh/rz-dmac.c:770:34: warning: ‘%u’ directive writing between 1 and 10 bytes into a region of size 3 [-Wformat-overflow=] 770 | sprintf(pdev_irqname, "ch%u", index); | ^~ In function ‘rz_dmac_chan_probe’, inlined from ‘rz_dmac_probe’ at drivers/dma/sh/rz-dmac.c:910:9: drivers/dma/sh/rz-dmac.c:770:31: note: directive argument in the range [0, 4294967294] 770 | sprintf(pdev_irqname, "ch%u", index); | ^~~~~~ drivers/dma/sh/rz-dmac.c:770:9: note: ‘sprintf’ output between 4 and 13 bytes into a destination of size 5 770 | sprintf(pdev_irqname, "ch%u", index); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ While at it use scnprintf() instead of sprintf() to make the code more robust. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/r/20240110222717.193719-1-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 98373a2 commit c4d6dcb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/dma/sh/rz-dmac.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,19 +755,19 @@ static struct dma_chan *rz_dmac_of_xlate(struct of_phandle_args *dma_spec,
755755

756756
static int rz_dmac_chan_probe(struct rz_dmac *dmac,
757757
struct rz_dmac_chan *channel,
758-
unsigned int index)
758+
u8 index)
759759
{
760760
struct platform_device *pdev = to_platform_device(dmac->dev);
761761
struct rz_lmdesc *lmdesc;
762-
char pdev_irqname[5];
762+
char pdev_irqname[6];
763763
char *irqname;
764764
int ret;
765765

766766
channel->index = index;
767767
channel->mid_rid = -EINVAL;
768768

769769
/* Request the channel interrupt. */
770-
sprintf(pdev_irqname, "ch%u", index);
770+
scnprintf(pdev_irqname, sizeof(pdev_irqname), "ch%u", index);
771771
channel->irq = platform_get_irq_byname(pdev, pdev_irqname);
772772
if (channel->irq < 0)
773773
return channel->irq;
@@ -845,9 +845,9 @@ static int rz_dmac_probe(struct platform_device *pdev)
845845
struct dma_device *engine;
846846
struct rz_dmac *dmac;
847847
int channel_num;
848-
unsigned int i;
849848
int ret;
850849
int irq;
850+
u8 i;
851851

852852
dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL);
853853
if (!dmac)

0 commit comments

Comments
 (0)