u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Paul Barker <paul.barker@sancloud.com>
To: u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>
Cc: Paul Barker <paul.barker@sancloud.com>
Subject: [PATCH 1/2] dm: core: Fix iteration over driver_info records
Date: Sat, 15 Oct 2022 10:19:08 +0100	[thread overview]
Message-ID: <20221015091909.3957290-2-paul.barker@sancloud.com> (raw)
In-Reply-To: <20221015091909.3957290-1-paul.barker@sancloud.com>

We should only perform additional iteration steps when needed to
initialize the parent of a device. Other binding errors (such as a
missing driver) should not lead to additional iteration steps.

Unnecessary iteration steps can cause issues when memory is tightly
constrained (such as in the TPL/SPL) since device_bind_by_name()
unconditionally allocates memory for a struct udevice. On the SanCloud
BBE this led to boot failure caused by memory exhaustion in the SPL
when booting from SPI flash.

Signed-off-by: Paul Barker <paul.barker@sancloud.com>
---
 drivers/core/lists.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/core/lists.c b/drivers/core/lists.c
index c49695b24f00..82d479564121 100644
--- a/drivers/core/lists.c
+++ b/drivers/core/lists.c
@@ -51,13 +51,13 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id)
 	return NULL;
 }
 
-static int bind_drivers_pass(struct udevice *parent, bool pre_reloc_only)
+static bool bind_drivers_pass(struct udevice *parent, bool pre_reloc_only,
+			      int *result)
 {
 	struct driver_info *info =
 		ll_entry_start(struct driver_info, driver_info);
 	const int n_ents = ll_entry_count(struct driver_info, driver_info);
 	bool missing_parent = false;
-	int result = 0;
 	int idx;
 
 	/*
@@ -98,12 +98,12 @@ static int bind_drivers_pass(struct udevice *parent, bool pre_reloc_only)
 				drt->dev = dev;
 		} else if (ret != -EPERM) {
 			dm_warn("No match for driver '%s'\n", entry->name);
-			if (!result || ret != -ENOENT)
-				result = ret;
+			if (!*result || ret != -ENOENT)
+				*result = ret;
 		}
 	}
 
-	return result ? result : missing_parent ? -EAGAIN : 0;
+	return missing_parent;
 }
 
 int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)
@@ -117,13 +117,8 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)
 	 * always succeed on the first pass.
 	 */
 	for (pass = 0; pass < 10; pass++) {
-		int ret;
-
-		ret = bind_drivers_pass(parent, pre_reloc_only);
-		if (!ret)
+		if (!bind_drivers_pass(parent, pre_reloc_only, &result))
 			break;
-		if (ret != -EAGAIN && !result)
-			result = ret;
 	}
 
 	return result;
-- 
2.25.1


  reply	other threads:[~2022-10-15  9:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-15  9:19 [PATCH 0/2] Fixes for SPI boot on SanCloud BBE Lite Paul Barker
2022-10-15  9:19 ` Paul Barker [this message]
2022-10-15 17:53   ` [PATCH 1/2] dm: core: Fix iteration over driver_info records Simon Glass
2022-10-25 12:59     ` Paul Barker
2022-10-15  9:19 ` [PATCH 2/2] configs: am335x_evm: Disable SPL_OF_CONTROL Paul Barker
2022-10-15 17:53   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221015091909.3957290-2-paul.barker@sancloud.com \
    --to=paul.barker@sancloud.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).