Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4681930yba; Tue, 30 Apr 2019 02:35:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhsxNLjrFiTHR9VLvFJYodZtDpLuJAKK6fI1lxJqGzs2ILzyUDzrHrKUElxTNeHoJONUtj X-Received: by 2002:a63:c64a:: with SMTP id x10mr15652595pgg.195.1556616923470; Tue, 30 Apr 2019 02:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556616923; cv=none; d=google.com; s=arc-20160816; b=QGThMkyTPZla8Yc8vK5NijxBFxmqN7PD3zElpvc8GpMXJifW1I+PLYP84CStHtHJea hnLozNOQtY6FI2TuJVcn6g3gfsQOecFTh+luOBYjXgOsTuLq6h074YOQhTS7rUH/FAVj HL9O55jMxru9WyaoMuou5MsfhR15NNGK+i5fvMu9AWIMa4hmldqUsLAuINa8suupquhf ReWmVUpixB1Wpm70Oveksww2vJSpycQ/pZW4cjCu8sj9A+KnMFoe7POxVyBmmnaEqxLy nStj8qaOAY6x4JeNqiIRys8zJtfnm5YDWU1+bGw2q7AoaexYahUIUUYTFMiRxTlsW6aE cEkQ== 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=2nAgVeAibf7CHiSZvctaLEPMxHxxicZndz0iLxffuMo=; b=dZk2MIlQMVHbe7G8ZA/sAtyWq7uvQcUIG6qcb9JQIC90b1LGKfbRETuVRqq73H5/G8 w0K1vVS+SeJDJ2WQRRQJKk9g8whsK+vqPy2E8C+xyUSzOvvC90zz61cE0tU+IjuRnlK0 j4YRlRxhqczgxqg9RYR1c7OMb/MK/z7A+w021NaTSNQWFZp88zHofdMne7ZAiwY8DWDC HsIqPBGAEGIdkd7i0ADlv6TPJ2N7u0tnAibE7afDALOl84mNZopx2QjU3/KZ5rZnlRp0 TSVoFRZ9cPkv23oDOjJgYd6oDuawpHq8jBargjRMufAw1JupzaJlmiH3iPeXTet6LdgD +dag== 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 l20si8882843pfj.71.2019.04.30.02.35.08; Tue, 30 Apr 2019 02:35:23 -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 S1726831AbfD3JcR (ORCPT + 99 others); Tue, 30 Apr 2019 05:32:17 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:48319 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726165AbfD3JcR (ORCPT ); Tue, 30 Apr 2019 05:32:17 -0400 X-Originating-IP: 109.213.14.175 Received: from localhost (alyon-652-1-31-175.w109-213.abo.wanadoo.fr [109.213.14.175]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id B78C31C001B; Tue, 30 Apr 2019 09:32:14 +0000 (UTC) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: Baruch Siach , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 1/4] rtc: digicolor: fix possible race condition Date: Tue, 30 Apr 2019 11:32:09 +0200 Message-Id: <20190430093212.28425-1-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.20.1 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 struct before requesting the IRQ. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-digicolor.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c index b253bf1b3531..5bb14c56bc9a 100644 --- a/drivers/rtc/rtc-digicolor.c +++ b/drivers/rtc/rtc-digicolor.c @@ -192,6 +192,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev) if (IS_ERR(rtc->regs)) return PTR_ERR(rtc->regs); + rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(rtc->rtc_dev)) + return PTR_ERR(rtc->rtc_dev); + irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; @@ -200,12 +204,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev) return ret; platform_set_drvdata(pdev, rtc); - rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, - &dc_rtc_ops, THIS_MODULE); - if (IS_ERR(rtc->rtc_dev)) - return PTR_ERR(rtc->rtc_dev); - return 0; + rtc->rtc_dev->ops = &dc_rtc_ops; + + return rtc_register_device(rtc->rtc_dev); } static const struct of_device_id dc_dt_ids[] = { -- 2.20.1