* [PATCH v2] usb: gadget: f_mass_storage: call try_to_freeze only when its safe
@ 2013-11-07 14:06 George Cherian
2013-11-07 15:24 ` Alan Stern
0 siblings, 1 reply; 2+ messages in thread
From: George Cherian @ 2013-11-07 14:06 UTC (permalink / raw)
To: balbi, stern, bigeasy; +Cc: gregkh, linux-usb, linux-kernel, George Cherian
Call try_to_freeze() in sleep_thread() only when its safe to sleep.
do_read() and do_write() calls sleep_thread with lock held.
Make sure these wont call try_to_freeze() by passing can_freeze flag
to sleep_thread.
Calling try_to_freeze() with a lock hold was done since day one in
f_mass_storage but since commit 0f9548ca1 ("lockdep: check that no
locks held at freeze time") lockdep complains about it.
Signed-off-by: George Cherian <george.cherian@ti.com>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
change from v1 -> v2
amend the commit log
drivers/usb/gadget/f_mass_storage.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index a03ba2c..f2d0d4b 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -602,13 +602,14 @@ static bool start_out_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
return true;
}
-static int sleep_thread(struct fsg_common *common)
+static int sleep_thread(struct fsg_common *common, bool can_freeze)
{
int rc = 0;
/* Wait until a signal arrives or we are woken up */
for (;;) {
- try_to_freeze();
+ if (can_freeze)
+ try_to_freeze();
set_current_state(TASK_INTERRUPTIBLE);
if (signal_pending(current)) {
rc = -EINTR;
@@ -682,7 +683,7 @@ static int do_read(struct fsg_common *common)
/* Wait for the next buffer to become available */
bh = common->next_buffhd_to_fill;
while (bh->state != BUF_STATE_EMPTY) {
- rc = sleep_thread(common);
+ rc = sleep_thread(common, false);
if (rc)
return rc;
}
@@ -937,7 +938,7 @@ static int do_write(struct fsg_common *common)
}
/* Wait for something to happen */
- rc = sleep_thread(common);
+ rc = sleep_thread(common, false);
if (rc)
return rc;
}
@@ -1504,7 +1505,7 @@ static int throw_away_data(struct fsg_common *common)
}
/* Otherwise wait for something to happen */
- rc = sleep_thread(common);
+ rc = sleep_thread(common, true);
if (rc)
return rc;
}
@@ -1625,7 +1626,7 @@ static int send_status(struct fsg_common *common)
/* Wait for the next buffer to become available */
bh = common->next_buffhd_to_fill;
while (bh->state != BUF_STATE_EMPTY) {
- rc = sleep_thread(common);
+ rc = sleep_thread(common, true);
if (rc)
return rc;
}
@@ -1828,7 +1829,7 @@ static int do_scsi_command(struct fsg_common *common)
bh = common->next_buffhd_to_fill;
common->next_buffhd_to_drain = bh;
while (bh->state != BUF_STATE_EMPTY) {
- rc = sleep_thread(common);
+ rc = sleep_thread(common, true);
if (rc)
return rc;
}
@@ -2174,7 +2175,7 @@ static int get_next_command(struct fsg_common *common)
/* Wait for the next buffer to become available */
bh = common->next_buffhd_to_fill;
while (bh->state != BUF_STATE_EMPTY) {
- rc = sleep_thread(common);
+ rc = sleep_thread(common, true);
if (rc)
return rc;
}
@@ -2193,7 +2194,7 @@ static int get_next_command(struct fsg_common *common)
/* Wait for the CBW to arrive */
while (bh->state != BUF_STATE_FULL) {
- rc = sleep_thread(common);
+ rc = sleep_thread(common, true);
if (rc)
return rc;
}
@@ -2379,7 +2380,7 @@ static void handle_exception(struct fsg_common *common)
}
if (num_active == 0)
break;
- if (sleep_thread(common))
+ if (sleep_thread(common, true))
return;
}
@@ -2516,7 +2517,7 @@ static int fsg_main_thread(void *common_)
}
if (!common->running) {
- sleep_thread(common);
+ sleep_thread(common, true);
continue;
}
--
1.8.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] usb: gadget: f_mass_storage: call try_to_freeze only when its safe
2013-11-07 14:06 [PATCH v2] usb: gadget: f_mass_storage: call try_to_freeze only when its safe George Cherian
@ 2013-11-07 15:24 ` Alan Stern
0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2013-11-07 15:24 UTC (permalink / raw)
To: George Cherian; +Cc: balbi, bigeasy, gregkh, linux-usb, linux-kernel
On Thu, 7 Nov 2013, George Cherian wrote:
> Call try_to_freeze() in sleep_thread() only when its safe to sleep.
> do_read() and do_write() calls sleep_thread with lock held.
> Make sure these wont call try_to_freeze() by passing can_freeze flag
> to sleep_thread.
>
> Calling try_to_freeze() with a lock hold was done since day one in
> f_mass_storage but since commit 0f9548ca1 ("lockdep: check that no
> locks held at freeze time") lockdep complains about it.
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Although I would have preferred it if you spelled "it's" and "won't"
with apostrophes in the first paragraph. Without the apostrophes,
"its" is a possessive pronoun (meaning "something belonging to it")
and "wont" is a noun (meaning "habit").
Alan Stern
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-07 15:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-07 14:06 [PATCH v2] usb: gadget: f_mass_storage: call try_to_freeze only when its safe George Cherian
2013-11-07 15:24 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).