Re: [rtc-linux] RTC used as a module

From
Michal Simek <monstr@monstr.eu>
Date
2017-03-03 19:55:36
Reply to
Alexandre Belloni, 2017-03-03
Hi

2017-03-03 16:09 GMT+01:00 Alexandre Belloni <
alexandre.belloni@free-electrons.com>:
On 03/03/2017 at 15:46:36 +0100, Michal Simek wrote:
quoted
This is the function which is making the difference.

It was added by John Stultz:
"timers: Introduce in-kernel alarm-timer interface"
(sha1:  ff3ead96d17f47ee70c294a5cc2cce9b61e82f0f)

Probe function has device_init_wakeup(&pdev->dev, 1);
That's why reference is taken (get_device() below)

static int alarmtimer_rtc_add_device(struct device *dev,
                              struct class_interface *class_intf)
{
      unsigned long flags;
      struct rtc_device *rtc = to_rtc_device(dev);

      if (rtcdev)
              return -EBUSY;

      pr_info("%s\n", __func__);

      if (!rtc->ops->set_alarm)
              return -1;

      pr_info("%s\n", __func__);

      if (!device_may_wakeup(rtc->dev.parent))
              return -1;

      spin_lock_irqsave(&rtcdev_lock, flags);
      if (!rtcdev) {
              rtcdev = rtc;
              /* hold a reference so it doesn't go away */
              get_device(dev);
      }
      spin_unlock_irqrestore(&rtcdev_lock, flags);
      return 0;
}

And in remove function device_init_wakeup(&pdev->dev, 0);
But because there is still a reference rtc_device_release() is not
called and ida is not freed.

Generic question which I think should be asked if in this situation
driver should be modular or not.
If driver can be modular then somewhere should be put_device().
From a quick look, I'd say the issue is coming from
8bc0dafb5cf38a19484dfb16e2c6d29e85820046 which removed the call to
rtc_class_open so you can actually unload the module.
This is from 2011 which is kind of surprising.

M


-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thread (19 messages) 19 messages, 4 authors, last reply 2017-08-21
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help