usb: gadget: f_mass_storage: Shut down mass storage device when USB connection is shut, down.
PATCH 1/1 usb: gadget: f_mass_storage: Shut down mass storage device when USB connection is shut, down.
f_mass_storage continues to send out packets after the connection to the USB host has been terminated, ignoring the error status.
--- drivers/usb/gadget/function/f_mass_storage.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/gadget/function/f_mass_storage.c +4 -0
@@ -529,6 +529,10 @@ static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,/* We can't do much more than wait for a reset */ req->status = rc; +if (rc==-ESHUTDOWN ) { + fsg->common->running =0 ; + } +/* * Note: currently the net2280 driver fails zero-length * submissions if DMA is enabled.
Signature · 5 lines
2.33.0 Flo -- Machines can do the work, so people have time to think.
Quoted 2 lines · Florian Faber
f_mass_storagecontinues to send out packets after the connection to the USB host has been terminated, ignoring the error status.
The driver doesn't send packets after the connection has been terminated -- that would be impossible. It may _try_ to send packets, but it can't actually send anything unless the hosts asks for the data. There's nothing wrong with trying and failing.
Quoted 12 lines
Signed-off-by Florian Faber <[email protected]>--- drivers/usb/gadget/function/f_mass_storage.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/gadget/function/f_mass_storage.c +0
-0
drivers/usb/gadget/function/f_mass_storage.c static int start_transfer(struct fsg_dev *fsg, struct · line 536
Quoted 8 lines
drivers/usb/gadget/function/f_mass_storage.c +4
-0@@ -529,6 +529,10 @@ static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,/* We can't do much more than wait for a reset */ req->status = rc; +if (rc==-ESHUTDOWN ) { + fsg->common->running =0 ; + } +
This is wrong because it isn't what common->running means. common->running means that the mass-storage configuration has been set by the host; it has nothing to do with whether or not the USB cable is connected.
Also the new code doesn't conform to the kernel's programming style (missing spaces around the "==" sign and braces not needed for a single-line conditional statement). And if it were a serious change, it should be merged with the conditional statement that follows, which also tests whether rc is -ESHUTDOWN.
Alan Stern
Quoted 8 lines · Alan Stern
Quoted 2 lines · Florian Faber
f_mass_storagecontinues to send out packets after the connection to the USB host has been terminated, ignoring the error status.The driver doesn't send packets after the connection has been terminated -- that would be impossible. It may _try_ to send packets, but it can't actually send anything unless the hosts asks for the data. There's nothing wrong with trying and failing.
Correct, that could have been expressed more clearly.
Quoted 17 lines
Quoted 17 lines
Signed-off-by Florian Faber <[email protected]>--- drivers/usb/gadget/function/f_mass_storage.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/gadget/function/f_mass_storage.c +0
-0@@ -529,6 +529,10 @@ static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,/* We can't do much more than wait for a reset */ req->status = rc;
Quoted 8 lines
drivers/usb/gadget/function/f_mass_storage.c static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, · line 535
Quoted 4 lines
drivers/usb/gadget/function/f_mass_storage.c +4
-0+if (rc==-ESHUTDOWN ) { + fsg->common->running =0 ; + } +This is wrong because it isn't what
common->runningmeans.common->runningmeans that the mass-storage configuration has been set by the host; it has nothing to do with whether or not the USB cable is connected.
So it is OK to keep the thread running and _trying_ to send out packets all the time until another USB host is plugged in, wasting resources?
I would argue that the removal of a USB host is an implicit configuration change.
Flo
Signature · 1 line
Machines can do the work, so people have time to think.
Quoted 39 lines · Florian Faber
Quoted 8 lines · Alan Stern
Quoted 2 lines · Florian Faber
f_mass_storagecontinues to send out packets after the connection to the USB host has been terminated, ignoring the error status.The driver doesn't send packets after the connection has been terminated -- that would be impossible. It may _try_ to send packets, but it can't actually send anything unless the hosts asks for the data. There's nothing wrong with trying and failing.
Correct, that could have been expressed more clearly.
Quoted 17 lines
Quoted 17 lines
Signed-off-by Florian Faber <[email protected]>--- drivers/usb/gadget/function/f_mass_storage.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/gadget/function/f_mass_storage.c +0
-0@@ -529,6 +529,10 @@ static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,/* We can't do much more than wait for a reset */ req->status = rc;Quoted 8 lines
drivers/usb/gadget/function/f_mass_storage.c static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, · line 535
Quoted 4 lines
drivers/usb/gadget/function/f_mass_storage.c +4
-0+if (rc==-ESHUTDOWN ) { + fsg->common->running =0 ; + } +This is wrong because it isn't what
common->runningmeans.common->runningmeans that the mass-storage configuration has been set by the host; it has nothing to do with whether or not the USB cable is connected.
Quoted 2 lines
So it is OK to keep the thread running and _trying_ to send out packets all the time until another USB host is plugged in, wasting resources?
Not all the time. When the disconnect occurs, the composite core's disconnect handler will reset the current configuration, thereby calling the driver's do_set_interface() routine, which will set common->running to 0.
Quoted 2 lines
I would argue that the removal of a USB host is an implicit configuration change.
Indeed it is. And it is treated as such by the existing code.
Alan Stern