Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2009043imm; Sun, 9 Sep 2018 13:41:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZFLsRJfyIobxbsvLaZbbsKu9UpBQGbcXYKria8JGbLWeVJWy/Nqu2dlt7usNv7yVSFFDZq X-Received: by 2002:a63:9a42:: with SMTP id e2-v6mr19732913pgo.263.1536525680477; Sun, 09 Sep 2018 13:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536525680; cv=none; d=google.com; s=arc-20160816; b=b9WBgBeaMVQ4Nwy932AucOUyxzfbjXqFkxfDsGL+gUVgN5m94wIrobdvy0iafuNQCw OOi+SJ05YvrZ+9+5tK7LWkSELEN48opq3LxAwyTLhtZkG3ugsLVrDHlsbDZE6NLSnmbi KPSMI34svSkdHZpTCcYLfGjk1OzjfYPa4ecslMuS8s538/JuuGo4KOP/Eu1L+M4iQ5m3 TXYVr4CfLfWhcQmah7JkXmdfAvVJ0fb12n5jE5UhHVIy5OpC1MToNCr3z4OJKsnuttg9 qJhL8KiEv2foc+Xaz56Fqe1pSCIL7P9eviXBDiG2u4mXAOZ4+jv2svAcC0EXCLKnHJb9 fHxw== 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 :message-id:date:subject:cc:to:from; bh=U/c1SOaxnmhTh6TjzMxGL1VxZ9xkLf6R3qIq0z4dAhY=; b=WPX3g01pe3vKpsNEW30MC5H0DaJW2Fpm1UBql+zXFAtMZmuoyaEfLsoXvtp/7B4G0B bmExegmK4rtmz33avP7Y7RcKX5muNBUs1XF/mD37Gs4HJWG9XweSUrMnD+Kcd1IETeI6 /KmluoTMCtcCI9uOeICFD2Wb6zY+Tz9DGJ7taY/NEZKVpdDYaMFtFPoIQxKGEXSL9LsX qeBN944y8MWkxSxSKVAk7aUxXHNIRqTydSFPtVpQsBNP4fpSpvaUFOF/L/dkTDexQZzC wA83nz6bGisyZrEx+tKKG8X3Orbx5HOQjJzhSynD9+BxTuqffQXdxRf7jKuLRQ6WSTdl sYFQ== 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 d130-v6si15230935pfg.257.2018.09.09.13.41.00; Sun, 09 Sep 2018 13:41:20 -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 S1726788AbeIJB3w (ORCPT + 99 others); Sun, 9 Sep 2018 21:29:52 -0400 Received: from mail.bootlin.com ([62.4.15.54]:47051 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726632AbeIJB3v (ORCPT ); Sun, 9 Sep 2018 21:29:51 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 990CB2071D; Sun, 9 Sep 2018 22:38:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id 6C27D203DC; Sun, 9 Sep 2018 22:38:57 +0200 (CEST) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Alexandre Belloni , Eddie Huang , Sean Wang Subject: [PATCH 1/3] rtc: mt6397: fix possible race condition Date: Sun, 9 Sep 2018 22:38:46 +0200 Message-Id: <20180909203848.3470-1-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.19.0.rc2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.19.0.rc2