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] fixup! of: fdt: implement fdt_machine_is_compatible
Date: Mon,  4 Mar 2024 19:55:58 +0100	[thread overview]
Message-ID: <20240304185558.3483252-1-a.fatoum@pengutronix.de> (raw)

of: fdt: have fdt_machine_is_compatible() return a score

fdt_machine_is_compatible() currently returns false on mismatch and
true on match. of_machine_is_compatible(), that it's meant to partially
replace, returns a positive score value, so multiple compatible machines
can be compared. Do likewise for fdt_machine_is_compatible.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/fdt.c | 18 +++++++++---------
 include/of.h     |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 23b7b90f8e54..2f3b0763999d 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -690,7 +690,7 @@ static int fdt_string_is_compatible(const char *haystack, int haystack_len,
 	return 0;
 }
 
-bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, const char *compat)
+int fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, const char *compat)
 {
 	uint32_t tag;
 	const struct fdt_property *fdt_prop;
@@ -705,7 +705,7 @@ bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, co
 
 	ret = fdt_parse_header(fdt, fdt_size, &f);
 	if (ret < 0)
-		return false;
+		return 0;
 
 	dt_struct = f.off_dt_struct;
 	dt_strings = (const void *)fdt + f.off_dt_strings;
@@ -713,11 +713,11 @@ bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, co
 	while (1) {
 		const __be32 *tagp = (const void *)fdt + dt_struct;
 		if (!dt_ptr_ok(fdt, tagp))
-			return false;
+			return 0;
 
 		tag = be32_to_cpu(*tagp);
 		if (tag != FDT_NOP && tag != expect)
-			return false;
+			return 0;
 
 		switch (tag) {
 		case FDT_BEGIN_NODE:
@@ -725,7 +725,7 @@ bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, co
 
 			/* The root node must have an empty name */
 			if (fnh->name[0] != '\0')
-				return false;
+				return 0;
 
 			dt_struct = dt_struct_advance(&f, dt_struct,
 					sizeof(struct fdt_node_header) + 1);
@@ -739,7 +739,7 @@ bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, co
 
 			name = dt_string(&f, dt_strings, fdt32_to_cpu(fdt_prop->nameoff));
 			if (!name)
-				return false;
+				return 0;
 
 			if (strcmp(name, "compatible")) {
 				dt_struct = dt_struct_advance(&f, dt_struct,
@@ -754,12 +754,12 @@ bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, co
 			break;
 
 		default:
-			return false;
+			return 0;
 		}
 
 		if (!dt_struct)
-			return false;
+			return 0;
 	}
 
-	return false;
+	return 0;
 }
diff --git a/include/of.h b/include/of.h
index 7ee75728d0ad..9cd2c9aee2a4 100644
--- a/include/of.h
+++ b/include/of.h
@@ -64,7 +64,7 @@ void of_clean_reserve_map(void);
 void fdt_add_reserve_map(void *fdt);
 void fdt_print_reserve_map(const void *fdt);
 
-bool fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, const char *compat);
+int fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, const char *compat);
 
 
 struct device;
-- 
2.39.2




             reply	other threads:[~2024-03-04 18:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 18:55 Ahmad Fatoum [this message]
2024-03-05 15:34 ` 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=20240304185558.3483252-1-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