mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] FIT: match best configuration when multiple are compatible
Date: Tue,  5 Dec 2023 12:36:18 +0100	[thread overview]
Message-ID: <20231205113618.3966168-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231205113618.3966168-1-a.fatoum@pengutronix.de>

Currently, we match the first compatible configuration. There may be
multiple matching configurations however and we should continue looking
for a better match if a match didn't achieve maximal score.

Do that by checking score against OF_DEVICE_COMPATIBLE_MAX_SCORE and
continuing the search if unequal.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/image-fit.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 5ef5013bd41d..b16752de05bc 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -720,6 +720,7 @@ static int fit_find_compatible_unit(struct device_node *conf_node,
 {
 	struct device_node *child = NULL;
 	struct device_node *barebox_root;
+	int best_score = 0;
 	const char *machine;
 	int ret;
 
@@ -732,13 +733,21 @@ static int fit_find_compatible_unit(struct device_node *conf_node,
 		return -ENOENT;
 
 	for_each_child_of_node(conf_node, child) {
-		if (of_device_is_compatible(child, machine)) {
+		int score = of_device_is_compatible(child, machine);
+		if (score > best_score) {
+			best_score = score;
 			*unit = child->name;
-			pr_info("matching unit '%s' found\n", *unit);
-			return 0;
+
+			if (score == OF_DEVICE_COMPATIBLE_MAX_SCORE)
+				break;
 		}
 	}
 
+	if (best_score) {
+		pr_info("matching unit '%s' found\n", *unit);
+		return 0;
+	}
+
 default_unit:
 	pr_info("No match found. Trying default.\n");
 	if (of_property_read_string(conf_node, "default", unit) == 0)
-- 
2.39.2




  parent reply	other threads:[~2023-12-05 11:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05 11:36 [PATCH 0/3] " Ahmad Fatoum
2023-12-05 11:36 ` [PATCH 1/3] of: define macro for maximum of_device_is_compatible return value Ahmad Fatoum
2023-12-05 11:36 ` [PATCH 2/3] of: early exit of_match_node if no better matches are possible Ahmad Fatoum
2023-12-05 11:36 ` Ahmad Fatoum [this message]
2023-12-13  6:44 ` [PATCH 0/3] FIT: match best configuration when multiple are compatible Sascha Hauer

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=20231205113618.3966168-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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