[PATCH 2/2] usb: gadget: f_mass_storage: Optimize schedule() call

Patrice Chotard <[email protected]>
Newsgroups gmane.comp.boot-loaders.u-boot
Message-ID <20260817-move_schedule_inside_sleep_thread-v1-2-0023194e8c47__11830.8256309078$1786981291$gmane$org@foss.st.com>
schedule was added in sleep_thread() by commit 4b6a3e860878
("usb: gadget: f_mass_storage: Add schedule() in sleep_thread()").
to ensure that watchdog is still reset periodically even on platform
that doesn't implement g_dnl_board_usb_cable_connected() and in case USB
cable is not connected.

Instead of calling schedule() for each for() loop iteration, call
schedule() only in case g_dnl_board_usb_cable_connected() is not
overloaded, in this particular case, g_dnl_board_usb_cable_connected()'s
return value is -EOPNOTSUPP.

Signed-off-by: Patrice Chotard <[email protected]>
---
 drivers/usb/gadget/f_mass_storage.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 621852080e2..f467693d2cb 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -651,6 +651,7 @@ static void busy_indicator(void)
 static int sleep_thread(struct fsg_common *common)
 {
 	int i = 0, k = 0;
+	int ret;
 
 	/* Wait until a signal arrives or we are woken up */
 	for (;;) {
@@ -673,13 +674,15 @@ static int sleep_thread(struct fsg_common *common)
 				return -EPIPE;
 
 			/* Check cable connection */
-			if (!g_dnl_board_usb_cable_connected())
+			ret = g_dnl_board_usb_cable_connected();
+			if (!ret)
 				return -EIO;
+			if (ret == -EOPNOTSUPP)
+				schedule();
 
 			k = 0;
 		}
 
-		schedule();
 		dm_usb_gadget_handle_interrupts(udcdev);
 	}
 	common->thread_wakeup_needed = 0;

-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.