public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Achim Leubner <achim_leubner@adaptec.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	clang-built-linux@googlegroups.com
Subject: Re: [PATCH] scsi: gdth: Only call dma_free_coherent when buf is not NULL in ioc_general
Date: Fri, 22 Mar 2019 08:26:53 -0700	[thread overview]
Message-ID: <20190322152653.GB21978@archlinux-ryzen> (raw)
In-Reply-To: <CAK8P3a0w=6kk8bkyKi0rU-8Fxmh0XqjqACadUJviMzkp67myOw@mail.gmail.com>

On Fri, Mar 22, 2019 at 03:30:08PM +0100, Arnd Bergmann wrote:
> On Fri, Mar 8, 2019 at 10:14 PM 'Nick Desaulniers' via Clang Built
> Linux <clang-built-linux@googlegroups.com> wrote:
> >
> > On Thu, Mar 7, 2019 at 3:19 PM Nathan Chancellor
> > <natechancellor@gmail.com> wrote:
> > >
> > > When building with -Wsometimes-uninitialized, Clang warns:
> > >
> > > drivers/scsi/gdth.c:3662:6: warning: variable 'paddr' is used
> > > uninitialized whenever 'if' condition is false
> > > [-Wsometimes-uninitialized]
> > >
> > > Don't attempt to call dma_free_coherent when buf is NULL (meaning that
> > > we never called dma_alloc_coherent and initialized paddr), which avoids
> > > this warning.
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/402
> > > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> > > ---
> > >  drivers/scsi/gdth.c | 5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
> > > index e7f1dd4f3b66..0ca9b4393770 100644
> > > --- a/drivers/scsi/gdth.c
> > > +++ b/drivers/scsi/gdth.c
> > > @@ -3697,8 +3697,9 @@ static int ioc_general(void __user *arg, char *cmnd)
> > >
> > >         rval = 0;
> > >  out_free_buf:
> > > -       dma_free_coherent(&ha->pdev->dev, gen.data_len + gen.sense_len, buf,
> > > -                       paddr);
> > > +       if (buf)
> > > +               dma_free_coherent(&ha->pdev->dev, gen.data_len + gen.sense_len,
> > > +                                 buf, paddr);
> > >         return rval;
> > >  }
> 
> I came up with a different fix for this, but I think yours is better
> 
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
> 
> For reference, this was my version:

This is also what I had initially but I felt this was more future proof
and matches how the rest of the tree handles calls to dma_free_coherent.

Thanks for the review!
Nathan

> 
> diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
> index e7f1dd4f3b66..c01f243902e1 100644
> --- a/drivers/scsi/gdth.c
> +++ b/drivers/scsi/gdth.c
> @@ -3697,8 +3697,9 @@ static int ioc_general(void __user *arg, char *cmnd)
> 
>         rval = 0;
>  out_free_buf:
> -       dma_free_coherent(&ha->pdev->dev, gen.data_len + gen.sense_len, buf,
> -                       paddr);
> +       if (gen.data_len + gen.sense_len > 0)
> +               dma_free_coherent(&ha->pdev->dev, gen.data_len +
> gen.sense_len, buf,
> +                               paddr);
>         return rval;
>  }
> 
> 
> > Alternatively, paddr is a dma_addr_t defined in include/linux/types.h:
> >
> > #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
> > typedef u64 dma_addr_t;
> > #else
> > typedef u32 dma_addr_t;
> > #endif
> >
> > Just initializing it to zero might be simpler than complicating the
> > control flow of this function further. Thoughts?
> 
> No, blindly shutting up warnings is almost never the
> right solution, even when they are false positives. The code
> might change in the future and the bogus initialization would
> then prevent the compiler from warning about a new bug.
> 
>       Arnd

  reply	other threads:[~2019-03-22 15:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07 23:18 [PATCH] scsi: gdth: Only call dma_free_coherent when buf is not NULL in ioc_general Nathan Chancellor
2019-03-08 21:14 ` Nick Desaulniers
2019-03-08 21:31   ` Nathan Chancellor
2019-03-22 14:30   ` Arnd Bergmann
2019-03-22 15:26     ` Nathan Chancellor [this message]
2019-03-20 19:12 ` Nathan Chancellor
2019-03-26  2:23 ` Martin K. Petersen

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=20190322152653.GB21978@archlinux-ryzen \
    --to=natechancellor@gmail.com \
    --cc=achim_leubner@adaptec.com \
    --cc=arnd@arndb.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=ndesaulniers@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