From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 1/2] FIT: factor out fit_fdt_is_compatible for readability
Date: Fri, 14 Feb 2025 12:23:42 +0100 [thread overview]
Message-ID: <20250214112343.3076535-1-a.fatoum@pengutronix.de> (raw)
This introduces no functional change, but makes the code inside
fit_find_compatible_unit() more readable.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/image-fit.c | 67 +++++++++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 31 deletions(-)
diff --git a/common/image-fit.c b/common/image-fit.c
index 58ce461623e6..e05161379d04 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -719,6 +719,40 @@ static int fit_config_verify_signature(struct fit_handle *handle, struct device_
return ret;
}
+static int fit_fdt_is_compatible(struct fit_handle *handle,
+ struct device_node *child,
+ const char *machine)
+{
+ struct device_node *image;
+ const char *unit = "fdt";
+ int data_len;
+ const void *data;
+ int ret;
+
+ if (of_property_present(child, "compatible"))
+ return 0;
+ if (!of_property_present(child, "fdt"))
+ return 0;
+
+ ret = fit_get_image(handle, child, &unit, &image);
+ if (ret)
+ goto err;
+
+ data = of_get_property(image, "data", &data_len);
+ if (!data)
+ goto err;
+
+ ret = fit_handle_decompression(image, "fdt", &data, &data_len);
+ if (ret)
+ goto err;
+
+ return fdt_machine_is_compatible(data, data_len, machine);
+err:
+ pr_warn("skipping malformed configuration \"%pOF\"\n",
+ child);
+ return 0;
+}
+
static int fit_find_compatible_unit(struct fit_handle *handle,
struct device_node *conf_node,
const char **unit)
@@ -740,37 +774,8 @@ static int fit_find_compatible_unit(struct fit_handle *handle,
for_each_child_of_node(conf_node, child) {
int score = of_device_is_compatible(child, machine);
- if (!score && !of_property_present(child, "compatible") &&
- of_property_present(child, "fdt")) {
- struct device_node *image;
- const char *unit = "fdt";
- int data_len;
- const void *data;
- int ret;
-
- ret = fit_get_image(handle, child, &unit, &image);
- if (ret)
- goto next;
-
- data = of_get_property(image, "data", &data_len);
- if (!data) {
- ret = -EINVAL;
- goto next;
- }
-
- ret = fit_handle_decompression(image, "fdt", &data, &data_len);
- if (ret) {
- ret = -EILSEQ;
- goto next;
- }
-
- score = fdt_machine_is_compatible(data, data_len, machine);
-
-next:
- if (ret)
- pr_warn("skipping malformed configuration: %pOF (%pe)\n",
- child, ERR_PTR(ret));
- }
+ if (!score)
+ score = fit_fdt_is_compatible(handle, child, machine);
if (score > best_score) {
best_score = score;
--
2.39.5
next reply other threads:[~2025-02-14 11:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 11:23 Ahmad Fatoum [this message]
2025-02-14 11:23 ` [PATCH master 2/2] FIT: do not decompress device trees to find compatible Ahmad Fatoum
2025-02-17 9:00 ` [PATCH master 1/2] FIT: factor out fit_fdt_is_compatible for readability 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=20250214112343.3076535-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