Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp6024107ybn; Sun, 29 Sep 2019 10:40:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxy8IaZ+zPO095cSDj+IokQhX/IEoOpG1JPvKqF2nWft1QbFuY4Bx4mBXT87t3OhJgKlXhA X-Received: by 2002:aa7:c34b:: with SMTP id j11mr15630531edr.245.1569778851524; Sun, 29 Sep 2019 10:40:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569778851; cv=none; d=google.com; s=arc-20160816; b=bVT/No0PPdrjGaSt3jHkVD8a7bK+nT9ZeZ8W6gQYZYVVbnhKOg19NcffwVRNxwPdud iqcZvKS/EgQrCjXIJfuNRibeuevVGEXf0gcSxE3IQ9VYpVQhqI0r/SU/u/n7yxBDVEna 8dAGewqGk1hH18CoqZ+FexNvJ6NclLFlcq27SpvP2znYtNsFk58hlNfXCpuXwHvIAGpj avTcYAy5QWNDDtB/OKUrPsjdixsIO/ntOnbNDkogePOjcG9WvPcvaRCbAQjYc5Biy0tk cMpbLAEX3n5/cxku+zQf1SR1BDo3qwmoir890u2RXKKHtFM6pvLnXzf0xsuqylQhrBNd AzmA== 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 :dkim-signature; bh=tFf7rqv3iZhYHOkEm98xKhuyEzeDEWeJJ6NPsG8Mmlo=; b=dfl6qwAfhv7ftnykZhwiNcB9GQQrM1Ytig2T1HvOSSjar5mTYLXzVcXKcdAjXhAtRn u7ywyc1ReKLNKD+brnAEXKNOyFz9gfv22ncnNcV/zuityUAx9TivpLSQXmlmg63Cvn2V rzxhp5GuUfA2AKlzERO0A20fkSRF1K0laiQFoUpuG/Um39ynH0e1BLJsWemqX26sIDvp Nj3nktj6forKXft5OkfyENk7/l+cpl+/N3+NgNn5v1+ZrMLfOIAoUws68ItbGva33I+1 GXff5UVpyOkoH+meoYPV3IeXsxwydAGhMZM46Jqc9Xc5wbiOBR7LciHfZ1FI58Rcz7Li okWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGENUDyN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a54si5496183edc.333.2019.09.29.10.40.27; Sun, 29 Sep 2019 10:40:51 -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; dkim=pass header.i=@kernel.org header.s=default header.b=GGENUDyN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730076AbfI2RkZ (ORCPT + 99 others); Sun, 29 Sep 2019 13:40:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:46978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729567AbfI2Rex (ORCPT ); Sun, 29 Sep 2019 13:34:53 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0092821928; Sun, 29 Sep 2019 17:34:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569778492; bh=l7NP07G1Ea8ObzNjqXfvhMjFFJVuFFmr/gpg2A2d3/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GGENUDyN67PgqZdWVnEfPUTCDNAZ6qkjMKY5BzufB64GNgSHNIqIN3AagC7wv6Dbn K8nW3/ivqA0fOkLjISRD6HgxSxIOcEK/P1ZF6rMJUas6hIFIYHvkNSgPuDah/A3ZYl YQKENQ0Ca8nsJ69bMvWclqLs1jfe53oghlhx3eAY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anson Huang , Dong Aisheng , Alexandre Belloni , Sasha Levin , linux-rtc@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 14/33] rtc: snvs: fix possible race condition Date: Sun, 29 Sep 2019 13:34:02 -0400 Message-Id: <20190929173424.9361-14-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190929173424.9361-1-sashal@kernel.org> References: <20190929173424.9361-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anson Huang [ Upstream commit 6fd4fe9b496d9ba3382992ff4fde3871d1b6f63d ] The RTC IRQ is requested before the struct rtc_device is allocated, this may lead to a NULL pointer dereference in IRQ handler. To fix this issue, allocating the rtc_device struct before requesting the RTC IRQ using devm_rtc_allocate_device, and use rtc_register_device to register the RTC device. Signed-off-by: Anson Huang Reviewed-by: Dong Aisheng Link: https://lore.kernel.org/r/20190716071858.36750-1-Anson.Huang@nxp.com Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-snvs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c index b2483a749ac45..3cf011e120530 100644 --- a/drivers/rtc/rtc-snvs.c +++ b/drivers/rtc/rtc-snvs.c @@ -273,6 +273,10 @@ static int snvs_rtc_probe(struct platform_device *pdev) if (!data) return -ENOMEM; + data->rtc = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(data->rtc)) + return PTR_ERR(data->rtc); + data->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap"); if (IS_ERR(data->regmap)) { @@ -335,10 +339,9 @@ static int snvs_rtc_probe(struct platform_device *pdev) goto error_rtc_device_register; } - data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, - &snvs_rtc_ops, THIS_MODULE); - if (IS_ERR(data->rtc)) { - ret = PTR_ERR(data->rtc); + data->rtc->ops = &snvs_rtc_ops; + ret = rtc_register_device(data->rtc); + if (ret) { dev_err(&pdev->dev, "failed to register rtc: %d\n", ret); goto error_rtc_device_register; } -- 2.20.1