Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp853420pxk; Thu, 17 Sep 2020 19:08:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4CqrpeGgfgDzn+C7CiDDswnmP40AmpEby7b6PeAqnhncgBA1AKxqGhRcDsbWLYOY2Tj88 X-Received: by 2002:aa7:d417:: with SMTP id z23mr34828484edq.62.1600394905089; Thu, 17 Sep 2020 19:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600394905; cv=none; d=google.com; s=arc-20160816; b=lWlbg+dea9TOGGvZLmt8f7Gh2P7r/KsmUeXOUEb67pSd9rEogIIe6ziXHBoCyxyaZ2 cA7l+iqJMX7H1U9l5S1eH3iPWfFEkH7X/tB+c6Up4QLT/HC6sH/+4RoQpTbX85Z3bFbH 7zx+J1FQvinyAK1VcjiOiPQMn0PsOfA7lZiSLZr5wchWfRb6ivjGBAP87qByMdm2H1NL doQKN5vlsHl4JKC7AYIr2LyM2pFcqqe+QwPSZq7nAgRKS+8ckpJ7pZYyMnELZX+VLgJn nwNZ6pgWLIuTo9ciYy4HiTAQMceXwUuMo6l9YmroYKUiuj7nFQPhk9AURF0C+fBIcZIs kKYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MBEOL6SyISbUqv3WBLfCaDRpZ6UwgzYTrLYUbhLeJdc=; b=oSChMZaB7PZsjYfgiqiJRDsj1DeQSW1Di+JO9pUSdP6WdQmSs3aAURqbX72IsQaNvw 65shF3Smo2o+VaMY5dPJMwkY3r0Fqi8jHIl9pyoSJCzu3N+I+q3i7TlwiMBoULud+r33 Yg3cAFthTLg2HcR0cSJGJ0hDAs/s3kNAAIGvcD72xYdlhwfX7D8UMvqNDrLqLBSBo70J anAtWudRIhHQpRlUM0ylhAS3jj63hmabR2mQQJmzUp7+U8DPiSI+UYvrvlRbl6odJcdB S/2RQIm/mnnPWevfdv8Ih/0rH1VW/ygAzRKjRmrQT+cBh0sMDpIxEmb02hl2I+YXk0jp ek6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U2QfzU6X; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p25si1041748edw.585.2020.09.17.19.08.01; Thu, 17 Sep 2020 19:08:25 -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=U2QfzU6X; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727393AbgIRCEv (ORCPT + 99 others); Thu, 17 Sep 2020 22:04:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:52484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727379AbgIRCEs (ORCPT ); Thu, 17 Sep 2020 22:04:48 -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 B09832344C; Fri, 18 Sep 2020 02:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394687; bh=yvSfY/wFuXDNcZOalTPhO9jKbqjuz1HOllkdtnBtnqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U2QfzU6XfHcMYi2fDi3gQ3dleSbbS+p9Clu+2l/TqHLIshOVds7TD6uJ2gEwh7TqY 7uKdIF0pC6SQm7K+s19VmO4L3gkHybh7GNt8ltE1XAjoIu3kANwsOjVCDCD/4cLm9E MjALF7iMat7Yz93ZPGryp5dlJiyNy/wAiK7Ixl1U= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alexandre Belloni , Sasha Levin , rtc-linux@googlegroups.com Subject: [PATCH AUTOSEL 5.4 176/330] rtc: ds1374: fix possible race condition Date: Thu, 17 Sep 2020 21:58:36 -0400 Message-Id: <20200918020110.2063155-176-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Belloni [ Upstream commit c11af8131a4e7ba1960faed731ee7e84c2c13c94 ] 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. Link: https://lore.kernel.org/r/20200306073404.56921-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-ds1374.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c index 367497914c100..28eb96cbaf98b 100644 --- a/drivers/rtc/rtc-ds1374.c +++ b/drivers/rtc/rtc-ds1374.c @@ -620,6 +620,10 @@ static int ds1374_probe(struct i2c_client *client, if (!ds1374) return -ENOMEM; + ds1374->rtc = devm_rtc_allocate_device(&client->dev); + if (IS_ERR(ds1374->rtc)) + return PTR_ERR(ds1374->rtc); + ds1374->client = client; i2c_set_clientdata(client, ds1374); @@ -641,12 +645,11 @@ static int ds1374_probe(struct i2c_client *client, device_set_wakeup_capable(&client->dev, 1); } - ds1374->rtc = devm_rtc_device_register(&client->dev, client->name, - &ds1374_rtc_ops, THIS_MODULE); - if (IS_ERR(ds1374->rtc)) { - dev_err(&client->dev, "unable to register the class device\n"); - return PTR_ERR(ds1374->rtc); - } + ds1374->rtc->ops = &ds1374_rtc_ops; + + ret = rtc_register_device(ds1374->rtc); + if (ret) + return ret; #ifdef CONFIG_RTC_DRV_DS1374_WDT save_client = client; -- 2.25.1