linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Pierre Ossman <drzeus-mmc@drzeus.cx>,
	Zdenek Kabelac <zdenek.kabelac@gmail.com>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: [Bug 10030] Suspend doesn't work when SD card is inserted
Date: Wed, 20 Feb 2008 23:15:48 +0100	[thread overview]
Message-ID: <200802202315.49032.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0802201604260.7212-100000@iolanthe.rowland.org>

On Wednesday, 20 of February 2008, Alan Stern wrote:
> On Wed, 20 Feb 2008, Pierre Ossman wrote:
> 
> > > And why not simply fail the suspend if the resume routine doesn't exist
> > > and the suspend routine does?  Maybe with an error message in the
> > > system log.
> > 
> > For the asymmetric case, I guess that would do. But I still want to remove devices when the bus handler has no suspend handling.
> 
> Then it appears the correct approach is to use the new 
> device_pm_schedule_removal() routine.  It schedules the removal of a 
> suspended device for a time when the system suspend is over.

Well, below is an uncompiled and untested but illustrating the idea that
might allow people not to bother with device_pm_schedule_removal()
explicitly and can fix the issue at hand.

[There are some cases that need handling and are not covered here.]

Please have a look.

Thanks,
Rafael

---
 drivers/base/core.c        |    5 ++++-
 drivers/base/power/main.c  |   22 ++++++++++++++++++++++
 drivers/base/power/power.h |    5 +++++
 3 files changed, 31 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/base/power/main.c
===================================================================
--- linux-2.6.orig/drivers/base/power/main.c
+++ linux-2.6/drivers/base/power/main.c
@@ -59,6 +59,26 @@ static DECLARE_RWSEM(pm_sleep_rwsem);
 
 int (*platform_enable_wakeup)(struct device *dev, int is_on);
 
+static struct task_struct *suspending_task;
+static DEFINE_MUTEX(suspending_task_mtx);
+
+bool in_suspend_context(void)
+{
+	bool result;
+
+	mutex_lock(&suspending_task_mtx);
+	result = (suspending_task == current);
+	mutex_unlock(&suspending_task_mtx);
+	return result;
+}
+
+static void set_suspending_task(struct task_struct *task)
+{
+	mutex_lock(&suspending_task_mtx);
+	suspending_task = task;
+	mutex_unlock(&suspending_task_mtx);
+}
+
 /**
  *	device_pm_add - add a device to the list of active devices
  *	@dev:	Device to be added to the list
@@ -272,6 +292,7 @@ static void dpm_resume(void)
 		mutex_lock(&dpm_list_mtx);
 	}
 	mutex_unlock(&dpm_list_mtx);
+	set_suspending_task(NULL);
 }
 
 /**
@@ -460,6 +481,7 @@ static int dpm_suspend(pm_message_t stat
 {
 	int error = 0;
 
+	set_suspending_task(current);
 	mutex_lock(&dpm_list_mtx);
 	while (!list_empty(&dpm_locked)) {
 		struct list_head *entry = dpm_locked.prev;
Index: linux-2.6/drivers/base/core.c
===================================================================
--- linux-2.6.orig/drivers/base/core.c
+++ linux-2.6/drivers/base/core.c
@@ -1162,7 +1162,10 @@ void device_destroy(struct class *class,
 	dev = class_find_device(class, &devt, __match_devt);
 	if (dev) {
 		put_device(dev);
-		device_unregister(dev);
+		if (in_suspend_context())
+			device_pm_schedule_removal(dev);
+		else
+			device_unregister(dev);
 	}
 }
 EXPORT_SYMBOL_GPL(device_destroy);
Index: linux-2.6/drivers/base/power/power.h
===================================================================
--- linux-2.6.orig/drivers/base/power/power.h
+++ linux-2.6/drivers/base/power/power.h
@@ -11,6 +11,7 @@ static inline struct device *to_device(s
 	return container_of(entry, struct device, power.entry);
 }
 
+extern bool in_suspend_context(void);
 extern void device_pm_add(struct device *);
 extern void device_pm_remove(struct device *);
 extern int pm_sleep_lock(void);
@@ -18,6 +19,10 @@ extern void pm_sleep_unlock(void);
 
 #else /* CONFIG_PM_SLEEP */
 
+static inline bool in_suspend_context(void)
+{
+	return false;
+}
 
 static inline void device_pm_add(struct device *dev)
 {

  reply	other threads:[~2008-02-20 22:18 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080219232338.E9A24108068@picon.linux-foundation.org>
2008-02-20 16:42 ` [Bug 10030] Suspend doesn't work when SD card is inserted Alan Stern
2008-02-20 17:30   ` Pierre Ossman
2008-02-20 19:26     ` Alan Stern
2008-02-20 20:51       ` Pierre Ossman
2008-02-20 20:58         ` Rafael J. Wysocki
2008-02-20 21:06         ` Alan Stern
2008-02-20 22:15           ` Rafael J. Wysocki [this message]
2008-02-20 22:24             ` Alan Stern
2008-02-20 22:41               ` Rafael J. Wysocki
2008-02-21  0:02               ` Rafael J. Wysocki
2008-02-21 16:27                 ` Alan Stern
2008-02-21 16:38                   ` Rafael J. Wysocki
2008-02-21 17:48                     ` Alan Stern
2008-02-21 22:47                       ` Rafael J. Wysocki
2008-02-21 23:05                         ` Alan Stern
2008-02-23  1:30                           ` Rafael J. Wysocki
2008-02-23  4:39                             ` Alan Stern
2008-02-23 20:16                               ` Rafael J. Wysocki
2008-02-23 23:29                                 ` Alan Stern
2008-02-24  0:19                                   ` Rafael J. Wysocki
2008-02-24  3:25                                     ` Alan Stern
2008-02-24  4:26                                       ` [linux-pm] " Alan Stern
2008-02-24 14:00                                         ` Rafael J. Wysocki
2008-02-24 15:33                                           ` Bugs in MMC [was: [Bug 10030] Suspend doesn't work when SD card is inserted] Alan Stern
2008-02-25 17:41                                             ` Pierre Ossman
2008-02-25 17:58                                               ` Alan Stern
2008-02-25 18:31                                                 ` Pierre Ossman
2008-02-25 20:00                                                   ` Alan Stern
2008-03-01 14:11                                                     ` Pierre Ossman
2008-03-01 14:36                                                       ` Alan Stern
2008-03-01 14:47                                                         ` Pierre Ossman
2008-02-25 22:51                                               ` Felipe Balbi
2008-03-03 21:59                                               ` David Brownell
2008-03-04  6:03                                                 ` Pierre Ossman
2008-03-04  9:44                                                   ` David Brownell
2008-03-04  9:58                                                     ` Pierre Ossman
2008-03-06 21:23                                                       ` David Brownell
2008-03-04 17:53                                                     ` Alan Stern
2008-03-04 18:53                                                       ` David Brownell
2008-03-04 19:51                                                         ` Alan Stern
2008-03-04 20:30                                                           ` David Brownell
2008-03-04 21:00                                                             ` Alan Stern
2008-03-06 15:55                                                               ` Pavel Machek
2008-03-06 20:33                                                                 ` Alan Stern
2008-03-06 20:53                                                                   ` Zdenek Kabelac
2008-03-06 21:31                                                                     ` Rafael J. Wysocki
2008-03-04 17:50                                                 ` Alan Stern
2008-02-24 13:33                                       ` [Bug 10030] Suspend doesn't work when SD card is inserted Rafael J. Wysocki
2008-02-24 20:25                                         ` Rafael J. Wysocki
2008-02-24 20:45                                           ` Alan Stern
2008-02-24 20:56                                             ` Rafael J. Wysocki
2008-02-24 21:11                                               ` Alan Stern
2008-02-24 22:18                                                 ` Rafael J. Wysocki
2008-02-24 13:51                                       ` Rafael J. Wysocki
2008-02-24 19:27                                         ` Alan Stern
2008-02-24 19:42                                           ` Zdenek Kabelac
2008-02-24 20:09                                             ` Rafael J. Wysocki
2008-02-24 18:21                                       ` Pavel Machek
2008-02-24 19:03                                         ` Alan Stern
2008-02-24 20:11                                           ` Pavel Machek
2008-02-24 20:33                                             ` Alan Stern
2008-02-24 21:42                                               ` Pavel Machek
2008-02-24 22:21                                                 ` Rafael J. Wysocki
2008-02-25  2:21                                                   ` Alan Stern
2008-02-25 11:41                                                     ` Rafael J. Wysocki
     [not found]                                                       ` <c4e36d110802250402q7312a488idf752e07db7504e8@mail.gmail.com>
2008-02-25 12:31                                                         ` Rafael J. Wysocki
2008-02-25  2:19                                                 ` Alan Stern
2008-02-25  9:03                                                   ` using long instead of atomic_t when only set/read is required (was Re: [Bug 10030] Suspend doesn't work when SD card is inserted) Pavel Machek
2008-02-25 14:46                                                     ` Alan Stern
2008-03-03 12:08                                                       ` [patch] Re: using long instead of atomic_t when only set/read is required Pavel Machek
2008-03-03 15:42                                                         ` Alan Stern
2008-03-03 15:53                                                           ` Alan Cox
2008-03-03 17:11                                                             ` Alan Stern
2008-03-03 17:26                                                               ` Linus Torvalds
2008-03-03 17:44                                                                 ` Pavel Machek
2008-03-03 19:27                                                                   ` Alan Stern
2008-03-06 15:58                                                                 ` Mark Lord
2008-03-06 16:11                                                                   ` Linus Torvalds
2008-03-06 16:27                                                                     ` Mark Lord
2008-03-03 17:16                                                             ` Nick Piggin
2008-03-03 17:31                                                               ` Paul E. McKenney
2008-03-03 17:33                                                               ` Alan Cox
2008-03-03 17:22                                                           ` Paul E. McKenney
2008-03-03 15:48                                                         ` Alan Cox
2008-03-03 17:24                                                           ` Pavel Machek
2008-03-03 20:27                                                             ` Rafael J. Wysocki
2008-03-03 21:12                                                               ` Paul E. McKenney
2008-03-03 22:23                                                               ` Linus Torvalds
2008-03-04 23:32                                                             ` Peter Hartley
2008-03-04 23:54                                                               ` Rafael J. Wysocki
2008-03-05  0:26                                                                 ` Paul E. McKenney
2008-02-25 11:40                                                   ` [Bug 10030] Suspend doesn't work when SD card is inserted Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802202315.49032.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=drzeus-mmc@drzeus.cx \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=zdenek.kabelac@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).