From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 Received: from mail-pa0-x22b.google.com (mail-pa0-x22b.google.com. [2607:f8b0:400e:c03::22b]) by gmr-mx.google.com with ESMTPS id rv6si2016592pac.1.2015.07.20.16.03.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jul 2015 16:03:00 -0700 (PDT) Received: by mail-pa0-x22b.google.com with SMTP id hj5so108250811pac.3 for ; Mon, 20 Jul 2015 16:03:00 -0700 (PDT) From: Dmitry Torokhov To: Alessandro Zummo , Alexandre Belloni Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [rtc-linux] [PATCH 3/4] RTC: properly manage lifetime of dev and cdev in rtc device Date: Mon, 20 Jul 2015 16:02:51 -0700 Message-Id: <1437433372-15425-3-git-send-email-dmitry.torokhov@gmail.com> In-Reply-To: <1437433372-15425-1-git-send-email-dmitry.torokhov@gmail.com> References: <1437433372-15425-1-git-send-email-dmitry.torokhov@gmail.com> Reply-To: rtc-linux@googlegroups.com Content-Type: text/plain; charset=UTF-8 List-ID: List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , 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 --- drivers/rtc/rtc-dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index 799c34b..a6d9434 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c @@ -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) -- 2.4.3.573.g4eafbef -- -- 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932339AbbGTXDJ (ORCPT ); Mon, 20 Jul 2015 19:03:09 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:35185 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932197AbbGTXDB (ORCPT ); Mon, 20 Jul 2015 19:03:01 -0400 From: Dmitry Torokhov To: Alessandro Zummo , Alexandre Belloni Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] RTC: properly manage lifetime of dev and cdev in rtc device Date: Mon, 20 Jul 2015 16:02:51 -0700 Message-Id: <1437433372-15425-3-git-send-email-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.4.3.573.g4eafbef In-Reply-To: <1437433372-15425-1-git-send-email-dmitry.torokhov@gmail.com> References: <1437433372-15425-1-git-send-email-dmitry.torokhov@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/rtc/rtc-dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index 799c34b..a6d9434 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c @@ -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) -- 2.4.3.573.g4eafbef