Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp643849ybz; Wed, 22 Apr 2020 05:22:28 -0700 (PDT) X-Google-Smtp-Source: APiQypLXzRVYSJrh9X+MmKmaxLUF03GNJBi1aE4/BRwlWYGdo527vu5t/D6mRr9eN1PJ5eVByIZg X-Received: by 2002:a17:906:7c11:: with SMTP id t17mr26552026ejo.73.1587558148119; Wed, 22 Apr 2020 05:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587558148; cv=none; d=google.com; s=arc-20160816; b=WQ6OF1uzvFBN3vhmu2jNJqxQPA0650OiRvwpAaPQVGyh/G43uV+U+qkC8K/4s2G2wM OO9fBiyg4FpZ8GNmVp9pqeo0FzJlpgnEb8WvYMg+jZTFxSvQ76WSeYvZrpGLWipC7m/u 8Hv3gdErje3S3KDFPFaIIUNoqVoxsZgI6275OOAd8XHmjB9trJ54Uc0oOSv7sq8AdpRz 6LnJITnyyyzyJIWRELkJ71f6jdXHEHf5F9cgsUx8xn6K5W2LDqCC4JqD3kAlUQwulM7F rkLeqoxt/wqfKDYKw9SIw/nuvfvG1VDh68x1vj5I6WRRd1WssMPj8/c4yxjGBxlH/YEm mJNA== 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=v2CImyQmd3kWKd9+RyXWbm4rtsaGxOBMNkvNr0txIoI=; b=mMJ3jQe+sCGkOkkYaUBTPZ9HfYYkohwEuMARAwdPQgAArifL20L1jXWjvDK38toCF3 XQz7GrZX38aQB+9jQvHUjsXTc1l1pleki6+fjtagOFRXDERfZLBGKBl5fAvZPSfV2NNg PFKiVCh/bjD20xhhr+DpzOVrIHgCFgSrH/68qKlvXFKPLyNS1r0eoF98Vi8Y9fmE0CNY RfXU8Ae23HBQy2f51IxFzyBuvq8o4Q8A6l3jMlUtOv9BzIuGoNRoTL/QZLtY3HbnvU7S OzAPNHfwR4mSH2AP09VmiP64cE6S51U5hqFM1cOnBhEmvRT901+8XlcC1izndC3x266m mO0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cpbIX5Te; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gj20si3402497ejb.48.2020.04.22.05.22.05; Wed, 22 Apr 2020 05:22:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cpbIX5Te; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731121AbgDVKcZ (ORCPT + 99 others); Wed, 22 Apr 2020 06:32:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:33824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730526AbgDVKZR (ORCPT ); Wed, 22 Apr 2020 06:25:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 D64C42075A; Wed, 22 Apr 2020 10:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587551116; bh=0rcL6w+U3QxTPUxJYsUdrnHmbxHPVlcjvRNL/c8lbPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cpbIX5TeeQpXd1Pyr/G5PCWjOCJ1JtSQ0/tGqrpwQ7lB34MiguAqg0K3p+l26S4Iv 82MdMf88zoMihpEMK/N8ual1H5bfWZd9fUnyP5YSY3p3GFg5VD1rdgerp5qcDUZYOX C6yQxREfRqxJc3DlH9BwHxfH1ZlEOzM34reTXgb0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandre Belloni , Sasha Levin Subject: [PATCH 5.6 070/166] rtc: 88pm860x: fix possible race condition Date: Wed, 22 Apr 2020 11:56:37 +0200 Message-Id: <20200422095056.412533753@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095047.669225321@linuxfoundation.org> References: <20200422095047.669225321@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 From: Alexandre Belloni [ Upstream commit 9cf4789e6e4673d0b2c96fa6bb0c35e81b43111a ] The RTC IRQ is requested before the struct rtc_device is allocated, this may lead to a NULL pointer dereference in the 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. Also remove the unnecessary error message as the core already prints the info. Link: https://lore.kernel.org/r/20200311223956.51352-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-88pm860x.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c index 4743b16a8d849..1526402e126b2 100644 --- a/drivers/rtc/rtc-88pm860x.c +++ b/drivers/rtc/rtc-88pm860x.c @@ -336,6 +336,10 @@ static int pm860x_rtc_probe(struct platform_device *pdev) info->dev = &pdev->dev; dev_set_drvdata(&pdev->dev, info); + info->rtc_dev = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(info->rtc_dev)) + return PTR_ERR(info->rtc_dev); + ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, rtc_update_handler, IRQF_ONESHOT, "rtc", info); @@ -377,13 +381,11 @@ static int pm860x_rtc_probe(struct platform_device *pdev) } } - info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm860x-rtc", - &pm860x_rtc_ops, THIS_MODULE); - ret = PTR_ERR(info->rtc_dev); - if (IS_ERR(info->rtc_dev)) { - dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); + info->rtc_dev->ops = &pm860x_rtc_ops; + + ret = rtc_register_device(info->rtc_dev); + if (ret) return ret; - } /* * enable internal XO instead of internal 3.25MHz clock since it can -- 2.20.1