From patchwork Fri Nov 6 16:37:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 541037 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-lb0-x240.google.com (mail-lb0-x240.google.com [IPv6:2a00:1450:4010:c04::240]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E54111402B4 for ; Sat, 7 Nov 2015 03:38:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=B/i1BCA8; dkim-atps=neutral Received: by lblw10 with SMTP id w10sf1730135lbl.0 for ; Fri, 06 Nov 2015 08:38:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe; bh=0eGEyJtYea4nIb9IFN+0ngKGnxz1KUA21Cg3FEJj3B8=; b=B/i1BCA8z4frCHvo1jVYJVMqc9vzSbVohe42nt5SMCPKmcGNN3zDT38nIgFpLCkvUc I9HBBVVjJ8NhJg/5yjp8LnB/GAwNYZJqjM/ZbToZbumgGNKKBl4n0qZ8xP1dDKbFJkd9 SGHhLhZ1cjJ9R4n+kByek5IxqIZGZUvbZbN8zonhThdKNMH3xCqAD6oqu1yRum7MWrnB VgE+psFb3VCdbg1I0LK+U7fN1HmLc51JOBo/XrpT2ZM2myVtSVJuFN/rqrtRYpGWn9Sk P67+gXsXcdn3sX2w4yekOXzo9s9njPQtxilvy1B4njGM5KNVlJD7ZjWKQ3vpaGdFlQ6k Kkow== X-Received: by 10.25.89.207 with SMTP id n198mr201177lfb.16.1446827882207; Fri, 06 Nov 2015 08:38:02 -0800 (PST) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.25.10.206 with SMTP id 197ls264288lfk.33.gmail; Fri, 06 Nov 2015 08:38:01 -0800 (PST) X-Received: by 10.112.145.201 with SMTP id sw9mr2881446lbb.13.1446827881403; Fri, 06 Nov 2015 08:38:01 -0800 (PST) Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de. [2001:67c:670:201:290:27ff:fe1d:cc33]) by gmr-mx.google.com with ESMTPS id s134si157486wmb.3.2015.11.06.08.38.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 06 Nov 2015 08:38:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of ukl@pengutronix.de designates 2001:67c:670:201:290:27ff:fe1d:cc33 as permitted sender) client-ip=2001:67c:670:201:290:27ff:fe1d:cc33; Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Zuk1X-0001X9-Ro; Fri, 06 Nov 2015 17:37:59 +0100 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.86) (envelope-from ) id 1Zuk1W-0008MJ-FM; Fri, 06 Nov 2015 17:37:58 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Alessandro Zummo , Alexandre Belloni Cc: rtc-linux@googlegroups.com, kernel@pengutronix.de Subject: [rtc-linux] [PATCH] rtc: pcf8523: refuse to write dates later than 2099 Date: Fri, 6 Nov 2015 17:37:56 +0100 Message-Id: <1446827876-31613-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.6.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: rtc-linux@googlegroups.com X-Original-Sender: u.kleine-koenig@pengutronix.de X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of ukl@pengutronix.de designates 2001:67c:670:201:290:27ff:fe1d:cc33 as permitted sender) smtp.mailfrom=ukl@pengutronix.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , When the chip increments the YEAR register and it already holds bin2bcd(99) it reads as 0 afterwards. With this behaviour the last valid day (without trickery) that has a representation is 2099-12-31 23:59:59. So refuse to write later dates. Signed-off-by: Uwe Kleine-König --- Hello, When setting the YEAR register to bin2bcd(100) == 0xa0 it increments just fine up to bin2bcd(159) == 0xf9 but these values are forbidden in the manual. But this doesn't help to expand (or shift) the range of supported dates. An alternative to this patch would be to save tm_year % 100 because that's what happens when waiting long enough anyhow. Would that be better? Do we already care at all for year-2100-problems? Best regards Uwe drivers/rtc/rtc-pcf8523.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c index 4cdb64be061b..261d65e67c8b 100644 --- a/drivers/rtc/rtc-pcf8523.c +++ b/drivers/rtc/rtc-pcf8523.c @@ -219,6 +219,17 @@ static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm) u8 regs[8]; int err; + /* + * The hardware can only store values between 0 and 99 in it's YEAR + * register (with 99 overflowing to 0 on increment). + * After 2100-02-28 we could start interpreting the year to be in the + * interval [2100, 2199], but there is no path to switch in a smooth way + * because the chip handles YEAR=0x00 (and the out-of-spec + * YEAR=0xa0) as a leap year, but 2100 isn't. + */ + if (tm->tm_year < 100 || tm->tm_year >= 200) + return -EINVAL; + err = pcf8523_stop_rtc(client); if (err < 0) return err;