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: jzi@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] bbu: fix exporting i.MX NAND bbu handler over fastboot
Date: Wed, 28 Sep 2022 10:56:22 +0200	[thread overview]
Message-ID: <20220928085622.2677478-1-a.fatoum@pengutronix.de> (raw)

handler->devicefile for i.MX NAND is nand0.barebox, which lacks a /dev/
prefix. This is ok for detection, as device_detect_by_name expects the
cdev name and devpath_to_name() will strip a /dev/ if available.

For stat() however, we need to add back /dev/, otherwise the file can't
be found. Rework the code to do that.

This fixes an issue where usbgadget -A '' -b would not export a i.MX
NAND barebox update handler.

Fixes: 726a802456bc ("common: bbu: only add available handlers")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bbu.c | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/common/bbu.c b/common/bbu.c
index d243ac89dd9f..3ec17216cb15 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -24,43 +24,42 @@
 
 static LIST_HEAD(bbu_image_handlers);
 
-static void append_bbu_entry(struct bbu_handler *handler, struct file_list *files)
+static void append_bbu_entry(const char *_name,
+			     const char *devicefile,
+			     struct file_list *files)
 {
 	char *name;
 
-	name = basprintf("bbu-%s", handler->name);
+	name = basprintf("bbu-%s", _name);
 
-	if (file_list_add_entry(files, name, handler->devicefile, 0))
+	if (file_list_add_entry(files, name, devicefile, 0))
 		pr_warn("duplicate partition name %s\n", name);
 
 	free(name);
 }
 
-static bool bbu_handler_is_available(struct bbu_handler *handler)
-{
-	struct stat s;
-	int ret;
-
-	device_detect_by_name(devpath_to_name(handler->devicefile));
-
-	ret = stat(handler->devicefile, &s);
-	if (ret)
-		return false;
-
-	return true;
-}
-
 void bbu_append_handlers_to_file_list(struct file_list *files)
 {
 	struct bbu_handler *handler;
 
 	list_for_each_entry(handler, &bbu_image_handlers, list) {
-		if (bbu_handler_is_available(handler)) {
-			append_bbu_entry(handler, files);
+		const char *cdevname;
+		struct stat s;
+		char *devpath;
+
+		cdevname = devpath_to_name(handler->devicefile);
+		device_detect_by_name(cdevname);
+
+		devpath = basprintf("/dev/%s", cdevname);
+
+		if (stat(devpath, &s) == 0) {
+			append_bbu_entry(handler->name, devpath, files);
 		} else {
 			pr_info("Skipping unavailable handler bbu-%s\n",
 				handler->name);
 		}
+
+		free(devpath);
 	}
 }
 
-- 
2.30.2




             reply	other threads:[~2022-09-28  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28  8:56 Ahmad Fatoum [this message]
2022-09-30 12:37 ` 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=20220928085622.2677478-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=jzi@pengutronix.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