LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] PCI: Always initialize dev in pciconfig_read
@ 2021-08-03 20:08 Nathan Chancellor
  2021-08-03 21:56 ` Bjorn Helgaas
  2021-08-03 23:09 ` Krzysztof Wilczyński
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2021-08-03 20:08 UTC (permalink / raw)
  To: Bjorn Helgaas, Krzysztof Wilczyński
  Cc: Nick Desaulniers, linux-pci, linux-kernel, clang-built-linux,
	Nathan Chancellor

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>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: Always initialize dev in pciconfig_read
  2021-08-03 20:08 [PATCH] PCI: Always initialize dev in pciconfig_read Nathan Chancellor
@ 2021-08-03 21:56 ` Bjorn Helgaas
  2021-08-03 23:09 ` Krzysztof Wilczyński
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2021-08-03 21:56 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Bjorn Helgaas, Krzysztof Wilczyński, Nick Desaulniers,
	linux-pci, linux-kernel, clang-built-linux

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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: Always initialize dev in pciconfig_read
  2021-08-03 20:08 [PATCH] PCI: Always initialize dev in pciconfig_read Nathan Chancellor
  2021-08-03 21:56 ` Bjorn Helgaas
@ 2021-08-03 23:09 ` Krzysztof Wilczyński
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Wilczyński @ 2021-08-03 23:09 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Bjorn Helgaas, Nick Desaulniers, linux-pci, linux-kernel,
	clang-built-linux

Hi Nathan,

> drivers/pci/syscall.c:18:21: note: initialize the variable 'dev' to
> silence this warning
>         struct pci_dev *dev;
>                            ^
>                             = NULL
[...]

Nice catch!  Thank you for fixing and sorry that I miss this one!

	Krzysztof

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-03 23:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 20:08 [PATCH] PCI: Always initialize dev in pciconfig_read Nathan Chancellor
2021-08-03 21:56 ` Bjorn Helgaas
2021-08-03 23:09 ` Krzysztof Wilczyński

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).