Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1398718pxb; Sat, 17 Apr 2021 17:01:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEOE877CwdUul/E0IE5pVJD3Od09SrzICGGji5YPWD1HiBvqlqFrMGkAlMeqo/qVHJ5bJr X-Received: by 2002:a63:eb10:: with SMTP id t16mr5338839pgh.393.1618704112675; Sat, 17 Apr 2021 17:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618704112; cv=none; d=google.com; s=arc-20160816; b=Fcj94mLc5wLZa/0+2ctV127NUUSGnwVILU0ZIKmmTCCmKHeZlbgUbf1qcQhpVJGA4+ s1G6CYErPmwQASpdT5L4+w63tHuYcD76aMkpqYS6yHkAH3DvjI1LpNmNtlEgAhWwFSiF JQxUNZyUPpWrdZ4jaR02VlfrMEDq5mQiaVSWrs/spvshupqhkbS2q/ITvkONPxxO0SYX 7VN3x0grGaic7pHrW35v3/FsfYXYd+OBoS1asWxIi9z90oifqUzC2xikzG8x31tkXju9 UU3f9IHRQhNO//1F157qzRVcEMiz5pbUJHUgxgq7QTHnzHwwXYyIh7Pieq6+PkgVbrkr DkOg== 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; bh=oIYVFa4xdykL9WDEVQmPbjIWDdjemvZcTmwlv/qa+3M=; b=jOtTjVCkZtMhOtA7OvXYAjVHyAOljNX53KiKictj0a+S2DY/q7ZWRca+JBJxQHaluc RLfwx10bX/W6wyAif7lPDXFTkTQsRezx0fgAJncyOdRZlkEEDWZ9JLYCaTM98DpEQKYP PxQ2IlHNjkCoeppToM4i4jFnKUNAtDzIi6uHWPzXDLHCwvB85BHg/d5l3SxsGo3SKLqc i1x2LrqztV/eK2vxNVwTzOSo+OTR9Acjbdm82Q/Zd+9G3cQmMkRZl4m0zv+9asLkni7+ 0zREXIO6LpVv9wNbKghUE0yvdFIYQyjxjUSmtyNSg3xGH7ustrRkIOkjo1Ur444hSrmN 51cQ== 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 w132si11322641pfd.78.2021.04.17.17.01.40; Sat, 17 Apr 2021 17:01:52 -0700 (PDT) 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 S236227AbhDRABB (ORCPT + 99 others); Sat, 17 Apr 2021 20:01:01 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:57835 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235843AbhDRAA6 (ORCPT ); Sat, 17 Apr 2021 20:00:58 -0400 X-Originating-IP: 90.65.108.55 Received: from localhost (lfbn-lyo-1-1676-55.w90-65.abo.wanadoo.fr [90.65.108.55]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 4A3B3C0004; Sun, 18 Apr 2021 00:00:30 +0000 (UTC) From: Alexandre Belloni To: Alessandro Zummo , Alexandre Belloni Cc: =?UTF-8?q?=C5=81ukasz=20Stelmach?= , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] rtc: rtc_update_irq_enable: rework UIE emulation Date: Sun, 18 Apr 2021 02:00:23 +0200 Message-Id: <20210418000023.995758-3-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210418000023.995758-1-alexandre.belloni@bootlin.com> References: <20210418000023.995758-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that the core is aware of whether alarms are available, it is possible to decide whether UIE emulation is required before actually trying to set the alarm. This greatly simplifies rtc_update_irq_enable because there is now only one error value to track and is not relying on the return value of __rtc_set_alarm anymore. Tested-by: Łukasz Stelmach Signed-off-by: Alexandre Belloni --- Changes in v2: - Fix possible deadlock when using UIE emulation (no impact on Łukasz' test) - Remove rc drivers/rtc/interface.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index dcb34c73319e..9a2bd4947007 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -545,7 +545,7 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable); int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) { - int rc = 0, err; + int err; err = mutex_lock_interruptible(&rtc->ops_lock); if (err) @@ -561,17 +561,21 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) if (rtc->uie_rtctimer.enabled == enabled) goto out; - if (rtc->uie_unsupported) { - err = -EINVAL; - goto out; + if (rtc->uie_unsupported || !test_bit(RTC_FEATURE_ALARM, rtc->features)) { + mutex_unlock(&rtc->ops_lock); +#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL + return rtc_dev_update_irq_enable_emul(rtc, enabled); +#else + return -EINVAL; +#endif } if (enabled) { struct rtc_time tm; ktime_t now, onesec; - rc = __rtc_read_time(rtc, &tm); - if (rc) + err = __rtc_read_time(rtc, &tm); + if (err) goto out; onesec = ktime_set(1, 0); now = rtc_tm_to_ktime(tm); @@ -585,24 +589,6 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) out: mutex_unlock(&rtc->ops_lock); - /* - * __rtc_read_time() failed, this probably means that the RTC time has - * never been set or less probably there is a transient error on the - * bus. In any case, avoid enabling emulation has this will fail when - * reading the time too. - */ - if (rc) - return rc; - -#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL - /* - * Enable emulation if the driver returned -EINVAL to signal that it has - * been configured without interrupts or they are not available at the - * moment. - */ - if (err == -EINVAL) - err = rtc_dev_update_irq_enable_emul(rtc, enabled); -#endif return err; } EXPORT_SYMBOL_GPL(rtc_update_irq_enable); -- 2.30.2