Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp272153ybi; Wed, 29 May 2019 21:06:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwcpXLr+0KOeJVr4w+lLBhJzGPrd0VmcyWZoCHEAOpSjdV10hChAK5yTYyFuyStYlBCacm X-Received: by 2002:a62:1ec1:: with SMTP id e184mr1665711pfe.185.1559189211922; Wed, 29 May 2019 21:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189211; cv=none; d=google.com; s=arc-20160816; b=OX8gpVsi01t4NUHRuZZhzFue1WuqCpx5ez44cylOY+c9YQ9PR1zk17Hk0NBBGlMuV2 Mr8VrlLwY5t1WexHvqQZBsQ3Mj1yTgR3Y7S7395ottimibOtdAJotKFZKFDvF7QzsmMj oyQqksIe7LHa8+SKWXE8jCEVfzPdcdxZwAo1jCX1KjTRgRnDc4owKXKJ6EWc7Kprzv3I NdTR2q+ErQvPMwKG/om3vcCH+loYpg+N1Td8Gu85EJCLKsgZeo5FhCk1c+J+aP/HoLPr wLKFMlc1JP2MB2gw3EOLWn8tJONZ+efN+x6gpfOjj4CFPC5vVetB8RwVG88umSOM8Ye3 MJWw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0N2h38Vw7m/q31DftPjFYzjVXyq/5tq787Dhdca1fx0=; b=GAav9c/eMuSRkUMUTdUZmxstvshokoJMdXh+ZAD8IrIdcA0HfrQBr3Fxye8cSRhPJW v0cL2xLcg1iYF+20ak/3zK0HiNJooIrmlAHtSeftof0dbR3T/O5W5ETLQr+Z/frc9sHn 0uSGWa00G3HalqNz6pgOB3RS/GTzZI7xErUMHF07UxzN2uGw+2/JGLNfuQhaP5N1QjEF uq15cQhShOI+1gao5q5gAtccE39OZVDzkaDPvW+oOOfYIgAf6mVJ+CxQ6yVqP2epVnVd sXh1G4x6ZyTG60dTtdNVjM7L/FhG1c22zCL8DcYGaALWF2lGX1cu8P3GZra+WRbF1iyR uVQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ljj529Q7; 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 u1si2297097pgo.595.2019.05.29.21.06.35; Wed, 29 May 2019 21:06: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=ljj529Q7; 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 S1726804AbfE3EFa (ORCPT + 99 others); Thu, 30 May 2019 00:05:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:48242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731238AbfE3DRo (ORCPT ); Wed, 29 May 2019 23:17:44 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 106302470B; Thu, 30 May 2019 03:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186264; bh=fNIicfzKqgNknvOL8kafg05oEuWLA66QXO1DUGfYGHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljj529Q7UCyBuSOwseUv/P/i0V/5T0em2AEmcLxMW3ulnFDgSKvUgKbsFNH5WlhYc 2L1UkjsUaENQpZ3QD/AoXwmpxKK7WGCn/LGz3RerwkorECobtiu2V9bP5ZeC3t1DIP TYlVURdqqmp33wH51qLrnbUYIR4YC5Ci9klQeCHo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandre Belloni , Sasha Levin Subject: [PATCH 4.19 199/276] rtc: xgene: fix possible race condition Date: Wed, 29 May 2019 20:05:57 -0700 Message-Id: <20190530030537.555698648@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit a652e00ee1233e251a337c28e18a1da59224e5ce ] 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 Signed-off-by: Sasha Levin --- drivers/rtc/rtc-xgene.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-xgene.c b/drivers/rtc/rtc-xgene.c index 153820876a820..2f741f455c30a 100644 --- a/drivers/rtc/rtc-xgene.c +++ b/drivers/rtc/rtc-xgene.c @@ -168,6 +168,10 @@ static int xgene_rtc_probe(struct platform_device *pdev) if (IS_ERR(pdata->csr_base)) return PTR_ERR(pdata->csr_base); + pdata->rtc = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(pdata->rtc)) + return PTR_ERR(pdata->rtc); + irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "No IRQ resource\n"); @@ -198,15 +202,15 @@ static int xgene_rtc_probe(struct platform_device *pdev) return ret; } - pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, - &xgene_rtc_ops, THIS_MODULE); - if (IS_ERR(pdata->rtc)) { - clk_disable_unprepare(pdata->clk); - return PTR_ERR(pdata->rtc); - } - /* HW does not support update faster than 1 seconds */ pdata->rtc->uie_unsupported = 1; + pdata->rtc->ops = &xgene_rtc_ops; + + ret = rtc_register_device(pdata->rtc); + if (ret) { + clk_disable_unprepare(pdata->clk); + return ret; + } return 0; } -- 2.20.1