Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2535958imu; Thu, 29 Nov 2018 06:33:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/X0lxne5pU6BBiMptqVNHByNCY/M9KCGUGIWAKMgW0i22r4p1TAe5IPkwru9+4EL1JD/gjX X-Received: by 2002:a62:3581:: with SMTP id c123mr1632287pfa.82.1543501981926; Thu, 29 Nov 2018 06:33:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501981; cv=none; d=google.com; s=arc-20160816; b=JXjrDdreuX2x0I/EWzDv0/NcmGj+YaXF+BulG9P0yZnzgcSjKxRiExPzSkmI42vvzH F8NUV5z83Fx/2LKL/t321447OkYqbEvzole6L5+mTBEOSOEO9jMNksyN2CJMxqCPEJLx hipjSccTwUEEzINomfWd0t6Zlp8rx/f915uRD5VL1UnPn8Yz7q0+0SV0mU5Hq8WHO6Vq krJyysSrqnL/XDsqA8R7GqcMFfNDooz2y+knDOxzryvkP3IWoGAqv5l60IsLi7Gnm8NA 5S5QzlJW4P9gAQX68CBPIiQ5vtnhbr5tMpquZlys8RA7JdNCa1qbRkGsjrJ8EyyZDtZy ralw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YxkyWznA7oUF/VfUeDNjH/IVGFHpiEc+rlYSEwnnKes=; b=cJudMUK/PVEd/V5ZTA5qF/UJdLU/b3iMGQv5LNuavr4PDFLezXAtMJzy6Mulvm/HF6 z0ADimWVx3QedpnKjzmoG8yeyfRy/PtXy+fZYiLG07dKsMipxF+nq/jO6Nu/qhD03p4B 5qiUeJ7AN3v1RymRR0UIKVu5t4Zl/S637jp2J3m/Obtl3JP1WiZQgxqm1Gg3rxreBeKE eWlOPyev6/ixPPvoikjnHFhcQrht1KWypS1ylJQ412rFVwxYMhQ23HlqeyrdhmQz5Fv+ zm/u2qA2SF/Ngpfk8j5osMNw4adoIyUQ4kWicrDvA7YoEp1ONsRr27DV8qtl+tq4+FNS g1bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fcPmX8US; 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 v141si2453293pfc.260.2018.11.29.06.32.33; Thu, 29 Nov 2018 06:33:01 -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; dkim=pass header.i=@kernel.org header.s=default header.b=fcPmX8US; 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 S1729090AbeK3Bgp (ORCPT + 99 others); Thu, 29 Nov 2018 20:36:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:39294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729050AbeK3Bgp (ORCPT ); Thu, 29 Nov 2018 20:36:45 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 52FA2213A2; Thu, 29 Nov 2018 14:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501871; bh=O0/difCFKisKCyBXuM8xEWeDBDj6VqhKRfyHHkaYUuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fcPmX8USSi6NNS9215gn7UcMiK2AM0tB44NFw58YIKzbTyfMabkaT6X8uACr7oPYJ ++xU0lGtg8zURKmb6vtxVizMY4dNiWXqG9fKuTqftZtDzYOPHHoKJIghCMhHrn8ucV Iyj9IruXo3VP0OAYS6AQSTY0O3YCfGUv1UfFg+oo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Alexandre Belloni , Sasha Levin Subject: [PATCH 4.19 075/110] rtc: cmos: Do not export alarm rtc_ops when we do not support alarms Date: Thu, 29 Nov 2018 15:12:46 +0100 Message-Id: <20181129135924.281270217@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129135921.231283053@linuxfoundation.org> References: <20181129135921.231283053@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit fbb974ba693bbfb4e24a62181ef16d4e45febc37 ] When there is no IRQ configured for the RTC, the rtc-cmos code does not support alarms, all alarm rtc_ops fail with -EIO / -EINVAL. The rtc-core expects a rtc driver which does not support rtc alarms to not have alarm ops at all. Otherwise the wakealarm sysfs attr will read as empty rather then returning an error, making it impossible for userspace to find out beforehand if alarms are supported. A system without an IRQ for the RTC before this patch: [root@localhost ~]# cat /sys/class/rtc/rtc0/wakealarm [root@localhost ~]# After this patch: [root@localhost ~]# cat /sys/class/rtc/rtc0/wakealarm cat: /sys/class/rtc/rtc0/wakealarm: No such file or directory [root@localhost ~]# This fixes gnome-session + systemd trying to use suspend-then-hibernate, which causes systemd to abort the suspend when writing the RTC alarm fails. BugLink: https://github.com/systemd/systemd/issues/9988 Signed-off-by: Hans de Goede Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-cmos.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index df0c5776d49b..a5a19ff10535 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -257,6 +257,7 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t) struct cmos_rtc *cmos = dev_get_drvdata(dev); unsigned char rtc_control; + /* This not only a rtc_op, but also called directly */ if (!is_valid_irq(cmos->irq)) return -EIO; @@ -452,6 +453,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) unsigned char mon, mday, hrs, min, sec, rtc_control; int ret; + /* This not only a rtc_op, but also called directly */ if (!is_valid_irq(cmos->irq)) return -EIO; @@ -516,9 +518,6 @@ static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled) struct cmos_rtc *cmos = dev_get_drvdata(dev); unsigned long flags; - if (!is_valid_irq(cmos->irq)) - return -EINVAL; - spin_lock_irqsave(&rtc_lock, flags); if (enabled) @@ -579,6 +578,12 @@ static const struct rtc_class_ops cmos_rtc_ops = { .alarm_irq_enable = cmos_alarm_irq_enable, }; +static const struct rtc_class_ops cmos_rtc_ops_no_alarm = { + .read_time = cmos_read_time, + .set_time = cmos_set_time, + .proc = cmos_procfs, +}; + /*----------------------------------------------------------------*/ /* @@ -855,9 +860,12 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq); goto cleanup1; } + + cmos_rtc.rtc->ops = &cmos_rtc_ops; + } else { + cmos_rtc.rtc->ops = &cmos_rtc_ops_no_alarm; } - cmos_rtc.rtc->ops = &cmos_rtc_ops; cmos_rtc.rtc->nvram_old_abi = true; retval = rtc_register_device(cmos_rtc.rtc); if (retval) -- 2.17.1