From: Rafael J. Wysocki Date: Mon, 17 Dec 2007 00:03:46 +0000 (+0100) Subject: Freezer: Fix APM emulation breakage X-Git-Tag: v2.6.23.15~34 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=b98ebe01754d083dbdfe7bd3cd46fa2106fad4ef;p=karo-tx-linux.git Freezer: Fix APM emulation breakage The APM emulation is currently broken as a result of commit 831441862956fffa17b9801db37e6ea1650b0f69 "Freezer: make kernel threads nonfreezable by default" that removed the PF_NOFREEZE annotations from apm_ioctl() without adding the appropriate freezer hooks. Fix it and remove the unnecessary variable flags from apm_ioctl(). This problem has been fixed in the mainline by commit cb43c54ca05c01533c45e4d3abfe8f99b7acf624 "Freezer: Fix APM emulation breakage". Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c index ec116df919d9..72183bd1b3fc 100644 --- a/drivers/char/apm-emulation.c +++ b/drivers/char/apm-emulation.c @@ -295,7 +295,6 @@ static int apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) { struct apm_user *as = filp->private_data; - unsigned long flags; int err = -EINVAL; if (!as->suser || !as->writer) @@ -331,10 +330,16 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) * Wait for the suspend/resume to complete. If there * are pending acknowledges, we wait here for them. */ - flags = current->flags; + freezer_do_not_count(); wait_event(apm_suspend_waitqueue, as->suspend_state == SUSPEND_DONE); + + /* + * Since we are waiting until the suspend is done, the + * try_to_freeze() in freezer_count() will not trigger + */ + freezer_count(); } else { as->suspend_state = SUSPEND_WAIT; mutex_unlock(&state_lock); @@ -362,14 +367,10 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) * Wait for the suspend/resume to complete. If there * are pending acknowledges, we wait here for them. */ - flags = current->flags; - - wait_event_interruptible(apm_suspend_waitqueue, + wait_event_freezable(apm_suspend_waitqueue, as->suspend_state == SUSPEND_DONE); } - current->flags = flags; - mutex_lock(&state_lock); err = as->suspend_result; as->suspend_state = SUSPEND_NONE; diff --git a/include/linux/freezer.h b/include/linux/freezer.h index efded00ad08c..7fa9500da1f4 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h @@ -4,6 +4,7 @@ #define FREEZER_H_INCLUDED #include +#include #ifdef CONFIG_PM_SLEEP /* @@ -126,6 +127,24 @@ static inline void set_freezable(void) current->flags &= ~PF_NOFREEZE; } +/* + * Freezer-friendly wrapper around wait_event_interruptible(), originally + * defined in + */ + +#define wait_event_freezable(wq, condition) \ +({ \ + int __retval; \ + do { \ + __retval = wait_event_interruptible(wq, \ + (condition) || freezing(current)); \ + if (__retval && !freezing(current)) \ + break; \ + else if (!(condition)) \ + __retval = -ERESTARTSYS; \ + } while (try_to_freeze()); \ + __retval; \ +}) #else /* !CONFIG_PM_SLEEP */ static inline int frozen(struct task_struct *p) { return 0; } static inline int freezing(struct task_struct *p) { return 0; } @@ -143,6 +162,10 @@ static inline void freezer_do_not_count(void) {} static inline void freezer_count(void) {} static inline int freezer_should_skip(struct task_struct *p) { return 0; } static inline void set_freezable(void) {} + +#define wait_event_freezable(wq, condition) \ + wait_event_interruptible(wq, condition) + #endif /* !CONFIG_PM_SLEEP */ #endif /* FREEZER_H_INCLUDED */