diff mbox

[U-Boot,03/10] dm: pci: Tidy up auto-config error handling

Message ID 1441756374-6762-4-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Sept. 8, 2015, 11:52 p.m. UTC
When the auto-configuration process fails for a device (generally due to
lack of memory) we should return the error correctly so that we don't
continue to try memory allocations which will fail.

Adjust the code to check for errors and abort if something goes wrong.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/pci/pci-uclass.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Bin Meng Sept. 14, 2015, 12:15 p.m. UTC | #1
On Wed, Sep 9, 2015 at 7:52 AM, Simon Glass <sjg@chromium.org> wrote:
> When the auto-configuration process fails for a device (generally due to
> lack of memory) we should return the error correctly so that we don't
> continue to try memory allocations which will fail.
>
> Adjust the code to check for errors and abort if something goes wrong.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/pci/pci-uclass.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> index b25298f..437c81a 100644
> --- a/drivers/pci/pci-uclass.c
> +++ b/drivers/pci/pci-uclass.c
> @@ -381,9 +381,13 @@ int pci_auto_config_devices(struct udevice *bus)
>              !ret && dev;
>              ret = device_find_next_child(&dev)) {
>                 unsigned int max_bus;
> +               int ret;
>
>                 debug("%s: device %s\n", __func__, dev->name);
> -               max_bus = pciauto_config_device(hose, pci_get_bdf(dev));
> +               ret = pciauto_config_device(hose, pci_get_bdf(dev));
> +               if (ret < 0)
> +                       return ret;
> +               max_bus = ret;
>                 sub_bus = max(sub_bus, max_bus);
>         }
>         debug("%s: done\n", __func__);
> @@ -757,6 +761,8 @@ static int pci_uclass_post_probe(struct udevice *bus)
>
>  #ifdef CONFIG_PCI_PNP
>         ret = pci_auto_config_devices(bus);
> +       if (ret < 0)
> +               return ret;
>  #endif
>
>  #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
> @@ -773,11 +779,14 @@ static int pci_uclass_post_probe(struct udevice *bus)
>          * Note we only call this 1) after U-Boot is relocated, and 2)
>          * root bus has finished probing.
>          */
> -       if ((gd->flags & GD_FLG_RELOC) && (bus->seq == 0))
> +       if ((gd->flags & GD_FLG_RELOC) && (bus->seq == 0)) {
>                 ret = fsp_init_phase_pci();
> +               if (ret)
> +                       return ret;
> +       }
>  #endif
>
> -       return ret < 0 ? ret : 0;
> +       return 0;
>  }
>
>  static int pci_uclass_child_post_bind(struct udevice *dev)
> --

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Simon Glass Oct. 18, 2015, 12:28 p.m. UTC | #2
On 14 September 2015 at 06:15, Bin Meng <bmeng.cn@gmail.com> wrote:
> On Wed, Sep 9, 2015 at 7:52 AM, Simon Glass <sjg@chromium.org> wrote:
>> When the auto-configuration process fails for a device (generally due to
>> lack of memory) we should return the error correctly so that we don't
>> continue to try memory allocations which will fail.
>>
>> Adjust the code to check for errors and abort if something goes wrong.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>>  drivers/pci/pci-uclass.c | 15 ++++++++++++---
>>  1 file changed, 12 insertions(+), 3 deletions(-)
[snip]
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot-x86.
diff mbox

Patch

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index b25298f..437c81a 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -381,9 +381,13 @@  int pci_auto_config_devices(struct udevice *bus)
 	     !ret && dev;
 	     ret = device_find_next_child(&dev)) {
 		unsigned int max_bus;
+		int ret;
 
 		debug("%s: device %s\n", __func__, dev->name);
-		max_bus = pciauto_config_device(hose, pci_get_bdf(dev));
+		ret = pciauto_config_device(hose, pci_get_bdf(dev));
+		if (ret < 0)
+			return ret;
+		max_bus = ret;
 		sub_bus = max(sub_bus, max_bus);
 	}
 	debug("%s: done\n", __func__);
@@ -757,6 +761,8 @@  static int pci_uclass_post_probe(struct udevice *bus)
 
 #ifdef CONFIG_PCI_PNP
 	ret = pci_auto_config_devices(bus);
+	if (ret < 0)
+		return ret;
 #endif
 
 #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
@@ -773,11 +779,14 @@  static int pci_uclass_post_probe(struct udevice *bus)
 	 * Note we only call this 1) after U-Boot is relocated, and 2)
 	 * root bus has finished probing.
 	 */
-	if ((gd->flags & GD_FLG_RELOC) && (bus->seq == 0))
+	if ((gd->flags & GD_FLG_RELOC) && (bus->seq == 0)) {
 		ret = fsp_init_phase_pci();
+		if (ret)
+			return ret;
+	}
 #endif
 
-	return ret < 0 ? ret : 0;
+	return 0;
 }
 
 static int pci_uclass_child_post_bind(struct udevice *dev)