[PATCH 09/17] dfu: Detach the controller on error

Marek Vasut marex at denx.de
Sat Aug 19 16:23:59 CEST 2023


In case anything errors out during the DFU registration, detach
the controller instead of bailing out right away. This way, the
controller can be reattached on next attempt.

Signed-off-by: Marek Vasut <marex at denx.de>
---
Cc: Angus Ainslie <angus at akkea.ca>
Cc: Dmitrii Merkurev <dimorinny at google.com>
Cc: Eddie Cai <eddie.cai.linux at gmail.com>
Cc: Kever Yang <kever.yang at rock-chips.com>
Cc: Lukasz Majewski <lukma at denx.de>
Cc: Miquel Raynal <miquel.raynal at bootlin.com>
Cc: Mattijs Korpershoek <mkorpershoek at baylibre.com>
Cc: Nishanth Menon <nm at ti.com>
Cc: Patrice Chotard <patrice.chotard at foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay at foss.st.com>
Cc: Philipp Tomsich <philipp.tomsich at vrull.eu>
Cc: Simon Glass <sjg at chromium.org>
Cc: Stefan Roese <sr at denx.de>
Cc: kernel at puri.sm
---
 common/dfu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/dfu.c b/common/dfu.c
index 96190889ab7..32fba84da16 100644
--- a/common/dfu.c
+++ b/common/dfu.c
@@ -34,7 +34,8 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	ret = g_dnl_register(usb_dnl_gadget);
 	if (ret) {
 		pr_err("g_dnl_register failed");
-		return CMD_RET_FAILURE;
+		ret = CMD_RET_FAILURE;
+		goto err_detach;
 	}
 
 #ifdef CONFIG_DFU_TIMEOUT
@@ -106,6 +107,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
 	}
 exit:
 	g_dnl_unregister();
+err_detach:
 	usb_gadget_release(usbctrl_index);
 
 	if (dfu_reset)
-- 
2.40.1



More information about the U-Boot mailing list