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(). Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx> --- 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 8d9f13d847f0..592668136bb5 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 *rtc_pdev; static DEFINE_SPINLOCK(rtcdev_lock); /** @@ -109,6 +110,7 @@ static int alarmtimer_rtc_add_device(struct device *dev) } rtcdev = rtc; + rtc_pdev = pdev; /* hold a reference so it doesn't go away */ get_device(dev); pdev = NULL; @@ -123,6 +125,23 @@ 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 (rtc_pdev) { + module_put(rtc->owner); + if (device_may_wakeup(rtc->dev.parent)) + device_init_wakeup(&rtc_pdev->dev, false); + + platform_device_unregister(rtc_pdev); + put_device(dev); + } + + rtcdev = NULL; + rtc_pdev = NULL; +} + static inline void alarmtimer_rtc_timer_init(void) { rtc_timer_init(&rtctimer, NULL, NULL); @@ -130,6 +149,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