From patchwork Fri Jan 7 12:49:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mateusz_Jo=C5=84czyk?= X-Patchwork-Id: 531551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11F2CC433EF for ; Fri, 7 Jan 2022 12:49:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238675AbiAGMtw (ORCPT ); Fri, 7 Jan 2022 07:49:52 -0500 Received: from mx-out.tlen.pl ([193.222.135.175]:9836 "EHLO mx-out.tlen.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238320AbiAGMtt (ORCPT ); Fri, 7 Jan 2022 07:49:49 -0500 Received: (wp-smtpd smtp.tlen.pl 25369 invoked from network); 7 Jan 2022 13:49:47 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1641559787; bh=UHf1ypbd17Kopy+oZJ9KeBqXEW0Si75CBEqlrPjJ6Rk=; h=From:To:Cc:Subject; b=Niuuaj6vl4Ldq+u9JxR845WtXP6Ugz6sglMRNFy3pQBZ73cszccKeE4ofdjGY8bxX G7fwZ4UDwPZWKPUFhwKdvgvORtlESiQdJKsQLycldaJbDcyPK9887gw1lon+1eDRVl Dtt1il7kSNQf6Y5/Y/nlQgTEY1EiVhYgNddITA4o= Received: from aafo3.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.4.144.3]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 7 Jan 2022 13:49:47 +0100 From: =?utf-8?q?Mateusz_Jo=C5=84czyk?= To: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Mateusz_Jo=C5=84czyk?= , Nobuhiro Iwamatsu , Alessandro Zummo , Alexandre Belloni , stable@vger.kernel.org Subject: [PATCH v5 1/9] rtc-cmos: take rtc_lock while reading from CMOS Date: Fri, 7 Jan 2022 13:49:26 +0100 Message-Id: <20220107124934.159878-2-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220107124934.159878-1-mat.jonczyk@o2.pl> References: <20220107124934.159878-1-mat.jonczyk@o2.pl> MIME-Version: 1.0 X-WP-MailID: dd77bd68e39a807167e8cc7b9dfb0677 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0100001 [4XKz] Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Reading from the CMOS involves writing to the index register and then reading from the data register. Therefore access to the CMOS has to be serialized with rtc_lock. This invocation of CMOS_READ was not serialized, which could cause trouble when other code is accessing CMOS at the same time. Use spin_lock_irq() like the rest of the function. Nothing in kernel modifies the RTC_DM_BINARY bit, so there could be a separate pair of spin_lock_irq() / spin_unlock_irq() before doing the math. Signed-off-by: Mateusz Jończyk Reviewed-by: Nobuhiro Iwamatsu Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: stable@vger.kernel.org --- drivers/rtc/rtc-cmos.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 4eb53412b808..dc3f8b0dde98 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -457,7 +457,10 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) min = t->time.tm_min; sec = t->time.tm_sec; + spin_lock_irq(&rtc_lock); rtc_control = CMOS_READ(RTC_CONTROL); + spin_unlock_irq(&rtc_lock); + if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { /* Writing 0xff means "don't care" or "match all". */ mon = (mon <= 12) ? bin2bcd(mon) : 0xff;