usb: gdaget: f_mass_storage: various fixes
cover usb: gdaget: f_mass_storage: various fixes
- remove useless "rc" local variable
- optimize schedule() call
optimize schedule() call
---
Patrice Chotard (2):
usb: gadget: f_mass_storage: Remove useless rc variable
usb: gadget: f_mass_storage: Optimize schedule() call
drivers/usb/gadget/f_mass_storage.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
---
base-commit: 36c377b9859ffb53eb1e39ea31e8d96d1e0fe1e5
change-id: 20260817-move_schedule_inside_sleep_thread-134c7ed2f87a
Best regards,
Signature · 1 line
Patrice Chotard <[email protected]>
PATCH 1/2 usb: gadget: f_mass_storage: Remove useless rc variable
rc variable is used as sleep_thread() return value. It's initialized to 0 and never updated inside sleep_thread(), remove it and return 0.
--- drivers/usb/gadget/f_mass_storage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/f_mass_storage.c +2 -2
@@ -650,7 +650,6 @@ static void busy_indicator(void)static int sleep_thread (struct fsg_common *common) { -int rc =0 ;int i =0 , k =0 ;/* Wait until a signal arrives or we are woken up */
@@ -684,7 +683,8 @@ static int sleep_thread(struct fsg_common *common)dm_usb_gadget_handle_interrupts (udcdev); } common->thread_wakeup_needed =0 ; -return rc; + +return 0 ; }/*-------------------------------------------------------------------------*/
Signature · 1 line
2.43.0
Re: [PATCH 1/2] usb: gadget: f_mass_storage: Remove useless rc variable
Quoted 5 lines · Patrice Chotard
rc variable is used as
sleep_thread()return value. It's initialized to 0 and never updated insidesleep_thread(), remove it and return 0.Signed-off-by Patrice Chotard <[email protected]>
Quoted 27 lines
--- drivers/usb/gadget/f_mass_storage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/gadget/f_mass_storage.c +2
-2@@ -650,7 +650,6 @@ static void busy_indicator(void)static int sleep_thread (struct fsg_common *common) { -int rc =0 ;int i =0 , k =0 ;/* Wait until a signal arrives or we are woken up */ @@ -684,7 +683,8 @@ static int sleep_thread(struct fsg_common *common)dm_usb_gadget_handle_interrupts (udcdev); } common->thread_wakeup_needed =0 ; -return rc; + +return 0 ; }/*-------------------------------------------------------------------------*/
Re: [PATCH 1/2] usb: gadget: f_mass_storage: Remove useless rc variable
In reply to Patrice ChotardQuoted 5 lines · Patrice Chotard
rc variable is used as
sleep_thread()return value. It's initialized to 0 and never updated insidesleep_thread(), remove it and return 0.Signed-off-by Patrice Chotard <[email protected]>
Re: [PATCH 1/2] usb: gadget: f_mass_storage: Remove useless rc variable
In reply to Patrice ChotardHi Patrice,
Thank you for the patch.
Quoted 5 lines · Patrice Chotard
rc variable is used as
sleep_thread()return value. It's initialized to 0 and never updated insidesleep_thread(), remove it and return 0.Signed-off-by Patrice Chotard <[email protected]>
PATCH 2/2 usb: gadget: f_mass_storage: Optimize schedule() call
In reply to Patrice Chotardschedule 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.
--- drivers/usb/gadget/f_mass_storage.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/gadget/f_mass_storage.c +5 -2
@@ -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 ;
Signature · 1 line
2.43.0
Re: [PATCH 2/2] usb: gadget: f_mass_storage: Optimize schedule() call
Hi Patrice,
Thank you for the patch and sorry for the review delays.
Quoted 29 lines · Patrice Chotard
schedule was added in
sleep_thread()by commit4b6a3e860878("usb: gadget:f_mass_storage: Addschedule()insleep_thread()"). to ensure that watchdog is still reset periodically even on platform that doesn't implementg_dnl_board_usb_cable_connected()and in case USB cable is not connected.Instead of calling
schedule()for eachfor()loop iteration, callschedule()only in caseg_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(-)drivers/usb/gadget/f_mass_storage.c +1
-0@@ -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 (;;) {
drivers/usb/gadget/f_mass_storage.c static int sleep_thread(struct fsg_common *common) · line 681
Quoted 9 lines
drivers/usb/gadget/f_mass_storage.c +4
-1@@ -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 ();
What happens on boards that override g_dnl_board_usb_cable_connected() that return a positive value?
Per my understanding, schedule() will never be called, and the watchdog will be triggered at some point, no?
Quoted 11 lines
drivers/usb/gadget/f_mass_storage.c +0
-1k =0 ; } -schedule ();dm_usb_gadget_handle_interrupts (udcdev); } common->thread_wakeup_needed =0 ;Signature · 1 line
2.43.0
Re: [PATCH 2/2] usb: gadget: f_mass_storage: Optimize schedule() call
Quoted 48 lines · Mattijs Korpershoek
Hi Patrice,
Thank you for the patch and sorry for the review delays.
Quoted 29 lines · Patrice Chotard
schedule was added in
sleep_thread()by commit4b6a3e860878("usb: gadget:f_mass_storage: Addschedule()insleep_thread()"). to ensure that watchdog is still reset periodically even on platform that doesn't implementg_dnl_board_usb_cable_connected()and in case USB cable is not connected.Instead of calling
schedule()for eachfor()loop iteration, callschedule()only in caseg_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(-)drivers/usb/gadget/f_mass_storage.c +1
-0@@ -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 (;;) {drivers/usb/gadget/f_mass_storage.c static int sleep_thread(struct fsg_common *common) · line 681
Quoted 9 lines
drivers/usb/gadget/f_mass_storage.c +4
-1@@ -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 ();What happens on boards that override
g_dnl_board_usb_cable_connected()that return a positive value?
Quoted 2 lines
Per my understanding,
schedule()will never be called, and the watchdog will be triggered at some point, no?
Hi Mattijs,
In case g_dnl_board_usb_cable_connected() returns 1 (it's currently the case on STM32MP157c-DK2 board), we stay inside sleep_thread() for(;;) loop until common->thread_wakeup_needed is set to 1 by wakeup_thread().
wakeup_thread() is called periodically (around every second, it was what i observed during testing) by either bulk_out_complete() or bulk_in_complete().
Then we came back in fsg_main_thread() which was sleep_thread() caller, and came back in while(1) loop of do_usb_mass_storage() where schedule() is called.
So watchdog is reset periodically.
Patrice
Quoted 12 lines
Quoted 12 lines
drivers/usb/gadget/f_mass_storage.c +0
-1k =0 ; } -schedule ();dm_usb_gadget_handle_interrupts (udcdev); } common->thread_wakeup_needed =0 ;Signature · 1 line
2.43.0
Re: [PATCH 2/2] usb: gadget: f_mass_storage: Optimize schedule() call
Quoted 74 lines · Patrice CHOTARD
Quoted 48 lines · Mattijs Korpershoek
Hi Patrice,
Thank you for the patch and sorry for the review delays.
Quoted 29 lines · Patrice Chotard
schedule was added in
sleep_thread()by commit4b6a3e860878("usb: gadget:f_mass_storage: Addschedule()insleep_thread()"). to ensure that watchdog is still reset periodically even on platform that doesn't implementg_dnl_board_usb_cable_connected()and in case USB cable is not connected.Instead of calling
schedule()for eachfor()loop iteration, callschedule()only in caseg_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(-)drivers/usb/gadget/f_mass_storage.c +1
-0@@ -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 (;;) {drivers/usb/gadget/f_mass_storage.c static int sleep_thread(struct fsg_common *common) · line 681
Quoted 9 lines
drivers/usb/gadget/f_mass_storage.c +4
-1@@ -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 ();What happens on boards that override
g_dnl_board_usb_cable_connected()that return a positive value?Quoted 2 lines
Per my understanding,
schedule()will never be called, and the watchdog will be triggered at some point, no?Hi Mattijs,
In case
g_dnl_board_usb_cable_connected()returns 1 (it's currently the case on STM32MP157c-DK2 board), we stay insidesleep_thread()for(;;) loop untilcommon->thread_wakeup_neededis set to 1 bywakeup_thread().
wakeup_thread()is called periodically (around every second, it was what i observed during testing) by eitherbulk_out_complete()orbulk_in_complete().Then we came back in
fsg_main_thread()which wassleep_thread()caller, and came back in while(1) loop ofdo_usb_mass_storage()whereschedule()is called.So watchdog is reset periodically.
Patrice
Quoted 5 lines
Quoted 5 lines
drivers/usb/gadget/f_mass_storage.c +0
-0k =0 ; }
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
drivers/usb/gadget/f_mass_storage.c +0
-1-schedule ();dm_usb_gadget_handle_interrupts (udcdev); } common->thread_wakeup_needed =0 ;Signature · 1 line
2.43.0
Hi Mattijs
We got a discussion with Marek on the previous version of this patch [1]. Marek's proposal is more simple/efficient than this current patch.
This patch will be abandoned.
Thanks
Patrice
[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Re: [PATCH 2/2] usb: gadget: f_mass_storage: Optimize schedule() call
Quoted 90 lines · Patrice CHOTARD
Quoted 74 lines · Patrice CHOTARD
Quoted 48 lines · Mattijs Korpershoek
Hi Patrice,
Thank you for the patch and sorry for the review delays.
Quoted 29 lines · Patrice Chotard
schedule was added in
sleep_thread()by commit4b6a3e860878("usb: gadget:f_mass_storage: Addschedule()insleep_thread()"). to ensure that watchdog is still reset periodically even on platform that doesn't implementg_dnl_board_usb_cable_connected()and in case USB cable is not connected.Instead of calling
schedule()for eachfor()loop iteration, callschedule()only in caseg_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(-)drivers/usb/gadget/f_mass_storage.c +1
-0@@ -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 (;;) {drivers/usb/gadget/f_mass_storage.c static int sleep_thread(struct fsg_common *common) · line 681
Quoted 9 lines
drivers/usb/gadget/f_mass_storage.c +4
-1@@ -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 ();What happens on boards that override
g_dnl_board_usb_cable_connected()that return a positive value?Quoted 2 lines
Per my understanding,
schedule()will never be called, and the watchdog will be triggered at some point, no?Hi Mattijs,
In case
g_dnl_board_usb_cable_connected()returns 1 (it's currently the case on STM32MP157c-DK2 board), we stay insidesleep_thread()for(;;) loop untilcommon->thread_wakeup_neededis set to 1 bywakeup_thread().
wakeup_thread()is called periodically (around every second, it was what i observed during testing) by eitherbulk_out_complete()orbulk_in_complete().Then we came back in
fsg_main_thread()which wassleep_thread()caller, and came back in while(1) loop ofdo_usb_mass_storage()whereschedule()is called.So watchdog is reset periodically.
Patrice
Quoted 5 lines
Quoted 5 lines
drivers/usb/gadget/f_mass_storage.c +0
-0k =0 ; }Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
drivers/usb/gadget/f_mass_storage.c +0
-1-schedule ();dm_usb_gadget_handle_interrupts (udcdev); } common->thread_wakeup_needed =0 ;Signature · 1 line
2.43.0Hi Mattijs
We got a discussion with Marek on the previous version of this patch [1]. Marek's proposal is more simple/efficient than this current patch.
Quoted 6 lines
This patch will be abandoned.
Thanks
Patrice[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
For information
I submitted Marek's proposal: https://patchwork.ozlabs.org/project/uboot/patch/20260917-ums_increase_ctrl-c_responsiveness-v1-1-95305f044ec2@foss.st.com/
Thanks
Patrice
Re: (subset) [PATCH 0/2] usb: gdaget: f_mass_storage: various fixes
In reply to Patrice ChotardHi,
Quoted 6 lines · Patrice Chotard
- remove useless "rc" local variable
- optimizeschedule()calloptimize
schedule()call
Thanks, Applied to https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu (u-boot-dfu)
[1/2] usb: gadget: f_mass_storage: Remove useless rc variable
https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/79af010ce624ce8908202e4937081f3e4c9d69a0
--
Mattijs