Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2009044imm; Sun, 9 Sep 2018 13:41:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbLNkWtqzsSAYkLC6CYjDThjumgL6oeRX7oHcbGMcwa/LAW//Lx8n18Z/mx+Q+KnUTUTICj X-Received: by 2002:a17:902:47:: with SMTP id 65-v6mr18302875pla.293.1536525680482; 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=C2F4l8AVM+BuiX1/VqP/73Vz4ja7bQrq+z7QwYgus/vLfJ4X1WplE7Mj020FTlBPz2 NsU6E9rBjbs3DZcU7zr3x+JQCyxn9OKPBjoxvhnl0nCrG+h+zoOuvjoKhn3z8V6RQo/f tLrHZsIwYdb3WzEULlVzv8wtL5ZRBZcuXWDyORb2obFiSpLFmSB+Cn9iDrwdpDXK8h6x 6FSpZRhjrBc3rHyNOG9cZ6OPCOpVfRw4oNLQ9ezjDoSbdonj+tdG7rSAwQtQ3yvNuiDE cLgRqp8BXEivjxeewKZfsxiRdMKjpBnpHYmigEEmq5Rre1cb6oVFJPN1Jyrq+XYtqtwG kIwg== 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:message-id:date:subject:cc:to:from; bh=yYxusJKZIAhGRlBQZeOvt1bqVFi9CuWWFPOc+0fYRRQ=; b=eaB1BsYmBn2rJgqik1u6zpQxvtRmXvoTWSTae8uLrL2nnnwz4U+uwhP4bbbNgUo9aF z6USLaCqbRcK5WzDmwgMKXP8Za8x0ugnBFwkIcn7ZJWx2FpUBOBpzI9N/uRijm2bjIFa RU18dmzFxGgBTfgfmM6Zs/o2zzhqI5MmSpsnUvP0PnUc163oIe8l3WHCY3kgVV6BLfBI 369Xtar0TT2od7+jczy4FkmhaXnZiT4bHbWqXIRO0plboDw7e+dEGZ3MTdG8pwoupUXB O6Zb9/5ZZRyRsPI+HBBAUMdpNCuGk1zXfPCqoZ/Aal0hp2G6jDMQa+gM1IeuQKu2vMwL WGFw== 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 31-v6si15581405pla.129.2018.09.09.13.40.50; 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 S1726885AbeIJB3x (ORCPT + 99 others); Sun, 9 Sep 2018 21:29:53 -0400 Received: from mail.bootlin.com ([62.4.15.54]:47053 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726658AbeIJB3w (ORCPT ); Sun, 9 Sep 2018 21:29:52 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id DB2A820726; 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, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id B349F203DC; 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 Subject: [PATCH 2/3] rtc: pl030: fix possible race condition Date: Sun, 9 Sep 2018 22:38:47 +0200 Message-Id: <20180909203848.3470-2-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.19.0.rc2 In-Reply-To: <20180909203848.3470-1-alexandre.belloni@bootlin.com> References: <20180909203848.3470-1-alexandre.belloni@bootlin.com> 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. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-pl030.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c index f85a1a93e669..343bb6ed1783 100644 --- a/drivers/rtc/rtc-pl030.c +++ b/drivers/rtc/rtc-pl030.c @@ -112,6 +112,13 @@ static int pl030_probe(struct amba_device *dev, const struct amba_id *id) goto err_rtc; } + rtc->rtc = devm_rtc_allocate_device(&dev->dev); + if (IS_ERR(rtc->rtc)) { + ret = PTR_ERR(rtc->rtc); + goto err_rtc; + } + + rtc->rtc->ops = &pl030_ops; rtc->base = ioremap(dev->res.start, resource_size(&dev->res)); if (!rtc->base) { ret = -ENOMEM; @@ -128,12 +135,9 @@ static int pl030_probe(struct amba_device *dev, const struct amba_id *id) if (ret) goto err_irq; - rtc->rtc = rtc_device_register("pl030", &dev->dev, &pl030_ops, - THIS_MODULE); - if (IS_ERR(rtc->rtc)) { - ret = PTR_ERR(rtc->rtc); + ret = rtc_register_device(rtc->rtc); + if (ret) goto err_reg; - } return 0; @@ -154,7 +158,6 @@ static int pl030_remove(struct amba_device *dev) writel(0, rtc->base + RTC_CR); free_irq(dev->irq[0], rtc); - rtc_device_unregister(rtc->rtc); iounmap(rtc->base); amba_release_regions(dev); -- 2.19.0.rc2