From patchwork Thu Jun 23 14:31:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Guinot X-Patchwork-Id: 908992 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5NEY8Ye018502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 23 Jun 2011 14:34:29 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QZkyg-00089Z-Ty; Thu, 23 Jun 2011 14:33:55 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QZkyg-0005y8-Iu; Thu, 23 Jun 2011 14:33:54 +0000 Received: from ns39351.ovh.net ([91.121.21.191]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QZkyc-0005xo-R7 for linux-arm-kernel@lists.infradead.org; Thu, 23 Jun 2011 14:33:51 +0000 Received: from localhost (87-98-128-90.ovh.net [87.98.128.90]) by ns39351.ovh.net (Postfix) with ESMTPSA id 12D5424DCC; Thu, 23 Jun 2011 16:33:39 +0200 (CEST) From: Simon Guinot To: Saeed Bishara , Nicolas Pitre Subject: [PATCH] rtc-mv: add check for valid year range Date: Thu, 23 Jun 2011 16:31:25 +0200 Message-Id: <1308839485-20116-1-git-send-email-simon@sequanux.org> X-Mailer: git-send-email 1.7.5.1 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110623_103351_012429_0075631B X-CRM114-Status: GOOD ( 10.19 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- Cc: Alessandro Zummo , linux-arm-kernel@lists.infradead.org, Simon Guinot X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 23 Jun 2011 14:34:29 +0000 (UTC) From: Simon Guinot Return -EINVAL when trying to set the RTC time with a date out of the 21th century. The on-chip RTC don't support such dates. Signed-off-by: Simon Guinot --- drivers/rtc/rtc-mv.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c index 60627a7..4a4b6c9 100644 --- a/drivers/rtc/rtc-mv.c +++ b/drivers/rtc/rtc-mv.c @@ -47,6 +47,9 @@ static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm) void __iomem *ioaddr = pdata->ioaddr; u32 rtc_reg; + if (tm->tm_year < 100 || tm->tm_year > 199) + return -EINVAL; + rtc_reg = (bin2bcd(tm->tm_sec) << RTC_SECONDS_OFFS) | (bin2bcd(tm->tm_min) << RTC_MINUTES_OFFS) | (bin2bcd(tm->tm_hour) << RTC_HOURS_OFFS) | @@ -55,7 +58,7 @@ static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm) rtc_reg = (bin2bcd(tm->tm_mday) << RTC_MDAY_OFFS) | (bin2bcd(tm->tm_mon + 1) << RTC_MONTH_OFFS) | - (bin2bcd(tm->tm_year % 100) << RTC_YEAR_OFFS); + (bin2bcd(tm->tm_year - 100) << RTC_YEAR_OFFS); writel(rtc_reg, ioaddr + RTC_DATE_REG_OFFS); return 0;