All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: Vinod Koul <vkoul@kernel.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	 Biju Das <biju.das.jz@bp.renesas.com>,
	dmaengine@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org,
	 Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>,
	 Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Subject: Re: [PATCH] dmaengine: sh: rz-dmac: Avoid format-overflow warning
Date: Thu, 11 Jan 2024 10:00:53 +0100	[thread overview]
Message-ID: <CAMuHMdX4bv0dtJ-G1o9by91RmP3DH1HQKvDL51g_25Yq=Yd2LQ@mail.gmail.com> (raw)
In-Reply-To: <20240110222717.193719-1-prabhakar.mahadev-lad.rj@bp.renesas.com>

Hi Prabhakar,

On Wed, Jan 10, 2024 at 11:27 PM Prabhakar <prabhakar.csengg@gmail.com> wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> 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.

Note that the danger lies into someone changing
RZ_DMAC_MAX_CHANNELS later...

> 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>

Some nits below...

> --- a/drivers/dma/sh/rz-dmac.c
> +++ b/drivers/dma/sh/rz-dmac.c
> @@ -845,9 +845,9 @@ static int rz_dmac_probe(struct platform_device *pdev)
>         struct dma_device *engine;
>         struct rz_dmac *dmac;
>         int channel_num;
> -       unsigned int i;
>         int ret;
>         int irq;
> +       u8 i;

Personally, I'm not much a fan of making loop counters smaller than
(unsigned) int.  If you do go this way, you should change channel_num
to u8, too, just like i in rz_dmac_remove().

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

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2024-01-11  9:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 22:27 [PATCH] dmaengine: sh: rz-dmac: Avoid format-overflow warning Prabhakar
2024-01-11  9:00 ` Geert Uytterhoeven [this message]
2024-01-19 12:50 ` Vinod Koul

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='CAMuHMdX4bv0dtJ-G1o9by91RmP3DH1HQKvDL51g_25Yq=Yd2LQ@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=claudiu.beznea.uj@bp.renesas.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=prabhakar.csengg@gmail.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=vkoul@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.