linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	clang-built-linux@googlegroups.com
Subject: Re: [PATCH] PCI: Always initialize dev in pciconfig_read
Date: Tue, 3 Aug 2021 16:56:21 -0500	[thread overview]
Message-ID: <20210803215621.GA1576408@bjorn-Precision-5520> (raw)
In-Reply-To: <20210803200836.500658-1-nathan@kernel.org>

On Tue, Aug 03, 2021 at 01:08:36PM -0700, Nathan Chancellor wrote:
> Clang warns:
> 
> drivers/pci/syscall.c:25:6: warning: variable 'dev' is used
> uninitialized whenever 'if' condition is true
> [-Wsometimes-uninitialized]
>         if (!capable(CAP_SYS_ADMIN))
>             ^~~~~~~~~~~~~~~~~~~~~~~
> drivers/pci/syscall.c:81:14: note: uninitialized use occurs here
>         pci_dev_put(dev);
>                     ^~~
> drivers/pci/syscall.c:25:2: note: remove the 'if' if its condition is
> always false
>         if (!capable(CAP_SYS_ADMIN))
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/pci/syscall.c:18:21: note: initialize the variable 'dev' to
> silence this warning
>         struct pci_dev *dev;
>                            ^
>                             = NULL
> 1 warning generated.
> 
> pci_dev_put accounts for a NULL pointer so initialize dev to NULL before
> the capability check so that there is no use of uninitialized memory.
> 
> Fixes: 61a6199787d9 ("PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Squashed in locally, thanks!

> ---
>  drivers/pci/syscall.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c
> index 525f16caed1d..61a6fe3cde21 100644
> --- a/drivers/pci/syscall.c
> +++ b/drivers/pci/syscall.c
> @@ -22,6 +22,7 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
>  	int err, cfg_ret;
>  
>  	err = -EPERM;
> +	dev = NULL;
>  	if (!capable(CAP_SYS_ADMIN))
>  		goto error;
>  
> 
> base-commit: 21d8e94253eb09f7c94c4db00dc714efc75b8701
> -- 
> 2.33.0.rc0
> 

  reply	other threads:[~2021-08-03 21:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 20:08 [PATCH] PCI: Always initialize dev in pciconfig_read Nathan Chancellor
2021-08-03 21:56 ` Bjorn Helgaas [this message]
2021-08-03 23:09 ` Krzysztof Wilczyński

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=20210803215621.GA1576408@bjorn-Precision-5520 \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=nathan@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).