Commit 0df3e421 authored by Nathan Chancellor's avatar Nathan Chancellor Committed by Michael Ellerman

PCI: rpaphp: Avoid a sometimes-uninitialized warning

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

fndit is only used to gate a sprintf call, which can be moved into the
loop to simplify the code and eliminate the local variable, which will
fix this warning.

Fixes: 2fcf3ae5 ("hotplug/drc-info: Add code to search ibm,drc-info property")
Suggested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
Acked-by: default avatarTyrel Datwyler <tyreld@linux.ibm.com>
Acked-by: default avatarJoel Savitz <jsavitz@redhat.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://github.com/ClangBuiltLinux/linux/issues/504
Link: https://lore.kernel.org/r/20190603221157.58502-1-natechancellor@gmail.com
parent ae2e953f
...@@ -230,7 +230,7 @@ static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name, ...@@ -230,7 +230,7 @@ static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name,
struct of_drc_info drc; struct of_drc_info drc;
const __be32 *value; const __be32 *value;
char cell_drc_name[MAX_DRC_NAME_LEN]; char cell_drc_name[MAX_DRC_NAME_LEN];
int j, fndit; int j;
info = of_find_property(dn->parent, "ibm,drc-info", NULL); info = of_find_property(dn->parent, "ibm,drc-info", NULL);
if (info == NULL) if (info == NULL)
...@@ -245,17 +245,13 @@ static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name, ...@@ -245,17 +245,13 @@ static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name,
/* Should now know end of current entry */ /* Should now know end of current entry */
if (my_index > drc.last_drc_index) /* Found it */
continue; if (my_index <= drc.last_drc_index) {
sprintf(cell_drc_name, "%s%d", drc.drc_name_prefix,
fndit = 1; my_index);
break; break;
}
} }
/* Found it */
if (fndit)
sprintf(cell_drc_name, "%s%d", drc.drc_name_prefix,
my_index);
if (((drc_name == NULL) || if (((drc_name == NULL) ||
(drc_name && !strcmp(drc_name, cell_drc_name))) && (drc_name && !strcmp(drc_name, cell_drc_name))) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment