Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753841AbcDNLKf (ORCPT ); Thu, 14 Apr 2016 07:10:35 -0400 Received: from mail1.bemta14.messagelabs.com ([193.109.254.111]:9821 "EHLO mail1.bemta14.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752808AbcDNLKd (ORCPT ); Thu, 14 Apr 2016 07:10:33 -0400 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRWlGSWpSXmKPExsUSt3Opse70Kv5 wgzO7zS06ri1msri8aw6bxf7ODkaLyxM72R1YPJ5susjosXPWXXaPPRNPsnl83iQXwBLFmpmX lF+RwJpxcudnxoIXIhXvDy9iamA8ItjFyMUhJLCeUWLhp9ssXYycQE6FRM/W78wgNpuAocS8N +8ZQWwWAVWJT2uOsYPYwgLJErvO/GcDaRYRmMgo8batEaiBg4NZwFxiww19kBpeAQeJ+yv/sE DYghInZz4Bs5kFJCQOvngBVi4koCWx/FgkSFhCwF5i+vurYGEJAX2JxmOxEGFDie+zvrFA2OY STb/2sk9g5J+FZOgsJEMXMDKtYtQoTi0qSy3SNbTQSyrKTM8oyU3MzNE1NDTRy00tLk5MT81J TCrWS87P3cQIDNJ6BgbGHYxHtnseYpTkYFIS5WXM4A8X4kvKT6nMSCzOiC8qzUktPsQow8GhJ MG7uRIoJ1iUmp5akZaZA4wXmLQEB4+SCK8YSJq3uCAxtzgzHSJ1ilGXY9u062uZhFjy8vNSpc R5t4EUCYAUZZTmwY2Axe4lRlkpYV5GBgYGIZ6C1KLczBJU+VeM4hyMSsK8p0Gm8GTmlcBtegV 0BBPQEWXveEGOKElESEk1ME5Se785XfTV/fdX/j301/3GeZd9YerC7j/Mf+IfLFD77rC/ue2x i+Gb4tBWjU6GP5YSndkTHjwNErF5OH2/So9ezLSvSZuflS868Sas6FZc48mfk7k2LWF2MYtRL drwx3p22GKF270erl9/O6xSs7i8eeLuqdsDH/I/CqnZGc1UtmaHYUfjK20lluKMREMt5qLiRA CDEPOt2AIAAA== X-Env-Sender: stwiss.opensource@diasemi.com X-Msg-Ref: server-16.tower-194.messagelabs.com!1460632215!7587234!1 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked From: Steve Twiss Date: Thu, 14 Apr 2016 12:04:54 +0100 Subject: [PATCH V1] rtc: da9053: fix access ordering error during RTC interrupt at system power on To: Alexandre Belloni , LINUXKERNEL , RTC-LINUX CC: Support Opensource Message-ID: <20160414111014.BB8B73FB1D@swsrvapps-01.diasemi.com> MIME-Version: 1.0 Content-Type: text/plain X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 14/04/2016 09:26:00 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2663 Lines: 85 From: Steve Twiss This fix alters the ordering of the IRQ and device registrations in the RTC driver probe function. This change will apply to the RTC driver that supports both DA9052 and DA9053 PMICs. A problem could occur with the existing RTC driver if: A system is started from a cold boot using the PMIC RTC IRQ to initiate a power on operation. For instance, if an RTC alarm is used to start a platform from power off. The existing driver IRQ is requested before the device has been properly registered. i.e. ret = da9052_request_irq() comes before rtc->rtc = devm_rtc_device_register(); In this case, an interrupt exists before the device has been registered and the IRQ handler can be called immediately: this can happen be before the memory for rtc->rtc has been allocated. The IRQ handler da9052_rtc_irq() contains the function call: rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF); which in turn tries to access the unavailable rtc->rtc. The fix is to reorder the functions inside the RTC probe. The IRQ is requested after the RTC device resource has been registered so that da9052_request_irq() is the last thing to happen. Signed-off-by: Steve Twiss --- This patch applies against linux-next and v4.6-rc3 This wake-up IRQ fault is similar to the one previously fixed in the DA9063 and DA9062 driver code. See reference: commit 77535acedc26627f16a1a39c1471f942689fe11e Author: Steve Twiss Date: Tue Dec 8 16:28:39 2015 +0000 Regards, Steve drivers/rtc/rtc-da9052.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c index 1ba4371..a20bcf0 100644 --- a/drivers/rtc/rtc-da9052.c +++ b/drivers/rtc/rtc-da9052.c @@ -302,6 +302,13 @@ static int da9052_rtc_probe(struct platform_device *pdev) if (ret != 0) rtc_err(rtc, "Failed to disable TICKS: %d\n", ret); + device_init_wakeup(&pdev->dev, true); + rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, + &da9052_rtc_ops, THIS_MODULE); + + if (IS_ERR(rtc->rtc)) + return PTR_ERR(rtc->rtc); + ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM", da9052_rtc_irq, rtc); if (ret != 0) { @@ -309,11 +316,7 @@ static int da9052_rtc_probe(struct platform_device *pdev) return ret; } - device_init_wakeup(&pdev->dev, true); - - rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, - &da9052_rtc_ops, THIS_MODULE); - return PTR_ERR_OR_ZERO(rtc->rtc); + return 0; } static struct platform_driver da9052_rtc_driver = { -- end-of-patch for PATCH V1