DMA Engine development
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
Cc: "Vinod Koul" <vkoul@kernel.org>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Tudor Ambarus" <tudor.ambarus@linaro.org>,
	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: usb-dmac: Avoid format-overflow warning
Date: Wed, 10 Jan 2024 15:58:18 -0800	[thread overview]
Message-ID: <202401101557.87634A6A@keescook> (raw)
In-Reply-To: <CA+V-a8tdmD7PB1Rp5K9doXKGzSLwhbSAXD1=UisQebUrug507A@mail.gmail.com>

On Wed, Jan 10, 2024 at 10:46:02PM +0000, Lad, Prabhakar wrote:
> Hi Kees,
> 
> Thank you for the review.
> 
> On Wed, Jan 10, 2024 at 10:41 PM Kees Cook <keescook@chromium.org> wrote:
> >
> > On Wed, Jan 10, 2024 at 10:22:10PM +0000, Prabhakar wrote:
> > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> > >
> > > gcc points out that the fix-byte buffer might be too small:
> > > drivers/dma/sh/usb-dmac.c: In function 'usb_dmac_probe':
> > > drivers/dma/sh/usb-dmac.c:720:34: warning: '%u' directive writing between 1 and 10 bytes into a region of size 3 [-Wformat-overflow=]
> > >   720 |         sprintf(pdev_irqname, "ch%u", index);
> > >       |                                  ^~
> > > In function 'usb_dmac_chan_probe',
> > >     inlined from 'usb_dmac_probe' at drivers/dma/sh/usb-dmac.c:814:9:
> > > drivers/dma/sh/usb-dmac.c:720:31: note: directive argument in the range [0, 4294967294]
> > >   720 |         sprintf(pdev_irqname, "ch%u", index);
> > >       |                               ^~~~~~
> > > drivers/dma/sh/usb-dmac.c:720:9: note: 'sprintf' output between 4 and 13 bytes into a destination of size 5
> > >   720 |         sprintf(pdev_irqname, "ch%u", index);
> > >       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >
> > > Maximum number of channels for USB-DMAC as per the driver is 1-99 so use
> > > u8 instead of unsigned int/int for DMAC channel indexing and make the
> > > pdev_irqname string long enough to avoid the warning.
> > >
> > > 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>
> >
> > This looks like good fixes; thanks! I see n_channels is sanity checked
> > during the probe in usb_dmac_chan_probe(), so this looks good.
> >
> > (Is there a reason not to also change n_channels to a u8?)
> >
> Good point, I oversighted it by just looking at the loop indices. I
> will send a v2 with that change.

I think you'll need a bounce variable in usb_dmac_chan_probe() since it
looks like it's reading a 32-bit value from DT, but otherwise, it should
be okay.

-Kees

-- 
Kees Cook

  reply	other threads:[~2024-01-10 23:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 22:22 [PATCH] dmaengine: usb-dmac: Avoid format-overflow warning Prabhakar
2024-01-10 22:41 ` Kees Cook
2024-01-10 22:46   ` Lad, Prabhakar
2024-01-10 23:58     ` Kees Cook [this message]
2024-01-11  9:05 ` Geert Uytterhoeven
2024-01-11 11:41   ` Lad, Prabhakar
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=202401101557.87634A6A@keescook \
    --to=keescook@chromium.org \
    --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=tudor.ambarus@linaro.org \
    --cc=u.kleine-koenig@pengutronix.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox