Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3935614imm; Tue, 11 Sep 2018 04:33:03 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb9zR4qmHumLcEm6XzRWCrkWDRdVABYMLM6GfbxdatnhfIw+yKgdPCjtlf5AyxXOGGrua9H X-Received: by 2002:a62:b20c:: with SMTP id x12-v6mr28763096pfe.201.1536665583914; Tue, 11 Sep 2018 04:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536665583; cv=none; d=google.com; s=arc-20160816; b=t2AbxMIvji90rPOlDBFcwRsfRGGdzsXuGsuW5poXWeWRgI4i7fQluJusVCjj58Xab0 mZ68ga0PCvNhf8PkiPDBmbcKhM+0oi+YxA/+jqIb0PFDhGRaYejlY9IUZ3SXQHNAKl1B 8tkYMmP1WEjEDTeDwfXL2bhFP2z551/zsXgxvs3RKRUi7Y2wNlceusEy/R1ODZYbhto3 4MwYaoTuMgMRWWhEpuYb7gZYDFlGsNZ2uXkKCZNbMxPjDdAReRnKX29cDzLPRtmNQqoX wPqxR+N0OCeqpdLGd+2H1NdbyJBYvcwC64s7Rd8Q9ohKVky11bXXsHhKrzBH82CmItI/ wN4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=Ujuj0OqGjleVXCvFP5ywUmg15Pt1eEAbFCgO+CNPiXg=; b=oDs4w2tcXyJOdTPxKVp5nimwvs1N5kCiOn1WH/XaRdx5jaxrf8XPn2nz937Rs6Ax8l JZzOhh6Kza+In69DJleNE0xfhnLeU1ekvDg6FNbUk9l7zFRHrBAss2AWoFpziDmDowFG +d+Hq/fH83+59D2RRY04gkqQ7acliNvEYDh6V9jIbdwDe8VPlrTVZdB6djZBiYJ/NIEP Xq+m1/ZLF+TKihR2FsKPtPmN1EZzocsU84V6JWcrX3pbDkZcO+YO4nKDwKuEce+KswuX dXiK/ChyrT22bRMul1yx66d0+5SHpN+xQ3d1MeXyCVkpLFxZlYsVT4tnI7iAtjx0L6Kz zzwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q126-v6si20805449pfb.277.2018.09.11.04.32.48; Tue, 11 Sep 2018 04:33:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726852AbeIKQbf (ORCPT + 99 others); Tue, 11 Sep 2018 12:31:35 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:26043 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726563AbeIKQbe (ORCPT ); Tue, 11 Sep 2018 12:31:34 -0400 X-UUID: 4c2ea15926ee45c89260f0c39ff4f565-20180911 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1548744902; Tue, 11 Sep 2018 19:32:32 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 11 Sep 2018 19:32:26 +0800 Received: from [172.21.77.4] (172.21.77.4) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 11 Sep 2018 19:32:26 +0800 Message-ID: <1536665546.25102.1.camel@mtksdaap41> Subject: Re: [PATCH 1/3] rtc: mt6397: fix possible race condition From: Eddie Huang To: Alexandre Belloni CC: , , , , Sean Wang Date: Tue, 11 Sep 2018 19:32:26 +0800 In-Reply-To: <20180909203848.3470-1-alexandre.belloni@bootlin.com> References: <20180909203848.3470-1-alexandre.belloni@bootlin.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2018-09-09 at 22:38 +0200, Alexandre Belloni wrote: > The IRQ is requested before the struct rtc is allocated and registered, but > this struct is used in the IRQ handler. This may lead to a NULL pointer > dereference. > > Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc > before requesting the IRQ. > > Cc: Eddie Huang > Cc: Sean Wang > Signed-off-by: Alexandre Belloni > --- > drivers/rtc/rtc-mt6397.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c > index 385f8303bb41..e9a25ec4d434 100644 > --- a/drivers/rtc/rtc-mt6397.c > +++ b/drivers/rtc/rtc-mt6397.c > @@ -332,6 +332,10 @@ static int mtk_rtc_probe(struct platform_device *pdev) > > platform_set_drvdata(pdev, rtc); > > + rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev); > + if (IS_ERR(rtc->rtc_dev)) > + return PTR_ERR(rtc->rtc_dev); > + > ret = request_threaded_irq(rtc->irq, NULL, > mtk_rtc_irq_handler_thread, > IRQF_ONESHOT | IRQF_TRIGGER_HIGH, > @@ -344,11 +348,11 @@ static int mtk_rtc_probe(struct platform_device *pdev) > > device_init_wakeup(&pdev->dev, 1); > > - rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev, > - &mtk_rtc_ops, THIS_MODULE); > - if (IS_ERR(rtc->rtc_dev)) { > + rtc->rtc_dev->ops = &mtk_rtc_ops; > + > + ret = rtc_register_device(rtc->rtc_dev); > + if (ret) { > dev_err(&pdev->dev, "register rtc device failed\n"); > - ret = PTR_ERR(rtc->rtc_dev); > goto out_free_irq; > } > > @@ -365,7 +369,6 @@ static int mtk_rtc_remove(struct platform_device *pdev) > { > struct mt6397_rtc *rtc = platform_get_drvdata(pdev); > > - rtc_device_unregister(rtc->rtc_dev); > free_irq(rtc->irq, rtc->rtc_dev); > irq_dispose_mapping(rtc->irq); > Thanks Acked-by: Eddie Huang