Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5653829pxb; Sun, 7 Nov 2021 17:17:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaE3bmvMiz86sv0K3HpG3eC1+uvaI9kl/jIjZwioh0vnoksZVyexUuzPB9J5FUt5dnCFHd X-Received: by 2002:a17:907:961e:: with SMTP id gb30mr33990309ejc.436.1636334232271; Sun, 07 Nov 2021 17:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636334232; cv=none; d=google.com; s=arc-20160816; b=R4/O69gyzhHvGb/AC2NdbYdAHyCT72pYQeStVVrnWIYxeiO7T7opHEJJ/khyM/+lq6 kza5VPRtl/RujWjB3xDGrUK5pNbUGpPiOzFCuu/FVI44Kv1iZy4fTDAD/dtkZD3KmCzX uSTviy1NWnZb8oy3GQTbLrz6o88FpgSYDVxsjTdDIrxUyhtUAI9RpnO3gipCOdgJwqq5 TvU9VWnr/sHhhySoCWusBqzK9j5IBz1ofe9zLCZ+CtBV2p5pd1QcVQ8Jh4t4SgbYzRVS 6qS0bGyK+R8mD/mJcqO2LtZ6NlKbYMyHhSQuvdgYAoJSZB490PNBmOx9sjyu1oZB0B4A cMVg== 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; bh=z6fd3bcOJDTSzrSzlPX1h5TMt4EXIvsbkXqGo6DDbvk=; b=BO+42Dbx9NLXG6p5z0g7NGR1lg+jErOYkG3AGbSu3UwOZiyR1GGptu+33r9eHG1vdS JdwDqHaU0DsewULcC0IV8Gb8bUXy6i8zjimO/aChPyVrENbdQ+z8cvLK8nyxSIeOPVlX MyPEhgMly3GrUp1Eil8dribpOmTah/RXtdc4wIu+fytKIyA1gu59mHJnKDWdSV7CfCQz 6qU9zaMWfG9mkcfUTGxZ+oQBVZx9r99m5zUVBXoeFIekmYh6US5YmbiDblmk0wZRn837 RV3G/alEhFMsO9TZRFsDZ8tV0HLAfRHQV7+gYHOpxMNItV7p+27TQojE1kq0DliBsmLP vkNg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr6si7396749ejc.567.2021.11.07.17.16.49; Sun, 07 Nov 2021 17:17:12 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236700AbhKGW5r (ORCPT + 99 others); Sun, 7 Nov 2021 17:57:47 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:54461 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233191AbhKGW5r (ORCPT ); Sun, 7 Nov 2021 17:57:47 -0500 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 25BAF20008; Sun, 7 Nov 2021 22:55:01 +0000 (UTC) From: Alexandre Belloni To: Alessandro Zummo , Alexandre Belloni Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/12] rtc: handle alarms with a minute resolution Date: Sun, 7 Nov 2021 23:54:46 +0100 Message-Id: <20211107225458.111068-1-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Handle alarms with a minute resolution in the core. Until now drivers have been open coding the seconds part removal and have been doing that wrongly. Most of them are rounding up which means the allow the system to miss deadlines. So, round down and let __rtc_set_alarm return immediately if the time has already passed. Signed-off-by: Alexandre Belloni --- drivers/rtc/interface.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index d005623e6eb3..d8e835798153 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -423,6 +423,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) if (err) return err; now = rtc_tm_to_time64(&tm); + if (scheduled <= now) return -ETIME; /* @@ -447,6 +448,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) { + ktime_t alarm_time; int err; if (!rtc->ops) @@ -468,7 +470,15 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) if (rtc->aie_timer.enabled) rtc_timer_remove(rtc, &rtc->aie_timer); - rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); + alarm_time = rtc_tm_to_ktime(alarm->time); + /* + * Round down so we never miss a deadline, checking for past deadline is + * done in __rtc_set_alarm + */ + if (test_bit(RTC_FEATURE_ALARM_RES_MINUTE, rtc->features)) + alarm_time = ktime_sub_ns(alarm_time, (u64)alarm->time.tm_sec * NSEC_PER_SEC); + + rtc->aie_timer.node.expires = alarm_time; rtc->aie_timer.period = 0; if (alarm->enabled) err = rtc_timer_enqueue(rtc, &rtc->aie_timer); -- 2.31.1