Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1274557rdb; Wed, 20 Sep 2023 05:00:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTN102Vpe7k5igXROL5RFjIKiMBHfqHYbOz7gRkxtObhNxcGHIH41bdN7E5QT4dEOCDuBQ X-Received: by 2002:a9d:65c2:0:b0:6bb:1c21:c52e with SMTP id z2-20020a9d65c2000000b006bb1c21c52emr2176367oth.15.1695211228039; Wed, 20 Sep 2023 05:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695211228; cv=none; d=google.com; s=arc-20160816; b=gML5+y0mvdIk4ZKx/7ZaN0czYVB6sjSPFBVVwKUMiVlQfdCvr0CCoTKmcsPxjUwGq5 +nmn2bDJtf2KHA9OY72ofl5EEO/XZDK/+llt8S2bdoPQxN0ZGpfHcQc49+CGHzNO+165 +mDk9rsD5b7YH/Z+xj6fvJWBK+3HXe6ctfPblCtufsuFO7s3r0f613erdsWYxJkgfXqw adbftQ6WWEmMpZtdwjjImLg5qpnJprFF3KnAq5Ji5+FRcMx6lGgD4nBJnhJZ/c3ujj3W SoWHS/OmoWODnON0hROGzXL1FdQLGd3w1RCVUPMv0ncWr7OmxvPSBVG8B3cXLyAdtr3E CIPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LlWgTvcAEAEwZVAyBoShnP0taLAAG7WsZ650UmqEUOo=; fh=WMUUeMYmv79Rn6bPL1/AfxUtlZSy2VxFGa1kqVVs5bw=; b=oUU8DQtVg+kQK8i5zu81rKteejHsJpdqelCFzJ2HPs8yC4g+IsvLbRYUAF8dMyT0i0 krii0T6+XO/fZSymhDH2w25KlUvRWfHmI4HRwTD4EowA6+Rqp/bc4k0XxySsQp71VTBh 5GQa3zlKeTgKHYNBzK5qxkrSdRNJ2VzddHNWADU1Bo7GPk8iYAWn2dTXy+YJBxKsMQm7 xFaKmmSCmw2d3+6kKCB/LJUwJYoMbqYCl1l5qqQvgKx96v+hpX9lPlNnC3cUcs95zPnb +RuZmn7Ej9wGWgaDb/sBjJbaiiV0InhtHc3a/gsqgkFfzuGwReFmBQjiTybhTbhXhH5g 4m8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id m16-20020a63fd50000000b0056546b5fef4si3721547pgj.232.2023.09.20.05.00.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:00:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C14ED802373B; Wed, 20 Sep 2023 05:00:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234977AbjITMAI (ORCPT + 99 others); Wed, 20 Sep 2023 08:00:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235036AbjITL7s (ORCPT ); Wed, 20 Sep 2023 07:59:48 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 303BDA3; Wed, 20 Sep 2023 04:59:42 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,161,1688396400"; d="scan'208";a="176655460" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 20 Sep 2023 20:59:41 +0900 Received: from localhost.localdomain (unknown [10.226.93.39]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 19F804328CA5; Wed, 20 Sep 2023 20:59:37 +0900 (JST) From: Biju Das To: Thomas Gleixner , Alessandro Zummo , Alexandre Belloni Cc: Biju Das , John Stultz , Stephen Boyd , Geert Uytterhoeven , Biju Das , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH] alarmtimer: Fix rebind failure Date: Wed, 20 Sep 2023 12:59:35 +0100 Message-Id: <20230920115935.144391-1-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 20 Sep 2023 05:00:13 -0700 (PDT) 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 --- 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