Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3164080pxb; Sun, 20 Feb 2022 11:09:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqfDME7q5TPcAk7wbneEZKKmwic0IkjkDvrAVE3JMgKemu7UP+QO0eQdEUI9GBr9BEhUKG X-Received: by 2002:a17:902:b410:b0:14b:e53:7aa0 with SMTP id x16-20020a170902b41000b0014b0e537aa0mr15914450plr.101.1645384174853; Sun, 20 Feb 2022 11:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645384174; cv=none; d=google.com; s=arc-20160816; b=Hpgb/qCRqO5abeZVu1+AbhdUUylkwG9DC/i2/FzBl92fK9uR5Kj6ZdcIHPiZCb8vTH U3g3OIpAb47P5gMXGuihb/cqITPZ6qHOEcWBqQUeOON2wYAmmJQ4ASTsJHQFRyGINwkb TquvqaE+1XnhnSkcSRF4PuWtO/YC6nW9uEc4chU0U6xWeqZfT/m8Np0OTXxSAE6RooBk x2jzb2+vf1CM2r8mrZIxImqTEGQlB2fWAoDduVdremlgasz1iQrHgeVN5KVLd2+ypI7w j+AuGH/4jm9iD08vZU5f53fEFHKuvK0ZwvIxvHAssrsPMx0LT1r8iM0CS/5iHWFBllLq gUFw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=X+qXjhMw4ablrWBQcUFh/9RQ37lVwgA+fXmJmWBXEBs=; b=VUHEUMofna/yokQuT4O2q8QiHjmegoilQRkmXhALOxzffLy/RTvWrN0iO0X9uPq/WM Jc3ynNvR7/D4jZN6AF8yvdcjf82n8PrILnCrI9nKN3rnYvsCXqjdtbLyOmQeN8TgSIDU EMcQvkDku3jf0yvkh5UMRwQPGR7gESjiE6aQ5PsHEsK3bjn3IlY1hOno8btQzPR7kZKC xuFQZQRiQAnNrzCW0A1io/2yo52oft8/UyfEOA3SBD3l48VoAu6lzUK+CfVygqA5BtVv hpc0cTn7wPCi4eYwOFoExIdv/kt0iAXUJSdNrHi4ODT7rhX7lBAFBeKQr/IzwDRVWYEB L61w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=OwmhmOB6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=o2.pl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z21si1253440pge.261.2022.02.20.11.09.19; Sun, 20 Feb 2022 11:09:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=OwmhmOB6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=o2.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235444AbiBTJEu (ORCPT + 99 others); Sun, 20 Feb 2022 04:04:50 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234171AbiBTJEr (ORCPT ); Sun, 20 Feb 2022 04:04:47 -0500 Received: from mx-out.tlen.pl (mx-out.tlen.pl [193.222.135.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640FB26568 for ; Sun, 20 Feb 2022 01:04:24 -0800 (PST) Received: (wp-smtpd smtp.tlen.pl 23161 invoked from network); 20 Feb 2022 10:04:19 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1645347860; bh=X+qXjhMw4ablrWBQcUFh/9RQ37lVwgA+fXmJmWBXEBs=; h=From:To:Cc:Subject; b=OwmhmOB65Z+svcWXNDTfJdHDSZSVc59X6f/5Yyh8Qp+bWY/F2Lh3yIc4UtUx79ijc FGXlT4h59kNjAW3JJjSXxmQBnv8NNdpq6TZd4xYfAvWx3fBgPetcZun75ArDN01R/n Dlz1LV+uEYpHI+NMFBXKzL2uInDwZ6M8IHjn3qSU= Received: from aaew227.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.4.126.227]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 20 Feb 2022 10:04:19 +0100 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= To: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni , Thomas Gleixner , stable@vger.kernel.org Subject: [PATCH] rtc-mc146818-lib: fix locking in mc146818_set_time Date: Sun, 20 Feb 2022 10:04:03 +0100 Message-Id: <20220220090403.153928-1-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-WP-MailID: e253a7ce734dbc8d685bdec651998b01 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000000 [QWMU] X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In mc146818_set_time(), CMOS_READ(RTC_CONTROL) was performed without the rtc_lock taken, which is required for CMOS accesses. Fix this. Nothing in kernel modifies RTC_DM_BINARY, so a separate critical section is allowed here. Fixes: dcf257e92622 ("rtc: mc146818: Reduce spinlock section in mc146818_set_time()") Signed-off-by: Mateusz Jończyk Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: Thomas Gleixner Cc: stable@vger.kernel.org --- drivers/rtc/rtc-mc146818-lib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c index ae9f131b43c0..562f99b664a2 100644 --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -232,8 +232,10 @@ int mc146818_set_time(struct rtc_time *time) if (yrs >= 100) yrs -= 100; - if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) - || RTC_ALWAYS_BCD) { + spin_lock_irqsave(&rtc_lock, flags); + save_control = CMOS_READ(RTC_CONTROL); + spin_unlock_irqrestore(&rtc_lock, flags); + if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { sec = bin2bcd(sec); min = bin2bcd(min); hrs = bin2bcd(hrs); base-commit: 754e0b0e35608ed5206d6a67a791563c631cec07 -- 2.25.1