Received: by 10.223.185.116 with SMTP id b49csp4465482wrg; Mon, 26 Feb 2018 19:05:10 -0800 (PST) X-Google-Smtp-Source: AH8x227a0+ks0qiBgFa8LNvXxIH3LNU2WfOSQGgY3CDM7uFnk+65Q2l9fPGSD12jLW5zMZdfs77P X-Received: by 10.99.125.79 with SMTP id m15mr10000493pgn.428.1519700710035; Mon, 26 Feb 2018 19:05:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519700709; cv=none; d=google.com; s=arc-20160816; b=l8oL/3GW6FJf3QDTuZfqgMZHM7+ROEuPsk9WW0V/ZTQkCWkZXMKzeVyTd4ee8ieZcF Hc2dsJhYC/9Sl5P1G9PzJ1oL4bJ3/rh7DKa4HqiCOrr/5Un0NISzV+xL1aQRw57kIaPD mjSCgf40yFZy8xdlwQzA4qY5TjeeNPB4UfVqvcRzZeinr7Tgina8doDx0HLCHwlDpXZt j3ieUkteB0RXBZWCILh7SsYIB20UT3DwAo3GNzZVC2fJrfeUaigz2PyZGS841A4IGcJl cyr0HoG9jt/rgLBkWifs2c+p7ymNvdcBek7cuNwijyrNkuB6yEYat9C0qJYj7I3ynjeg yL0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=RHuAfPf7gatM7h/JfJcBtq2GCm10kqlxhtYmz+RBi1c=; b=jZdF4+iZxYjfb0nN5hNEJDSCFTQFluHzywEz6XXYyVPcE+31T2kgnHCIl1W4WjlQJ2 K5xwkqAn7An6bv1UY6o5G9ZlaTs91COzhayoDp0pgPWfCHIkqGgRVWeMUwbFJX79yD1Y 49d4EXZcbiVxWvDTqV4OUAEDYMa9xgEqtEQaoAeZXxmGzaF48i5xgQ+8uzoE2nd/CkPN RIOrcc072ROwdDzaOAsHm36Srd99/Hg98atHjvK18IQ3Uv2t0EhnXWR4p9zeh9G/6lcS leLXkvBWuBz5WKt4u6OvP+tc+3QsJfzwCgOoKt0sct8PjBGN6vc9OJv2PMhxra0K+uEx odPQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13si7783752pfc.255.2018.02.26.19.04.55; Mon, 26 Feb 2018 19:05:09 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751587AbeB0CuR (ORCPT + 99 others); Mon, 26 Feb 2018 21:50:17 -0500 Received: from regular1.263xmail.com ([211.150.99.132]:33926 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751396AbeB0CuQ (ORCPT ); Mon, 26 Feb 2018 21:50:16 -0500 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.131]) by regular1.263xmail.com (Postfix) with ESMTP id 8157E9416; Tue, 27 Feb 2018 10:50:12 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 1BC3E39C; Tue, 27 Feb 2018 10:50:06 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <5d8b5fb0ab401602e5c8e847dbac03a4> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 28725KQUFAD; Tue, 27 Feb 2018 10:50:12 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Cc: zyw@rock-chips.com, briannorris@google.com, dianders@google.com, jwerner@chromium.org, Jeffy Chen , linux-rtc@vger.kernel.org, Alexandre Belloni , Alessandro Zummo Subject: [RESEND PATCH v3] rtc: cros-ec: return -ETIME when refused to set alarms in the past Date: Tue, 27 Feb 2018 10:50:03 +0800 Message-Id: <20180227025003.8823-1-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since accessing a Chrome OS EC based rtc is a slow operation, there is a race window where if the alarm is set for the next second and the second ticks over right before calculating the alarm offset. In this case the current driver is setting a 0-second alarm, which would be considered as disabling alarms by the EC(EC_RTC_ALARM_CLEAR). This breaks, e.g., hwclock which relies on RTC_UIE_ON -> rtc_update_irq_enable(), which sets a 1-second alarm and expects it to fire an interrupt. So return -ETIME when the alarm is in the past, follow __rtc_set_alarm(). Signed-off-by: Jeffy Chen --- Changes in v3: Fix alarm time comparing. Changes in v2: Rewrite commit message as Brian suggested. Check alarm time only when that alarm is enabled. drivers/rtc/rtc-cros-ec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c index f0ea6899c731..bf7ced095c94 100644 --- a/drivers/rtc/rtc-cros-ec.c +++ b/drivers/rtc/rtc-cros-ec.c @@ -197,10 +197,10 @@ static int cros_ec_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) cros_ec_rtc->saved_alarm = (u32)alarm_time; } else { /* Don't set an alarm in the past. */ - if ((u32)alarm_time < current_time) - alarm_offset = EC_RTC_ALARM_CLEAR; - else - alarm_offset = (u32)alarm_time - current_time; + if ((u32)alarm_time <= current_time) + return -ETIME; + + alarm_offset = (u32)alarm_time - current_time; } ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, alarm_offset); -- 2.11.0