mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Biju Das <biju.das.jz@bp.renesas.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
	Dan Carpenter <dan.carpenter@linaro.org>
Cc: Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	"linux-sound@vger.kernel.org" <linux-sound@vger.kernel.org>,
	"linux-renesas-soc@vger.kernel.org"
	<linux-renesas-soc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: RE: [PATCH] ASoC: renesas: rz-ssi: Add a check for negative sample_space
Date: Wed, 8 Jan 2025 11:08:24 +0000	[thread overview]
Message-ID: <TY3PR01MB113463ACD4D18075A0DCD2F6D86122@TY3PR01MB11346.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <CAMuHMdWRm0UtJ+vZgmizjHW6y7gCfLoWapjC3Hh0w3ABWOG9YA@mail.gmail.com>

Hi Geert,

> -----Original Message-----
> From: Geert Uytterhoeven <geert@linux-m68k.org>
> Sent: 08 January 2025 10:58
> Subject: Re: [PATCH] ASoC: renesas: rz-ssi: Add a check for negative sample_space
> 
> Hi Dan,
> 
> On Wed, Jan 8, 2025 at 10:29 AM Dan Carpenter <dan.carpenter@linaro.org> wrote:
> > My static checker rule complains about this code.  The concern is that
> > if "sample_space" is negative then the "sample_space >= runtime->channels"
> > condition will not work as intended because it will be type promoted
> > to a high unsigned int value.
> >
> > strm->fifo_sample_size is SSI_FIFO_DEPTH (32).  The SSIFSR_TDC_MASK is
> > 0x3f.  Without any further context it does seem like a reasonable
> > warning and it can't hurt to add a check for negatives.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 03e786bd4341 ("ASoC: sh: Add RZ/G2L SSIF-2 driver")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> Thanks for your patch!
> 
> > --- a/sound/soc/renesas/rz-ssi.c
> > +++ b/sound/soc/renesas/rz-ssi.c
> > @@ -521,6 +521,8 @@ static int rz_ssi_pio_send(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm)
> >         sample_space = strm->fifo_sample_size;
> >         ssifsr = rz_ssi_reg_readl(ssi, SSIFSR);
> >         sample_space -= (ssifsr >> SSIFSR_TDC_SHIFT) &
> > SSIFSR_TDC_MASK;
> > +       if (sample_space < 0)
> > +               return -EINVAL;
> >
> >         /* Only add full frames at a time */
> >         while (frames_left && (sample_space >= runtime->channels)) {
> 
> In practice this cannot happen, as the maximum value of the field is 0x20 (= SSI_FIFO_DEPTH), but
> better safe than sorry, so
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> 
> Biju/Prabhakar: The documentation for the TDC bits in the FIFO Status Register seems to be incorrect
> (in all of the RZ/G2L, RZ/G2UL, RZ/G3S, and RZ/A2M documentation):
> 
>     TDC[5:0] Bits
>     These bits indicate the number of valid data that are stored in
>     the transmit FIFO data register (SSIFTDR). With this flag as H’0,
>     there is no data to be transmitted. With H’10, there is no space to
>     write data.
> 
> As the FIFO size is 4 bytes x 32 stages for both the transmit and receive FIFOs, the above should be
> H'20 instead of H'10.

Thanks for pointing it out. Will check this with HW documentation team about this issue.

Cheers,
Biju

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08  9:28 Dan Carpenter
2025-01-08 10:57 ` Geert Uytterhoeven
2025-01-08 11:08   ` Biju Das [this message]
2025-01-08 14:48 ` Mark Brown

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=TY3PR01MB113463ACD4D18075A0DCD2F6D86122@TY3PR01MB11346.jpnprd01.prod.outlook.com \
    --to=biju.das.jz@bp.renesas.com \
    --cc=broonie@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=geert@linux-m68k.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=tiwai@suse.com \
    /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

all inboxes | Powered by JetHome®