linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Fix alarmtimer suspend failure
@ 2020-01-24  5:58 Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 1/4] alarmtimer: Make alarmtimer platform device child of RTC device Stephen Boyd
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Stephen Boyd @ 2020-01-24  5:58 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner; +Cc: linux-kernel, Stephen Boyd

We recently ran into a suspend problem where the alarmtimer platform
driver's suspend function fails because the RTC that it's trying
to program is already suspended. This patch series fixes that problem
by making the platform device a child of the RTC.

The last two patches are non-critical changes to how we do the wakeup
and some code cleanup.

Changes from v2:
 * Picked up review tags from Doug
 * Removed extra space between - and 1 on first patch
 * Split last patch into two

Changes from v1:
 * Dropped first patch that got picked up
 * Reworked second patch to autogenerate the device id and use IS_ERR()

Stephen Boyd (4):
  alarmtimer: Make alarmtimer platform device child of RTC device
  alarmtimer: Use wakeup source from alarmtimer platform device
  alarmtimer: Make alarmtimer_get_rtcdev() a stub when
    CONFIG_RTC_CLASS=n
  alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality

 include/linux/alarmtimer.h |  4 ++++
 kernel/time/alarmtimer.c   | 40 +++++++++++++-------------------------
 2 files changed, 17 insertions(+), 27 deletions(-)


base-commit: bc80e6ad8ee12b0ee6c7d05faf1ebd3f2fb8f1e5
-- 
Sent by a computer, using git, on the internet


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 1/4] alarmtimer: Make alarmtimer platform device child of RTC device
  2020-01-24  5:58 [PATCH v3 0/4] Fix alarmtimer suspend failure Stephen Boyd
@ 2020-01-24  5:58 ` Stephen Boyd
  2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 2/4] alarmtimer: Use wakeup source from alarmtimer platform device Stephen Boyd
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Stephen Boyd @ 2020-01-24  5:58 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner; +Cc: linux-kernel, Stephen Boyd, Douglas Anderson

The alarmtimer_suspend() function will fail if an RTC device is on a bus
such as SPI or i2c and that RTC device registers and probes after
alarmtimer_init() registers and probes the 'alarmtimer' platform device.
This is because system wide suspend suspends devices in the reverse
order of their probe. When alarmtimer_suspend() attempts to program the
RTC for a wakeup it will try to program an RTC device on a bus that has
already been suspended.

Let's move the alarmtimer device registration to be when the RTC we use
for wakeup is registered. Register the 'alarmtimer' platform device as a
child of the RTC device too, so that we can be guaranteed that the RTC
device won't be suspended when alarmtimer_suspend() is called.

Reported-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 kernel/time/alarmtimer.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 9dc7a0913190..205365906137 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -91,6 +91,7 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 	unsigned long flags;
 	struct rtc_device *rtc = to_rtc_device(dev);
 	struct wakeup_source *__ws;
+	struct platform_device *pdev;
 	int ret = 0;
 
 	if (rtcdev)
@@ -102,9 +103,11 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 		return -1;
 
 	__ws = wakeup_source_register(dev, "alarmtimer");
+	pdev = platform_device_register_data(dev, "alarmtimer",
+					     PLATFORM_DEVID_AUTO, NULL, 0);
 
 	spin_lock_irqsave(&rtcdev_lock, flags);
-	if (!rtcdev) {
+	if (__ws && !IS_ERR(pdev) && !rtcdev) {
 		if (!try_module_get(rtc->owner)) {
 			ret = -1;
 			goto unlock;
@@ -115,10 +118,14 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 		get_device(dev);
 		ws = __ws;
 		__ws = NULL;
+		pdev = NULL;
+	} else {
+		ret = -1;
 	}
 unlock:
 	spin_unlock_irqrestore(&rtcdev_lock, flags);
 
+	platform_device_unregister(pdev);
 	wakeup_source_unregister(__ws);
 
 	return ret;
@@ -905,8 +912,7 @@ static void get_boottime_timespec(struct timespec64 *tp)
  */
 static int __init alarmtimer_init(void)
 {
-	struct platform_device *pdev;
-	int error = 0;
+	int error;
 	int i;
 
 	alarmtimer_rtc_timer_init();
@@ -931,15 +937,7 @@ static int __init alarmtimer_init(void)
 	if (error)
 		goto out_if;
 
-	pdev = platform_device_register_simple("alarmtimer", -1, NULL, 0);
-	if (IS_ERR(pdev)) {
-		error = PTR_ERR(pdev);
-		goto out_drv;
-	}
 	return 0;
-
-out_drv:
-	platform_driver_unregister(&alarmtimer_driver);
 out_if:
 	alarmtimer_rtc_interface_remove();
 	return error;
-- 
Sent by a computer, using git, on the internet


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 2/4] alarmtimer: Use wakeup source from alarmtimer platform device
  2020-01-24  5:58 [PATCH v3 0/4] Fix alarmtimer suspend failure Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 1/4] alarmtimer: Make alarmtimer platform device child of RTC device Stephen Boyd
@ 2020-01-24  5:58 ` Stephen Boyd
  2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 3/4] alarmtimer: Make alarmtimer_get_rtcdev() a stub when CONFIG_RTC_CLASS=n Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 4/4] alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality Stephen Boyd
  3 siblings, 1 reply; 9+ messages in thread
From: Stephen Boyd @ 2020-01-24  5:58 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner; +Cc: linux-kernel, Stephen Boyd, Douglas Anderson

Use the wakeup source that can be associated with the 'alarmtimer'
platform device instead of registering another one by hand.

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 kernel/time/alarmtimer.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 205365906137..395d4a6db1b2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -58,8 +58,6 @@ static DEFINE_SPINLOCK(freezer_delta_lock);
 #endif
 
 #ifdef CONFIG_RTC_CLASS
-static struct wakeup_source *ws;
-
 /* rtc timer and device for setting alarm wakeups at suspend */
 static struct rtc_timer		rtctimer;
 static struct rtc_device	*rtcdev;
@@ -90,7 +88,6 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 {
 	unsigned long flags;
 	struct rtc_device *rtc = to_rtc_device(dev);
-	struct wakeup_source *__ws;
 	struct platform_device *pdev;
 	int ret = 0;
 
@@ -102,12 +99,13 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 	if (!device_may_wakeup(rtc->dev.parent))
 		return -1;
 
-	__ws = wakeup_source_register(dev, "alarmtimer");
 	pdev = platform_device_register_data(dev, "alarmtimer",
 					     PLATFORM_DEVID_AUTO, NULL, 0);
+	if (!IS_ERR(pdev))
+		device_init_wakeup(&pdev->dev, true);
 
 	spin_lock_irqsave(&rtcdev_lock, flags);
-	if (__ws && !IS_ERR(pdev) && !rtcdev) {
+	if (!IS_ERR(pdev) && !rtcdev) {
 		if (!try_module_get(rtc->owner)) {
 			ret = -1;
 			goto unlock;
@@ -116,8 +114,6 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 		rtcdev = rtc;
 		/* hold a reference so it doesn't go away */
 		get_device(dev);
-		ws = __ws;
-		__ws = NULL;
 		pdev = NULL;
 	} else {
 		ret = -1;
@@ -126,7 +122,6 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 	spin_unlock_irqrestore(&rtcdev_lock, flags);
 
 	platform_device_unregister(pdev);
-	wakeup_source_unregister(__ws);
 
 	return ret;
 }
@@ -293,7 +288,7 @@ static int alarmtimer_suspend(struct device *dev)
 		return 0;
 
 	if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
-		__pm_wakeup_event(ws, 2 * MSEC_PER_SEC);
+		pm_wakeup_event(dev, 2 * MSEC_PER_SEC);
 		return -EBUSY;
 	}
 
@@ -308,7 +303,7 @@ static int alarmtimer_suspend(struct device *dev)
 	/* Set alarm, if in the past reject suspend briefly to handle */
 	ret = rtc_timer_start(rtc, &rtctimer, now, 0);
 	if (ret < 0)
-		__pm_wakeup_event(ws, MSEC_PER_SEC);
+		pm_wakeup_event(dev, MSEC_PER_SEC);
 	return ret;
 }
 
-- 
Sent by a computer, using git, on the internet


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 3/4] alarmtimer: Make alarmtimer_get_rtcdev() a stub when CONFIG_RTC_CLASS=n
  2020-01-24  5:58 [PATCH v3 0/4] Fix alarmtimer suspend failure Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 1/4] alarmtimer: Make alarmtimer platform device child of RTC device Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 2/4] alarmtimer: Use wakeup source from alarmtimer platform device Stephen Boyd
@ 2020-01-24  5:58 ` Stephen Boyd
  2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd
  2020-01-24  5:58 ` [PATCH v3 4/4] alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality Stephen Boyd
  3 siblings, 1 reply; 9+ messages in thread
From: Stephen Boyd @ 2020-01-24  5:58 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner; +Cc: linux-kernel, Stephen Boyd

The export isn't there for the stubbed version of
alarmtimer_get_rtcdev() so this won't work if someone tries to call this
function when CONFIG_RTC_CLASS=n. Export a stub function in the header
file so that callers don't have to worry about linking against this
symbol. And rtcdev isn't used outside of this ifdef so we don't need to
redefine it as NULL. Drop that because we're nearby.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/alarmtimer.h | 4 ++++
 kernel/time/alarmtimer.c   | 5 -----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h
index 74748e306f4b..05e758b8b894 100644
--- a/include/linux/alarmtimer.h
+++ b/include/linux/alarmtimer.h
@@ -60,7 +60,11 @@ u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
 u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
 ktime_t alarm_expires_remaining(const struct alarm *alarm);
 
+#ifdef CONFIG_RTC_CLASS
 /* Provide way to access the rtc device being used by alarmtimers */
 struct rtc_device *alarmtimer_get_rtcdev(void);
+#else
+static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
+#endif
 
 #endif
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 395d4a6db1b2..36124aea8d6f 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -145,11 +145,6 @@ static void alarmtimer_rtc_interface_remove(void)
 	class_interface_unregister(&alarmtimer_rtc_interface);
 }
 #else
-struct rtc_device *alarmtimer_get_rtcdev(void)
-{
-	return NULL;
-}
-#define rtcdev (NULL)
 static inline int alarmtimer_rtc_interface_setup(void) { return 0; }
 static inline void alarmtimer_rtc_interface_remove(void) { }
 static inline void alarmtimer_rtc_timer_init(void) { }
-- 
Sent by a computer, using git, on the internet


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 4/4] alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality
  2020-01-24  5:58 [PATCH v3 0/4] Fix alarmtimer suspend failure Stephen Boyd
                   ` (2 preceding siblings ...)
  2020-01-24  5:58 ` [PATCH v3 3/4] alarmtimer: Make alarmtimer_get_rtcdev() a stub when CONFIG_RTC_CLASS=n Stephen Boyd
@ 2020-01-24  5:58 ` Stephen Boyd
  2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd
  3 siblings, 1 reply; 9+ messages in thread
From: Stephen Boyd @ 2020-01-24  5:58 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner; +Cc: linux-kernel, Stephen Boyd

This function doesn't do anything like this comment says when an RTC
device hasn't been chosen. It looks like we used to do something like
that before commit 8bc0dafb5cf3 ("alarmtimers: Rework RTC device
selection using class interface") but that's long gone now. Remove this
sentence to avoid confusing the reader.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 kernel/time/alarmtimer.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 36124aea8d6f..2ffb466af77e 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -67,8 +67,6 @@ static DEFINE_SPINLOCK(rtcdev_lock);
  * alarmtimer_get_rtcdev - Return selected rtcdevice
  *
  * This function returns the rtc device to use for wakealarms.
- * If one has not already been chosen, it checks to see if a
- * functional rtc device is available.
  */
 struct rtc_device *alarmtimer_get_rtcdev(void)
 {
-- 
Sent by a computer, using git, on the internet


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: timers/core] alarmtimer: Make alarmtimer_get_rtcdev() a stub when CONFIG_RTC_CLASS=n
  2020-01-24  5:58 ` [PATCH v3 3/4] alarmtimer: Make alarmtimer_get_rtcdev() a stub when CONFIG_RTC_CLASS=n Stephen Boyd
@ 2020-01-24 20:08   ` tip-bot2 for Stephen Boyd
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Stephen Boyd @ 2020-01-24 20:08 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Stephen Boyd, Thomas Gleixner, x86, LKML

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     fd928f3e32ba09381b287f8b732418434d932855
Gitweb:        https://git.kernel.org/tip/fd928f3e32ba09381b287f8b732418434d932855
Author:        Stephen Boyd <swboyd@chromium.org>
AuthorDate:    Thu, 23 Jan 2020 21:58:48 -08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 24 Jan 2020 21:03:53 +01:00

alarmtimer: Make alarmtimer_get_rtcdev() a stub when CONFIG_RTC_CLASS=n

The stubbed version of alarmtimer_get_rtcdev() is not exported.
so this won't work if this function is used in a module when
CONFIG_RTC_CLASS=n.

Move the stub function to the header file and make it inline so that
callers don't have to worry about linking against this symbol.

rtcdev isn't used outside of this ifdef so it's not required to be
redefined to NULL. Drop that while touching this area.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200124055849.154411-4-swboyd@chromium.org
---
 include/linux/alarmtimer.h | 4 ++++
 kernel/time/alarmtimer.c   | 5 -----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h
index 74748e3..05e758b 100644
--- a/include/linux/alarmtimer.h
+++ b/include/linux/alarmtimer.h
@@ -60,7 +60,11 @@ u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
 u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
 ktime_t alarm_expires_remaining(const struct alarm *alarm);
 
+#ifdef CONFIG_RTC_CLASS
 /* Provide way to access the rtc device being used by alarmtimers */
 struct rtc_device *alarmtimer_get_rtcdev(void);
+#else
+static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
+#endif
 
 #endif
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 685ff57..2ffb466 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -143,11 +143,6 @@ static void alarmtimer_rtc_interface_remove(void)
 	class_interface_unregister(&alarmtimer_rtc_interface);
 }
 #else
-struct rtc_device *alarmtimer_get_rtcdev(void)
-{
-	return NULL;
-}
-#define rtcdev (NULL)
 static inline int alarmtimer_rtc_interface_setup(void) { return 0; }
 static inline void alarmtimer_rtc_interface_remove(void) { }
 static inline void alarmtimer_rtc_timer_init(void) { }

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: timers/core] alarmtimer: Use wakeup source from alarmtimer platform device
  2020-01-24  5:58 ` [PATCH v3 2/4] alarmtimer: Use wakeup source from alarmtimer platform device Stephen Boyd
@ 2020-01-24 20:08   ` tip-bot2 for Stephen Boyd
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Stephen Boyd @ 2020-01-24 20:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Stephen Boyd, Thomas Gleixner, Douglas Anderson, x86, LKML

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     7c94caca877b0feeca6f5f7b07d48c508e20d58f
Gitweb:        https://git.kernel.org/tip/7c94caca877b0feeca6f5f7b07d48c508e20d58f
Author:        Stephen Boyd <swboyd@chromium.org>
AuthorDate:    Thu, 23 Jan 2020 21:58:47 -08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 24 Jan 2020 21:00:21 +01:00

alarmtimer: Use wakeup source from alarmtimer platform device

Use the wakeup source that can be associated with the 'alarmtimer'
platform device instead of registering another one by hand.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20200124055849.154411-3-swboyd@chromium.org

---
 kernel/time/alarmtimer.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index f0469cc..685ff57 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -58,8 +58,6 @@ static DEFINE_SPINLOCK(freezer_delta_lock);
 #endif
 
 #ifdef CONFIG_RTC_CLASS
-static struct wakeup_source *ws;
-
 /* rtc timer and device for setting alarm wakeups at suspend */
 static struct rtc_timer		rtctimer;
 static struct rtc_device	*rtcdev;
@@ -88,7 +86,6 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 {
 	unsigned long flags;
 	struct rtc_device *rtc = to_rtc_device(dev);
-	struct wakeup_source *__ws;
 	struct platform_device *pdev;
 	int ret = 0;
 
@@ -100,12 +97,13 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 	if (!device_may_wakeup(rtc->dev.parent))
 		return -1;
 
-	__ws = wakeup_source_register(dev, "alarmtimer");
 	pdev = platform_device_register_data(dev, "alarmtimer",
 					     PLATFORM_DEVID_AUTO, NULL, 0);
+	if (!IS_ERR(pdev))
+		device_init_wakeup(&pdev->dev, true);
 
 	spin_lock_irqsave(&rtcdev_lock, flags);
-	if (__ws && !IS_ERR(pdev) && !rtcdev) {
+	if (!IS_ERR(pdev) && !rtcdev) {
 		if (!try_module_get(rtc->owner)) {
 			ret = -1;
 			goto unlock;
@@ -114,8 +112,6 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 		rtcdev = rtc;
 		/* hold a reference so it doesn't go away */
 		get_device(dev);
-		ws = __ws;
-		__ws = NULL;
 		pdev = NULL;
 	} else {
 		ret = -1;
@@ -124,7 +120,6 @@ unlock:
 	spin_unlock_irqrestore(&rtcdev_lock, flags);
 
 	platform_device_unregister(pdev);
-	wakeup_source_unregister(__ws);
 
 	return ret;
 }
@@ -291,7 +286,7 @@ static int alarmtimer_suspend(struct device *dev)
 		return 0;
 
 	if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
-		__pm_wakeup_event(ws, 2 * MSEC_PER_SEC);
+		pm_wakeup_event(dev, 2 * MSEC_PER_SEC);
 		return -EBUSY;
 	}
 
@@ -306,7 +301,7 @@ static int alarmtimer_suspend(struct device *dev)
 	/* Set alarm, if in the past reject suspend briefly to handle */
 	ret = rtc_timer_start(rtc, &rtctimer, now, 0);
 	if (ret < 0)
-		__pm_wakeup_event(ws, MSEC_PER_SEC);
+		pm_wakeup_event(dev, MSEC_PER_SEC);
 	return ret;
 }
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: timers/core] alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality
  2020-01-24  5:58 ` [PATCH v3 4/4] alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality Stephen Boyd
@ 2020-01-24 20:08   ` tip-bot2 for Stephen Boyd
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Stephen Boyd @ 2020-01-24 20:08 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Stephen Boyd, Thomas Gleixner, x86, LKML

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     6b088cefbeaa87ba48bf838edfc1e19c9ff3976b
Gitweb:        https://git.kernel.org/tip/6b088cefbeaa87ba48bf838edfc1e19c9ff3976b
Author:        Stephen Boyd <swboyd@chromium.org>
AuthorDate:    Thu, 23 Jan 2020 21:58:49 -08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 24 Jan 2020 21:00:20 +01:00

alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality

This function doesn't do anything like this comment says when an RTC device
hasn't been chosen. It looks like we used to do something like that before
commit 8bc0dafb5cf3 ("alarmtimers: Rework RTC device selection using class
interface") but that's long gone now. Remove this sentence to avoid
confusing the reader.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200124055849.154411-5-swboyd@chromium.org

---
 kernel/time/alarmtimer.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 9dc7a09..564ff5d 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -69,8 +69,6 @@ static DEFINE_SPINLOCK(rtcdev_lock);
  * alarmtimer_get_rtcdev - Return selected rtcdevice
  *
  * This function returns the rtc device to use for wakealarms.
- * If one has not already been chosen, it checks to see if a
- * functional rtc device is available.
  */
 struct rtc_device *alarmtimer_get_rtcdev(void)
 {

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip: timers/core] alarmtimer: Make alarmtimer platform device child of RTC device
  2020-01-24  5:58 ` [PATCH v3 1/4] alarmtimer: Make alarmtimer platform device child of RTC device Stephen Boyd
@ 2020-01-24 20:08   ` tip-bot2 for Stephen Boyd
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Stephen Boyd @ 2020-01-24 20:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Douglas Anderson, Stephen Boyd, Thomas Gleixner, x86, LKML

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     c79108bd19a8490315847e0c95ac6526fcd8e770
Gitweb:        https://git.kernel.org/tip/c79108bd19a8490315847e0c95ac6526fcd8e770
Author:        Stephen Boyd <swboyd@chromium.org>
AuthorDate:    Thu, 23 Jan 2020 21:58:46 -08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 24 Jan 2020 21:00:20 +01:00

alarmtimer: Make alarmtimer platform device child of RTC device

The alarmtimer_suspend() function will fail if an RTC device is on a bus
such as SPI or i2c and that RTC device registers and probes after
alarmtimer_init() registers and probes the 'alarmtimer' platform device.

This is because system wide suspend suspends devices in the reverse order
of their probe. When alarmtimer_suspend() attempts to program the RTC for a
wakeup it will try to program an RTC device on a bus that has already been
suspended.

Move the alarmtimer device registration to happen when the RTC which is
used for wakeup is registered. Register the 'alarmtimer' platform device as
a child of the RTC device too, so that it can be guaranteed that the RTC
device won't be suspended when alarmtimer_suspend() is called.

Reported-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20200124055849.154411-2-swboyd@chromium.org

---
 kernel/time/alarmtimer.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 564ff5d..f0469cc 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -89,6 +89,7 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 	unsigned long flags;
 	struct rtc_device *rtc = to_rtc_device(dev);
 	struct wakeup_source *__ws;
+	struct platform_device *pdev;
 	int ret = 0;
 
 	if (rtcdev)
@@ -100,9 +101,11 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 		return -1;
 
 	__ws = wakeup_source_register(dev, "alarmtimer");
+	pdev = platform_device_register_data(dev, "alarmtimer",
+					     PLATFORM_DEVID_AUTO, NULL, 0);
 
 	spin_lock_irqsave(&rtcdev_lock, flags);
-	if (!rtcdev) {
+	if (__ws && !IS_ERR(pdev) && !rtcdev) {
 		if (!try_module_get(rtc->owner)) {
 			ret = -1;
 			goto unlock;
@@ -113,10 +116,14 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 		get_device(dev);
 		ws = __ws;
 		__ws = NULL;
+		pdev = NULL;
+	} else {
+		ret = -1;
 	}
 unlock:
 	spin_unlock_irqrestore(&rtcdev_lock, flags);
 
+	platform_device_unregister(pdev);
 	wakeup_source_unregister(__ws);
 
 	return ret;
@@ -903,8 +910,7 @@ static void get_boottime_timespec(struct timespec64 *tp)
  */
 static int __init alarmtimer_init(void)
 {
-	struct platform_device *pdev;
-	int error = 0;
+	int error;
 	int i;
 
 	alarmtimer_rtc_timer_init();
@@ -929,15 +935,7 @@ static int __init alarmtimer_init(void)
 	if (error)
 		goto out_if;
 
-	pdev = platform_device_register_simple("alarmtimer", -1, NULL, 0);
-	if (IS_ERR(pdev)) {
-		error = PTR_ERR(pdev);
-		goto out_drv;
-	}
 	return 0;
-
-out_drv:
-	platform_driver_unregister(&alarmtimer_driver);
 out_if:
 	alarmtimer_rtc_interface_remove();
 	return error;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-01-24 20:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24  5:58 [PATCH v3 0/4] Fix alarmtimer suspend failure Stephen Boyd
2020-01-24  5:58 ` [PATCH v3 1/4] alarmtimer: Make alarmtimer platform device child of RTC device Stephen Boyd
2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd
2020-01-24  5:58 ` [PATCH v3 2/4] alarmtimer: Use wakeup source from alarmtimer platform device Stephen Boyd
2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd
2020-01-24  5:58 ` [PATCH v3 3/4] alarmtimer: Make alarmtimer_get_rtcdev() a stub when CONFIG_RTC_CLASS=n Stephen Boyd
2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd
2020-01-24  5:58 ` [PATCH v3 4/4] alarmtimer: Update alarmtimer_get_rtcdev() docs to reflect reality Stephen Boyd
2020-01-24 20:08   ` [tip: timers/core] " tip-bot2 for Stephen Boyd

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).