From: Tomer Maimon <tmaimon77@gmail.com>
To: olof@lixom.net
Cc: broonie@kernel.org, Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Nancy Yuen <yuenn@google.com>,
Patrick Venture <venture@google.com>,
Brendan Higgins <brendanhiggins@google.com>,
Avi Fishman <avifishman70@gmail.com>,
Joel Stanley <joel@jms.id.au>,
linux-spi@vger.kernel.org,
OpenBMC Maillist <openbmc@lists.ozlabs.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
devicetree <devicetree@vger.kernel.org>
Subject: Re: [PATCH v1 1/1] spi: npcm: fix uninitialized 'val' warning in receive function
Date: Tue, 20 Nov 2018 12:51:19 +0200 [thread overview]
Message-ID: <CAP6Zq1j46ch8UUxJkO7SnrHWyP3Y7g58Fodejr98WN-TW8jhEw@mail.gmail.com> (raw)
In-Reply-To: <CAOesGMjUJ1+qmbPWcVFm1F_F0fcdg-54YY6o4iK=PYWoAuEczA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]
Hi Olof,
On Sun, 18 Nov 2018 at 23:38, Olof Johansson <olof@lixom.net> wrote:
> On Sun, Nov 18, 2018 at 4:36 AM Tomer Maimon <tmaimon77@gmail.com> wrote:
> >
> > Fix uninitialized 'val' warning receive function, send function
> > has been modify to be aligned with the receive function.
> >
> > Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
> > ---
> > drivers/spi/spi-npcm-pspi.c | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/spi/spi-npcm-pspi.c b/drivers/spi/spi-npcm-pspi.c
> > index 6dae91091143..f75df49ab84e 100644
> > --- a/drivers/spi/spi-npcm-pspi.c
> > +++ b/drivers/spi/spi-npcm-pspi.c
> > @@ -199,11 +199,11 @@ static void npcm_pspi_send(struct npcm_pspi *priv)
> > wsize = min(bytes_per_word(priv->bits_per_word), priv->tx_bytes);
> > priv->tx_bytes -= wsize;
> >
> > - if (priv->tx_buf) {
> > - if (wsize == 1)
> > - iowrite8(*priv->tx_buf, NPCM_PSPI_DATA +
> priv->base);
> > + if (priv->tx_buf && wsize) {
>
> In general, doing an early:
> if (!condition)
> return;
>
> is a pattern we prefer in the kernel. Setting up the assumptions at
> the beginning of the function makes it easier to follow the code flow,
> and saves a level of indentation.
>
> It's a matter of taste though, and this function has only one level.
> So, either way is OK. Just mentioning it.
>
> > if (wsize == 2)
> > iowrite16(*priv->tx_buf, NPCM_PSPI_DATA +
> priv->base);
> > + else
> > + iowrite8(*priv->tx_buf, NPCM_PSPI_DATA +
> priv->base);
>
> I think this is broken? If wsize is something else than 1 or 2, you'll
> do a one-byte write but advance the buffer pointer with a different
> amount.
>
> It'll be fairly tricky to debug if this ever happens (it shouldn't,
> but still). This is why I added a WARN_ON_ONCE() in my patch instead.
>
We just tried to reduce the number of lines to minimum, so we have debug it
quite a lot (with all the numbers that can
get from priv->tx_bytes) and the only numbers that minimum function return
are 0, 1 or 2.
But in the end of the day, we don't have an issue with your solution as
long it will be done also in the transfer function.
So if you can send a new patch with transfer function modification as well
it will be great (Please let me know if you like me to send the patch).
Thanks again
Tomer
-Olof
>
[-- Attachment #2: Type: text/html, Size: 3531 bytes --]
next prev parent reply other threads:[~2018-11-20 10:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-18 12:35 [PATCH v1 0/1] npcm: fix uninitialized 'val' warning in receive function Tomer Maimon
2018-11-18 12:35 ` [PATCH v1 1/1] spi: " Tomer Maimon
2018-11-18 21:38 ` Olof Johansson
2018-11-20 10:51 ` Tomer Maimon [this message]
2018-11-20 13:02 ` 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=CAP6Zq1j46ch8UUxJkO7SnrHWyP3Y7g58Fodejr98WN-TW8jhEw@mail.gmail.com \
--to=tmaimon77@gmail.com \
--cc=avifishman70@gmail.com \
--cc=brendanhiggins@google.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=joel@jms.id.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=olof@lixom.net \
--cc=openbmc@lists.ozlabs.org \
--cc=robh+dt@kernel.org \
--cc=venture@google.com \
--cc=yuenn@google.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;
as well as URLs for NNTP newsgroup(s).