linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: rpaphp: Avoid a sometimes-uninitialized warning
@ 2019-06-03 17:43 Nathan Chancellor
  2019-06-03 21:07 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Nathan Chancellor @ 2019-06-03 17:43 UTC (permalink / raw)
  To: Tyrel Datwyler, Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: linux-pci, linux-kernel, clang-built-linux, Bjorn Helgaas,
	Nathan Chancellor, linuxppc-dev

When building with -Wsometimes-uninitialized, clang warns:

drivers/pci/hotplug/rpaphp_core.c:243:14: warning: variable 'fndit' is
used uninitialized whenever 'for' loop exits because its condition is
false [-Wsometimes-uninitialized]
        for (j = 0; j < entries; j++) {
                    ^~~~~~~~~~~
drivers/pci/hotplug/rpaphp_core.c:256:6: note: uninitialized use occurs
here
        if (fndit)
            ^~~~~
drivers/pci/hotplug/rpaphp_core.c:243:14: note: remove the condition if
it is always true
        for (j = 0; j < entries; j++) {
                    ^~~~~~~~~~~
drivers/pci/hotplug/rpaphp_core.c:233:14: note: initialize the variable
'fndit' to silence this warning
        int j, fndit;
                    ^
                     = 0

Looking at the loop in a vacuum as clang would, fndit could be
uninitialized if entries was ever zero or the if statement was
always true within the loop. Regardless of whether or not this
warning is a problem in practice, "found" variables should always
be initialized to false so that there is no possibility of
undefined behavior.

Link: https://github.com/ClangBuiltLinux/linux/issues/504
Fixes: 2fcf3ae508c2 ("hotplug/drc-info: Add code to search ibm,drc-info property")
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 drivers/pci/hotplug/rpaphp_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index bcd5d357ca23..07b56bf2886f 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -230,7 +230,7 @@ static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name,
 	struct of_drc_info drc;
 	const __be32 *value;
 	char cell_drc_name[MAX_DRC_NAME_LEN];
-	int j, fndit;
+	int j, fndit = 0;
 
 	info = of_find_property(dn->parent, "ibm,drc-info", NULL);
 	if (info == NULL)
-- 
2.22.0.rc2


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

end of thread, other threads:[~2019-08-10 10:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 17:43 [PATCH] PCI: rpaphp: Avoid a sometimes-uninitialized warning Nathan Chancellor
2019-06-03 21:07 ` Nick Desaulniers
2019-06-03 21:51   ` Nathan Chancellor
2019-06-03 22:11 ` [PATCH v2] " Nathan Chancellor
2019-06-04  0:03   ` Tyrel Datwyler
2019-06-27 19:18   ` Nathan Chancellor
2019-06-28  2:57   ` Joel Savitz
2019-07-22  2:43   ` Nathan Chancellor
2019-07-22  4:05     ` Michael Ellerman
2019-08-02  0:11       ` Bjorn Helgaas
2019-08-02 12:24         ` Michael Ellerman
2019-08-10 10:20   ` Michael Ellerman
2019-06-04  6:24 ` [PATCH] " Christophe Leroy

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