Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4481806ivc; Tue, 3 Nov 2020 13:10:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwy9qhVynua85nySvEMMGW4udYKgJSG8YieDCclYWxoatkGw/qw2R9WW9+QeQfgMddwb7Tu X-Received: by 2002:aa7:d9c2:: with SMTP id v2mr7181604eds.95.1604437853070; Tue, 03 Nov 2020 13:10:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437853; cv=none; d=google.com; s=arc-20160816; b=Np8nvbH8k/su/b0/HKyxKEA8bo0WbrChuCHBfZhFoQHNd6D+QCD5akQe5HsDcM+rf2 UObQGRY/l0phoDi6KpAeC7p42ocdDygUyMxweyBRdurdwzKBoEs0hRCCQTUR+ZmHvgg6 jGA+h/6WneT7g2qvRsupJxiz8E3qtFMvFZ11xPd4Pu5Ds7UDkFGQYD4ePShic7kiO+Y6 RQnc5mh9PCm1J0Wn/kAyJ2Db01QEsG4aWLPFypdqdPNonU4yKE9lPYw37er+y4pDYF7r UnEptYO3SY7AkCrCK+5urMOVd6rlxmfHh7Vz39MQOU0swDovXhmgM8NDU4/3QvdlXTve CV9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qGEB9lrCiB5RmQ1v8u8YAFSyEig2Y3Ob9p4cD2O77qE=; b=G9F7aMeVhIGBn9enq8Le/mKr87QnuMv55YIt5pBOXBTlel0A0yJWSTIoK2e5iK5V9N Q1hwWc5aZ7eoRx+xobn6cjq+vKRVNQtQp+MFyfICuYKEY57hEdBx82NajIfGd4sIaJR+ 2hI7i1po239Lnw72/Kc0gJvIWrFdP3c2xYOfxzN0ywkLfjK3ysYi+5nKmE3GsdH8kSPK EwBabMI3K76SlBwzASDwiIoyRRq959/XMztRb7LWp4FgnRgsIzB6Oa2VCWtO24ZQkJgi IjWg5WGRdid7FtrAApuerKU9O4SJUfUhkD3Aak0tWyf66oJcVd0TrhLUewzpRu+6nx8c uHcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u3YdsnP0; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co16si14060367edb.465.2020.11.03.13.10.30; Tue, 03 Nov 2020 13:10:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=u3YdsnP0; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388361AbgKCVIA (ORCPT + 99 others); Tue, 3 Nov 2020 16:08:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:47290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388345AbgKCVHy (ORCPT ); Tue, 3 Nov 2020 16:07:54 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 0F36C206B5; Tue, 3 Nov 2020 21:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437674; bh=4W7mOMzad/Ugm0x2tJkIWCRui190OZvtegKywXFEoZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u3YdsnP0sjdiEt0PQmMhtoWPgoYAD4NEudwss1XXop+8EJIvg3Bg6x85mgtPBSLda NTMxEg8kPKtwTzGPTdKtmo5QRFMXbHHvQxlEszLTxac2wktr8loJW99r7HiiJRhwbS J0r0ZeJrHUNVxP1PijwL7SWjPPrISMJr7VwxcVQ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bartosz Golaszewski , Alexandre Belloni Subject: [PATCH 4.19 178/191] rtc: rx8010: dont modify the global rtc ops Date: Tue, 3 Nov 2020 21:37:50 +0100 Message-Id: <20201103203249.312789260@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Bartosz Golaszewski commit d3b14296da69adb7825022f3224ac6137eb30abf upstream. The way the driver is implemented is buggy for the (admittedly unlikely) use case where there are two RTCs with one having an interrupt configured and the second not. This is caused by the fact that we use a global rtc_class_ops struct which we modify depending on whether the irq number is present or not. Fix it by using two const ops structs with and without alarm operations. While at it: not being able to request a configured interrupt is an error so don't ignore it and bail out of probe(). Fixes: ed13d89b08e3 ("rtc: Add Epson RX8010SJ RTC driver") Signed-off-by: Bartosz Golaszewski Signed-off-by: Alexandre Belloni Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20200914154601.32245-2-brgl@bgdev.pl Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-rx8010.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) --- a/drivers/rtc/rtc-rx8010.c +++ b/drivers/rtc/rtc-rx8010.c @@ -428,16 +428,26 @@ static int rx8010_ioctl(struct device *d } } -static struct rtc_class_ops rx8010_rtc_ops = { +static const struct rtc_class_ops rx8010_rtc_ops_default = { .read_time = rx8010_get_time, .set_time = rx8010_set_time, .ioctl = rx8010_ioctl, }; +static const struct rtc_class_ops rx8010_rtc_ops_alarm = { + .read_time = rx8010_get_time, + .set_time = rx8010_set_time, + .ioctl = rx8010_ioctl, + .read_alarm = rx8010_read_alarm, + .set_alarm = rx8010_set_alarm, + .alarm_irq_enable = rx8010_alarm_irq_enable, +}; + static int rx8010_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); + const struct rtc_class_ops *rtc_ops; struct rx8010_data *rx8010; int err = 0; @@ -468,16 +478,16 @@ static int rx8010_probe(struct i2c_clien if (err) { dev_err(&client->dev, "unable to request IRQ\n"); - client->irq = 0; - } else { - rx8010_rtc_ops.read_alarm = rx8010_read_alarm; - rx8010_rtc_ops.set_alarm = rx8010_set_alarm; - rx8010_rtc_ops.alarm_irq_enable = rx8010_alarm_irq_enable; + return err; } + + rtc_ops = &rx8010_rtc_ops_alarm; + } else { + rtc_ops = &rx8010_rtc_ops_default; } rx8010->rtc = devm_rtc_device_register(&client->dev, client->name, - &rx8010_rtc_ops, THIS_MODULE); + rtc_ops, THIS_MODULE); if (IS_ERR(rx8010->rtc)) { dev_err(&client->dev, "unable to register the class device\n");