Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3210801pxb; Mon, 9 Nov 2020 05:41:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4rz5kjSNI47ko0i7Zl2bEl4d8KUt8tmmwug/bA1DHzvoAx4/+mi88hfFnDpeuFpUCqKQ1 X-Received: by 2002:a50:dac9:: with SMTP id s9mr14939769edj.75.1604929296839; Mon, 09 Nov 2020 05:41:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929296; cv=none; d=google.com; s=arc-20160816; b=uNCYj/oIj6Z/4fYkq5BX5t62uSEAe3yvuhGmdgW7ag9ytXjHxVnj5+imUyoJ/zArdu I0/lGfVabHNEiK3ICWhhnShzRXuDZRua7T7FhjB6DUCIJgcHpcePWMs+vFboQoLMrGeP ycKh6tTBa7Y5ELfpkZDalY+67MtF4dcDTAJqtUV1SeUJdspgeYN0O0RgSmruBzpCDwLQ HwRYOv3RH8iJsy7QaMeFXMfseimQsjmSCjKwUBmlWeCDt/eG6qUcamcZ+j29w5Pqy/id 6kRfUOJrSyrMhXKAeVGEHH62DzW5eeifVW7sL0mrCu0Zo5GWCL6J0bs7fxSmUwN6uLvE 9bAQ== 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=p6gkQVm73LksIMsmqG2Zb2ZtmA36fN3QpxeWykOypPQ=; b=poNt69hWhrxoBiBEcc3xj/1eb+7RFCRoALB2xRw5/Xv50/imZTpMc6moy6qPOIqJFu l9zBpVz2loKAKqKbFdYII6t690gLzpFBfM/QUOOGhD/4UjTqZSBVnCccDjpN/JgfPgqK VgSvarF7l8rTeRgc8nr0WLqLhKXGOAXfiC6XF4KWxwrgcvCyvyTPBWKMC4j+kK/yK+aH H06/DEhhwbs53oSF+p6tai71y/gmG0qwCue5EgNdsAYWNjaCdeqqGvtaa5NF4hUQSUio zGlDvK29njZlfPL8TAiEe4/wYYXr8t0Z6jRN6gJQP83UbdKbwSCzrfMtXdaNA7c9dKiK MSXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zR+Aa0ge; 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 k12si6691858ejr.406.2020.11.09.05.41.13; Mon, 09 Nov 2020 05:41:36 -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=zR+Aa0ge; 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 S1731598AbgKINh6 (ORCPT + 99 others); Mon, 9 Nov 2020 08:37:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:56968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730201AbgKINDu (ORCPT ); Mon, 9 Nov 2020 08:03:50 -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 A83C2206C0; Mon, 9 Nov 2020 13:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927029; bh=NWw+EvJR+pMJNCnEb8dKP/yAa1d7ZSFJ+35CWjpXPrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zR+Aa0geSilw+mTJxrTDRLJvyCMLRGR5I3Thy8KY38h2/4KAuG615H+G0NG+uGzEx Rp4s0T26aH5r0nB9wBiqvTTl31obq+FunexrBjjSw/gEmGU/MdFcRCJ5hl5/98KWPE OY1VWj26DakJ6mEsulc45UZhQIfH5BSMJgSYI9Pk= 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.9 079/117] rtc: rx8010: dont modify the global rtc ops Date: Mon, 9 Nov 2020 13:55:05 +0100 Message-Id: <20201109125029.437045558@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 @@ -423,16 +423,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; @@ -463,16 +473,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");