Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp822122pxb; Tue, 3 Nov 2020 13:31:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/OTH+hE8dWdp/4kmNTtxZLzTLxPcatZK7D67AJBOzzyh/tlfkCZY9oxPah0/emRgDxkeC X-Received: by 2002:a17:906:c43:: with SMTP id t3mr21407590ejf.219.1604439101858; Tue, 03 Nov 2020 13:31:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439101; cv=none; d=google.com; s=arc-20160816; b=fB1KsQHK77Z4vUxIR1XEYJM+x1EUNgYr7wNdVHKEu01q0z1KmZYjLGtWG6xuC92WdN wjmd2ASYM+8dpXN8ZLp6bBh2Z5OlUMlnmwx5mKmlBdRdx55igLVIOw/o0iE87reEaKx6 Bz0zg8AIeoPVfnA7x591/5Fwdde4QuJM4JxOMP8xm7nCRZ/wnonwsMYGH9rmUKCJd4HJ qOecEoTUmUBnBQsUQL1AS9IEnN8g351sNqGvXPF/iHiJgnWi5XNI8PzyuKauOU+UR05y g9EOiLSts1jCx0svn4R52lttWG7UsaZdBOCijBVgO5lzY2RfMUwEgKfqdow6tKQVfHIT +oGA== 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=0N2nHZgpwyOKz+74/C90vU7LqkqTYLAtx1cq7oUEi10=; b=jAOdYI2TSvnDGBnpE7lFAEz85NY5x/R1xc3HRdqvMzdNVJvSFXsaq0WGDdcnQe0AAx QksB4GaQryWPtFs7OZ9IZhTY3qVlMz+v0HJiiq/VC9GBY+uXWeNu82vhYiM2G7JWcW0d l5sG/k9HN8ur9Kbld87MMHAOr74dEk/TOkJu8cFwu/PpL2/5R2NLeie0gc58bSOUvY1g abJru37u1UQvEAoRAYitJzcvKuCIaE0HO5XenETN4fBEmFAhsWUPePFEVGREDCubFW+a k65ybV52InO+8D/Up9vpjuy6NmHgP1MQzpqQiIaULV62hxh75QwbxCQYXatYriEj6FPP h05Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M3ZTKs11; 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 z22si6531ejx.130.2020.11.03.13.31.19; Tue, 03 Nov 2020 13:31:41 -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=M3ZTKs11; 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 S1732282AbgKCV2m (ORCPT + 99 others); Tue, 3 Nov 2020 16:28:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:34754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733121AbgKCU7d (ORCPT ); Tue, 3 Nov 2020 15:59:33 -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 020E522226; Tue, 3 Nov 2020 20:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437172; bh=JR4T5gEPqDRh5LsJJ2sCGiS8NiCyDyheY+/rh/QCPuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3ZTKs11vJpKHmjaHdtyul4bhGnLxGum3FKVVAn95jNo1XT6ldAhv1sshPx5lD5GL m93xA1yEldFADhWfjIOLyN1luH2lsQavahtp+v9/oz4u81OY703KyfHZ0DNcPvrI4Y Q1g+B8+xFTyuY/W7mOcH4xjv0JYM+G+n1s3G53ME= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bartosz Golaszewski , Alexandre Belloni Subject: [PATCH 5.4 177/214] rtc: rx8010: dont modify the global rtc ops Date: Tue, 3 Nov 2020 21:37:05 +0100 Message-Id: <20201103203307.304517193@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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 @@ -424,16 +424,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 = client->adapter; + const struct rtc_class_ops *rtc_ops; struct rx8010_data *rx8010; int err = 0; @@ -464,16 +474,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");