Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3387255ybp; Sun, 6 Oct 2019 10:48:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLaAtGu7lvBgDtP4T0Tsc/QcLJPoHOZQa7vpYT7k8aMuwpW+dIZF4XptVVDiJdy+CjCncl X-Received: by 2002:aa7:d313:: with SMTP id p19mr25143745edq.197.1570384134810; Sun, 06 Oct 2019 10:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384134; cv=none; d=google.com; s=arc-20160816; b=hpGy4/lqEf1zbXPlTGudnyuRyPzEnQZjDu9GFV2U2f6SBFEfHkGljWMOiW6xI9mGmw jB/NbNudN88EzCY+GEkQX4OPQrleZidGfrUnF9WRbNT3YC36jYjFxV490Zhzga5ZLk0e KAbo55lezxwF+3LMz/6tqY3Dtn3d4ErTYmNd6FUQtoH3qdpRMuxEZ9Q2bb9SPPAZIege ZUFz+7k5KTQZy3zKEbhx6dU9kDNPSWDPzjPQG294w/ZlAZsPZTLxIw0XCpJ2CDvMc+A8 cpiWHpRArh/Z3Y7kfB37JlPJwjTNPQWUhtFJUI9mFU779INcImaQejdrXYEI9C3FPB5r 4b0A== 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=heAJMGV+YAmDRs3Um5HBUrWnpo4tWDv0rfHtg8YSF44=; b=cmndKHHiivnd+eJjWzk4iL3zAvY2yysWFAuCEITPECH3Evu3719VkpxwhcU9DRVwXW eHN3ylTWzXwnBUlkUWyvZf6rPN4nHKtzI2uMxBIn33TyBIEwc7fmHtu/2u3P/rM1swSP VRhRjvZgoQUmEzEja5X5fLhzGgu7SrADGnPkm72knkN8KOI1mQC53nFPSVcyaD5lSzIi dZWAf1g+F8KcWOFFR2/bxp/OBP7fTIqWh4Z08HkzUgYLmaqC1biNW9FHWLyuiiXNhUKr D81l/gZlbNtGsg6z7PoA7UVo3o7xb4zDTEpLAZXEKg/GasbnoeeK7IibGkZCS7eF9vDJ E1Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="hV/7Xdis"; 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 q28si7382550eda.322.2019.10.06.10.48.31; Sun, 06 Oct 2019 10:48:54 -0700 (PDT) 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="hV/7Xdis"; 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 S1729715AbfJFRnU (ORCPT + 99 others); Sun, 6 Oct 2019 13:43:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:43240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731499AbfJFRnS (ORCPT ); Sun, 6 Oct 2019 13:43:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 5610220700; Sun, 6 Oct 2019 17:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383797; bh=YDlb7eJfsCJYSe+W+bAGfQM6oR+1wKO4K2sY+007I9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hV/7XdisJarHNqc5dE6sudsxjFeVhkYLs3Jce8XbFLMxb/FCxb8Vw+uJIeKEs8Uhx OJoQQrUl1mdhGiCw1LOwyXs92y0J7tZ7HKtotmzYw9Pf7Fcm9yxTRA/xGdSZrgKjO/ 2iktRFNyWGjAMcWC5tu6PiZspWxfCgx6eLX5U09s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Biwen Li , Alexandre Belloni , Sasha Levin Subject: [PATCH 5.3 100/166] rtc: pcf85363/pcf85263: fix regmap error in set_time Date: Sun, 6 Oct 2019 19:21:06 +0200 Message-Id: <20191006171221.970972410@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171212.850660298@linuxfoundation.org> References: <20191006171212.850660298@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Biwen Li [ Upstream commit 7ef66122bdb3b839e9f51b76d7e600b6e21ef648 ] Issue: - # hwclock -w hwclock: RTC_SET_TIME: Invalid argument Why: - Relative commit: 8b9f9d4dc511 ("regmap: verify if register is writeable before writing operations"), this patch will always check for unwritable registers, it will compare reg with max_register in regmap_writeable. - The pcf85363/pcf85263 has the capability of address wrapping which means if you access an address outside the allowed range (0x00-0x2f) hardware actually wraps the access to a lower address. The rtc-pcf85363 driver will use this feature to configure the time and execute 2 actions in the same i2c write operation (stopping the clock and configure the time). However the driver has also configured the `regmap maxregister` protection mechanism that will block accessing addresses outside valid range (0x00-0x2f). How: - Split of writing regs to two parts, first part writes control registers about stop_enable and resets, second part writes RTC time and date registers. Signed-off-by: Biwen Li Link: https://lore.kernel.org/r/20190829021418.4607-1-biwen.li@nxp.com Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-pcf85363.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c index a075e77617dcb..3450d615974d5 100644 --- a/drivers/rtc/rtc-pcf85363.c +++ b/drivers/rtc/rtc-pcf85363.c @@ -166,7 +166,12 @@ static int pcf85363_rtc_set_time(struct device *dev, struct rtc_time *tm) buf[DT_YEARS] = bin2bcd(tm->tm_year % 100); ret = regmap_bulk_write(pcf85363->regmap, CTRL_STOP_EN, - tmp, sizeof(tmp)); + tmp, 2); + if (ret) + return ret; + + ret = regmap_bulk_write(pcf85363->regmap, DT_100THS, + buf, sizeof(tmp) - 2); if (ret) return ret; -- 2.20.1