Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp6025402ybn; Sun, 29 Sep 2019 10:42:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwI69T0XV2kwiVYhMFeaNCfB8bSNO8+SSURBPotCLG03KoJnHL1yfuCQqIJz8jVp6XOWFbI X-Received: by 2002:a17:906:41a:: with SMTP id d26mr16073990eja.17.1569778966827; Sun, 29 Sep 2019 10:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569778966; cv=none; d=google.com; s=arc-20160816; b=z/P9yxnd2kKBfKGvpvFzWUPFnV24AYJG1C8ZUkWMXYSqJOm22k0u0g0eLJUmFhA3eA ROXZhcdKQmEwuWwvNdJ9ok8INeDcyXUHTO54nQzM4t18MBTQRA8UOk1trIaRAxeeAy1I qa3a/vxo+059QIm3ooVehFg9UB3BiXD/wsM+UuoHQDte0lj6TIdblJNDT9gxjW55lGCV Qh1D+6ZY1uOke8qHaqGeq+2D8zs7NtR6BvGMwP/6+lGRgAHRVB4E4WLhpoUQI3dMZFDo zsEk8EMRQA+OXfDm+cCAu8rtaCYJ1ZkUHvlQl6wG31jlKDqfzuEQGWzujlmuau9u3+D2 Mj9A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3e5s/DFErOKmPmfRIJ0oKhmlxoutztadGSeWOTnnr7E=; b=Zwg5jlNR0jRLsQMg8ffRgRFEsp3t2D8adSeicjR0lTEuvU/+6L8W+eqpgl0MsFjkis qRZsim2VR0qjTOPPQEIgoZjRTBv9oaUpCXZbSo9VCe2Fc6t++tn9JKUDEuhfcWWocDow /9+E9pU+EY6VvZDqpTJjFDR9mD07PZTyPxV40eEWpCl0O5G7UdAUgMitfdJZxG3isNkv VKX+tUXt8SEFaRrdOOFBB2ibl23RQB6BjjX/MIsb2XepiywPrQ00F4mkz/+ZWDYkFp0V N1bYcuMsBEeWODIs+dLm6O4JMkcWzsBVsmC+3yT3WsL76AIf8S7tVH7kbJ12YskwmFHm eKQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vNCYxsOs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ck7si5907377ejb.250.2019.09.29.10.42.22; Sun, 29 Sep 2019 10:42:46 -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=vNCYxsOs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729722AbfI2RkU (ORCPT + 99 others); Sun, 29 Sep 2019 13:40:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:47012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730476AbfI2Rey (ORCPT ); Sun, 29 Sep 2019 13:34:54 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 21CBD2196E; Sun, 29 Sep 2019 17:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569778493; bh=SZIa8j9CJhCBRyj+SHTyx1EHRbuknY5E3dcb6CrkBkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vNCYxsOsSScyb6Uw2aIL/ruI8eQQ/HqNmRHsCzHHj4ju0/h/T2Kjr4rXaDjUZTDpY JcqIOGZMpO4PDuCBH0QXtkOsldyLr0xAjX9I3ZaOLYJuBUY31xDajBRV+kUyVbPvrO dP8iyxzbp788QZyXIpe5eJjvbgy51vEUOQ37+oTc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Biwen Li , Alexandre Belloni , Sasha Levin , linux-rtc@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 15/33] rtc: pcf85363/pcf85263: fix regmap error in set_time Date: Sun, 29 Sep 2019 13:34:03 -0400 Message-Id: <20190929173424.9361-15-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190929173424.9361-1-sashal@kernel.org> References: <20190929173424.9361-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 c04a1edcd5716..c3702684b3426 100644 --- a/drivers/rtc/rtc-pcf85363.c +++ b/drivers/rtc/rtc-pcf85363.c @@ -169,7 +169,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