Skip to contentSkip to conversation

PCI: Always initialize dev in pciconfig_read

PATCH In review Nathan Chancellor 3 participants 3 messages Aug 3, 2021 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Always initialize dev in pciconfig_read

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")
---
 drivers/pci/syscall.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/syscall.c +1 -0
index 525f16caed1d..61a6fe3cde21 100644
@@ -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

Signature · 1 line
2.33.0.rc0
#1 lore raw
Quoted 19 lines · 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
Quoted 7 lines

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

Squashed in locally, thanks!

Quoted 21 lines
---
 drivers/pci/syscall.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/syscall.c +1 -0
index 525f16caed1d..61a6fe3cde21 100644
@@ -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

Signature · 1 line
2.33.0.rc0
#2 lore raw
In reply to Nathan Chancellor

Hi Nathan,

Quoted 5 lines

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