mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] bbu: fix exporting i.MX NAND bbu handler over fastboot
@ 2022-09-28  8:56 Ahmad Fatoum
  2022-09-30 12:37 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-09-28  8:56 UTC (permalink / raw)
  To: barebox; +Cc: jzi, Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-30 12:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28  8:56 [PATCH master] bbu: fix exporting i.MX NAND bbu handler over fastboot Ahmad Fatoum
2022-09-30 12:37 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox