Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp168754imd; Wed, 31 Oct 2018 16:42:20 -0700 (PDT) X-Google-Smtp-Source: AJdET5da+YA6c0GoimqQ4D3r59aGOOMUn7xTwrfCHieUjpa4BRtXDR6KJllpazDYqIBgcOvn46El X-Received: by 2002:a63:c10f:: with SMTP id w15mr1276708pgf.199.1541029340317; Wed, 31 Oct 2018 16:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029340; cv=none; d=google.com; s=arc-20160816; b=n3L86a0XyXtR1ul2N8wRYY9SlgqhIeIN1ZamPpx7372s40IBEUYqbqvSNpXBWN8azR ZxL2LVYTK1SLwSXl7PykNeqJ0C0jOy8WXu0z5uvW69RFztx9TAdhK+DRQQo21RPqGZcu pL7YPMqxaJFLMqnVlFyxt7eeRJMxoAJLt5cMQhJx7Gf70IOyTpcZEyauRlxuUYOL09kS RpP5ILbjjzjj6sTtz1nNYjP4vEJcMeoDGI7O4THOWseyOqGf+HtI4gFfNr16f61Q4DGX F4B1euGKmAE3sPB4P/sPXfI9r7l9rba14CMYoeWixRYavngU/KpGz2rZK1eOsJhvTyQF r/0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=wHSrYaLFEKW9BtP3udbFbBU2SAKScsCe1Lj0LsfOsJI=; b=MGi6pn+mq/CNv3QtTzWLxzc9gjTvPkl9lvNK+g2Db2VVOXOYMvzF/EEB3lp8gVe0uE f4LTwAqsDUHPJHFWJ/ofQBPVFzZmaPBTOFzGyWyLr1nYYk/4xPZaud/eHsr5T5BEEuoZ ORB+V4mne5z8m/lFK+Iy5iuQYJbtb8JjOXlsdbfmpLIvQ8l3S6R8ALO9D8ZJ89XPnWAH y5oI/BmnGaUgVO8Fh2lamtYnINuPl1lzWSnYPwdrBHspOPly0GfyaRxh52JRmGpljet6 dBf+YNJX2zWGU/YDtP6ptkLReBCgM+WaATZSBJkzvyJGiApCYxmbfJxCaPUMRJZkrwG6 U2VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WrwpLBP0; 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 v189si17793548pgb.398.2018.10.31.16.42.05; Wed, 31 Oct 2018 16:42: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; dkim=pass header.i=@kernel.org header.s=default header.b=WrwpLBP0; 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 S1729395AbeKAIIC (ORCPT + 99 others); Thu, 1 Nov 2018 04:08:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:56438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729319AbeKAIIB (ORCPT ); Thu, 1 Nov 2018 04:08:01 -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 47B0A20847; Wed, 31 Oct 2018 23:07:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027270; bh=mI4rkwRfpdXnDl9oWOd9suwcjunbLincP2B5YfZGY+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WrwpLBP0ineTj6QvkD8Tpy1wxMloANY6IONGEONJp4sBhJ5fXUaGP1IwmNbGr4pKZ 7a3Z//s92MtV7QC0AF0x18a88hDnr8Zq1dTR0/pOMklwbRF2RzzcxvBC4Fm8FxIeNT q98PDVIasq7ygS7SqdAu3Rjgi4DrOBVGjvp/FasA= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexandre Belloni , Lee Jones , Sasha Levin Subject: [PATCH AUTOSEL 4.19 143/146] mfd: menelaus: Fix possible race condition and leak Date: Wed, 31 Oct 2018 19:05:38 -0400 Message-Id: <20181031230541.28822-143-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Belloni [ Upstream commit 9612f8f503804d2fd2f63aa6ba1e58bba4612d96 ] The IRQ work is added 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 calling menelaus_add_irq_work. Also, this solves a possible leak as the RTC is never released. Signed-off-by: Alexandre Belloni Signed-off-by: Lee Jones Signed-off-by: Sasha Levin --- drivers/mfd/menelaus.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c index 29b7164a823b..d28ebe7ecd21 100644 --- a/drivers/mfd/menelaus.c +++ b/drivers/mfd/menelaus.c @@ -1094,6 +1094,7 @@ static void menelaus_rtc_alarm_work(struct menelaus_chip *m) static inline void menelaus_rtc_init(struct menelaus_chip *m) { int alarm = (m->client->irq > 0); + int err; /* assume 32KDETEN pin is pulled high */ if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) { @@ -1101,6 +1102,12 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m) return; } + m->rtc = devm_rtc_allocate_device(&m->client->dev); + if (IS_ERR(m->rtc)) + return; + + m->rtc->ops = &menelaus_rtc_ops; + /* support RTC alarm; it can issue wakeups */ if (alarm) { if (menelaus_add_irq_work(MENELAUS_RTCALM_IRQ, @@ -1125,10 +1132,8 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m) menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control); } - m->rtc = rtc_device_register(DRIVER_NAME, - &m->client->dev, - &menelaus_rtc_ops, THIS_MODULE); - if (IS_ERR(m->rtc)) { + err = rtc_register_device(m->rtc); + if (err) { if (alarm) { menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ); device_init_wakeup(&m->client->dev, 0); -- 2.17.1