rtc: dev: properly manage lifetime of dev and cdev in rtc device
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 20 Jul 2015 23:02:51 +0000 (16:02 -0700)
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>
Sat, 5 Sep 2015 11:19:07 +0000 (13:19 +0200)
struct rtc embeds both struct dev and struct cdev.  Unfortunately character
device structure may outlive the parent rtc structure unless we set it up
as parent of character device so that it will stay pinned until character
device is freed.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
drivers/rtc/rtc-dev.c

index 799c34bcb26f3b54cfc45100775990918727bb53..a6d9434addf6f79cc1a0b210f0ac75aaa2563637 100644 (file)
@@ -477,6 +477,7 @@ void rtc_dev_prepare(struct rtc_device *rtc)
 
        cdev_init(&rtc->char_dev, &rtc_dev_fops);
        rtc->char_dev.owner = rtc->owner;
+       rtc->char_dev.kobj.parent = &rtc->dev.kobj;
 }
 
 void rtc_dev_add_device(struct rtc_device *rtc)