rpaphp_drc_add_slot() overwrites retval on every loop iteration, so a
failure to register a slot is lost if a later slot registers
successfully and the function returns success.

Track the first error and return it, while still attempting to register
the remaining slots.

Signed-off-by: Adriano Cordova <[email protected]>
---
 drivers/pci/hotplug/rpaphp_core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/rpaphp_core.c 
b/drivers/pci/hotplug/rpaphp_core.c
index 2316de0fd198..af7241d526cf 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -376,6 +376,7 @@ static int rpaphp_drc_add_slot(struct device_node *dn)
 {
        struct slot *slot;
        int retval = 0;
+       int first_error = 0;
        int i;
        const __be32 *indexes, *names, *types, *power_domains;
        char *name, *type;
@@ -407,16 +408,18 @@ static int rpaphp_drc_add_slot(struct device_node *dn)
                if (!retval)
                        retval = rpaphp_register_slot(slot);
 
-               if (retval)
+               if (retval) {
+                       if (!first_error)
+                               first_error = retval;
                        dealloc_slot_struct(slot);
+               }
 
                name += strlen(name) + 1;
                type += strlen(type) + 1;
        }
-       dbg("%s - Exit: rc[%d]\n", __func__, retval);
+       dbg("%s - Exit: rc[%d]\n", __func__, first_error);
 
-       /* XXX FIXME: reports a failure only if last entry in loop failed */
-       return retval;
+       return first_error;
 }
 
 /**
-- 
2.51.0


Reply via email to