From patchwork Thu Jan 26 14:20:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 48704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp296360wrn; Thu, 26 Jan 2023 06:23:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXtM4s96fOMIDQ17/pOSzu0+u4ePmAJ7z0/Ya+ArBmFDyog40epeQtrHJdwaZoe1P3/aKpDj X-Received: by 2002:a17:907:d094:b0:7c9:6e0e:1427 with SMTP id vc20-20020a170907d09400b007c96e0e1427mr34818715ejc.6.1674743018283; Thu, 26 Jan 2023 06:23:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674743018; cv=none; d=google.com; s=arc-20160816; b=tYkKVjRKAmDd39DqQZ/GdYpjklHYtLVZlVilN63/2z0KyJK4nLlQUNiOCHIJhjImuW VGfgmPSWlvSZZ6dk2hdkRSQwwprWO+DhQyk3Gwng9nW3/tm8oTMyzOTIXZC/DM1O5zOS PY1udaijvBmgzb2iAc8ku2BC+0RvdUhICNQ/TXpYgz9APiylhsY8yELVl7DbyAleM91d OnWfQ69abI8mBhSdOAWr7LsRvN4KJSzrvCGX5GK+cZlIvJ1ge7nAIKP8Bn+nZbUApyV1 RFo3wA98cTjIg86TLBCGzryUzzbQdZF/fxyAJQGX6FVxTuUeRXl6QxofotomZa7Gqa8M 9XgA== 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=vVqlC9ge1hHuk79ia3sbPtZ3NGpNDhdOZk72He/hH7c=; b=WeMADiUwYXiumj4XntRpZZG2QjQK+sVbur+0LPHcFQJGzOjAEQhG1ykfEN//LnyQfU L9c2TrP9mU3B2ZAUFU4wXS7wXKbOGq+fV5tfg+4DE14Ad0n2YvaSiewsrCiGLY7FlEeE NymMKw91EZ6xhaQqZAZIMbdaNSLc95wAxcBYwyxHxNI91JU/BM1SR4W7UqHwlrBLiKGa rvQE+gBedyyXtvpeWCVUilbOvJ9kunW9kUUH/LL2YwD9w1BZBycejhvXzlG8ss9Nalmw tDZyQpOIu+oQ9bmzLHqi41LoesfTGWvp1MzLUAQDOeXSgxbSdODDx7zyXpCm51z84rF3 utIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lyvjj+++; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q9-20020a056402040900b0048c1bb5d23bsi1848469edv.67.2023.01.26.06.23.13; Thu, 26 Jan 2023 06:23:38 -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 header.i=@kernel.org header.s=k20201202 header.b=lyvjj+++; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231950AbjAZOXE (ORCPT + 99 others); Thu, 26 Jan 2023 09:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230287AbjAZOW7 (ORCPT ); Thu, 26 Jan 2023 09:22:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CE65113E4; Thu, 26 Jan 2023 06:22:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2928661844; Thu, 26 Jan 2023 14:22:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D67DC4339C; Thu, 26 Jan 2023 14:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674742977; bh=DNEhyu7u4f062FvvbtsFWr1nXt0qu/y1C2h9iu3ZUpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lyvjj+++zBplLPtJ3Fe6CTaq9zUg02yWKvoLq+i3X1BqE1/faXTCQLfga0vyVbHAi 8DdC1cfRTNkWd4dPYrRaY/l9T157clSt4RXJmvfkRKBojoC4tTEvKtp6B+y7BbC0aT K44y8f8AYiuCf1Y4cEXM/kyLVK1RX4rTYDoQ0MNYoHY3NUFy1raebW375ckHPoea2b qUHhfYUxah8JfAVY55E99k2inM6PC7sFHdx2L1Mjm2ce3KNhyEl28dm+PT5RLZ8Mme osL36OMJlZlVXW8nLAsrSFOGie4Y3YQDKFFc5Paz4XyJ4RR3F5uuUmAKgcIOfpg28g 3uUZcg39+hkaw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pL39c-0006iE-01; Thu, 26 Jan 2023 15:23:04 +0100 From: Johan Hovold To: Alexandre Belloni , Bjorn Andersson Cc: Andy Gross , Konrad Dybcio , Alessandro Zummo , Rob Herring , Krzysztof Kozlowski , Maximilian Luz , linux-arm-msm@vger.kernel.org, linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 01/24] rtc: pm8xxx: fix set-alarm race Date: Thu, 26 Jan 2023 15:20:34 +0100 Message-Id: <20230126142057.25715-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230126142057.25715-1-johan+linaro@kernel.org> References: <20230126142057.25715-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756095334850324030?= X-GMAIL-MSGID: =?utf-8?q?1756095334850324030?= Make sure to disable the alarm before updating the four alarm time registers to avoid spurious alarms during the update. Note that the disable needs to be done outside of the ctrl_reg_lock section to prevent a racing alarm interrupt from disabling the newly set alarm when the lock is released. Fixes: 9a9a54ad7aa2 ("drivers/rtc: add support for Qualcomm PMIC8xxx RTC") Cc: stable@vger.kernel.org # 3.1 Signed-off-by: Johan Hovold --- drivers/rtc/rtc-pm8xxx.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c index 716e5d9ad74d..d114f0da537d 100644 --- a/drivers/rtc/rtc-pm8xxx.c +++ b/drivers/rtc/rtc-pm8xxx.c @@ -221,7 +221,6 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { int rc, i; u8 value[NUM_8_BIT_RTC_REGS]; - unsigned int ctrl_reg; unsigned long secs, irq_flags; struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; @@ -233,6 +232,11 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) secs >>= 8; } + rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, + regs->alarm_en, 0); + if (rc) + return rc; + spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, @@ -242,19 +246,11 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) goto rtc_rw_fail; } - rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg); - if (rc) - goto rtc_rw_fail; - - if (alarm->enabled) - ctrl_reg |= regs->alarm_en; - else - ctrl_reg &= ~regs->alarm_en; - - rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); - if (rc) { - dev_err(dev, "Write to RTC alarm control register failed\n"); - goto rtc_rw_fail; + if (alarm->enabled) { + rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, + regs->alarm_en, regs->alarm_en); + if (rc) + goto rtc_rw_fail; } dev_dbg(dev, "Alarm Set for h:m:s=%ptRt, y-m-d=%ptRdr\n",