linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] alarmtimer: Fix rebind failure
@ 2023-09-22  8:12 Biju Das
  2023-10-09  7:00 ` Biju Das
  2023-10-09 15:10 ` Thomas Gleixner
  0 siblings, 2 replies; 12+ messages in thread
From: Biju Das @ 2023-09-22  8:12 UTC (permalink / raw)
  To: Thomas Gleixner, Alessandro Zummo, Alexandre Belloni
  Cc: Biju Das, John Stultz, Stephen Boyd, Douglas Anderson,
	Geert Uytterhoeven, Biju Das, linux-rtc, linux-kernel,
	linux-renesas-soc

The resources allocated in alarmtimer_rtc_add_device() are not freed
leading to re-bind failure for the endpoint driver. Fix this issue
by adding alarmtimer_rtc_remove_device().

Fixes: c79108bd19a8 ("alarmtimer: Make alarmtimer platform device child of RTC device")
Fixes: 7c94caca877b ("alarmtimer: Use wakeup source from alarmtimer platform device")
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2:
 * Add fixes tag.
 * Replaced the variable rtc_pdev->alarmtimer_pdev
 * Added the check rtcdev == rtc before unregistering the real alarmtimer.
Note:
 This issue is found while adding irq support for built in RTC
 found on Renesas PMIC RAA215300 device. This issue should present
 on all RTC drivers which calls device_init_wakeup() in probe().
---
 kernel/time/alarmtimer.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 8d9f13d847f0..04d67de8b1fe 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -61,6 +61,7 @@ static DEFINE_SPINLOCK(freezer_delta_lock);
 /* rtc timer and device for setting alarm wakeups at suspend */
 static struct rtc_timer		rtctimer;
 static struct rtc_device	*rtcdev;
+static struct platform_device	*alarmtimer_pdev;
 static DEFINE_SPINLOCK(rtcdev_lock);
 
 /**
@@ -109,6 +110,7 @@ static int alarmtimer_rtc_add_device(struct device *dev)
 		}
 
 		rtcdev = rtc;
+		alarmtimer_pdev = pdev;
 		/* hold a reference so it doesn't go away */
 		get_device(dev);
 		pdev = NULL;
@@ -123,6 +125,22 @@ static int alarmtimer_rtc_add_device(struct device *dev)
 	return ret;
 }
 
+static void alarmtimer_rtc_remove_device(struct device *dev)
+{
+	struct rtc_device *rtc = to_rtc_device(dev);
+
+	if (rtcdev == rtc) {
+		module_put(rtc->owner);
+		if (device_may_wakeup(rtc->dev.parent))
+			device_init_wakeup(&alarmtimer_pdev->dev, false);
+
+		platform_device_unregister(alarmtimer_pdev);
+		put_device(dev);
+		alarmtimer_pdev = NULL;
+		rtcdev = NULL;
+	}
+}
+
 static inline void alarmtimer_rtc_timer_init(void)
 {
 	rtc_timer_init(&rtctimer, NULL, NULL);
@@ -130,6 +148,7 @@ static inline void alarmtimer_rtc_timer_init(void)
 
 static struct class_interface alarmtimer_rtc_interface = {
 	.add_dev = &alarmtimer_rtc_add_device,
+	.remove_dev = &alarmtimer_rtc_remove_device,
 };
 
 static int alarmtimer_rtc_interface_setup(void)
-- 
2.25.1


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

end of thread, other threads:[~2023-10-11  9:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-22  8:12 [PATCH v2] alarmtimer: Fix rebind failure Biju Das
2023-10-09  7:00 ` Biju Das
2023-10-09 15:10 ` Thomas Gleixner
2023-10-09 15:30   ` Biju Das
2023-10-09 15:46     ` Thomas Gleixner
2023-10-09 17:02       ` Biju Das
2023-10-09 22:00         ` Thomas Gleixner
2023-10-10  6:18           ` Biju Das
2023-10-10 15:16             ` Thomas Gleixner
2023-10-10 15:45               ` Geert Uytterhoeven
2023-10-11  6:58                 ` Biju Das
2023-10-11  9:12                   ` Thomas Gleixner

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