From patchwork Sun Jun 6 12:42:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wan ZongShun X-Patchwork-Id: 54817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-px0-f184.google.com (mail-px0-f184.google.com [209.85.212.184]) by ozlabs.org (Postfix) with ESMTP id 9AA6EB7D65 for ; Sun, 6 Jun 2010 22:43:00 +1000 (EST) Received: by pxi15 with SMTP id 15sf476487pxi.11 for ; Sun, 06 Jun 2010 05:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:received:received:message-id:date :from:user-agent:mime-version:to:subject :x-original-authentication-results:x-original-sender:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type; bh=6LQUtcz2MDsUno7S/2lw+1NZuYo5bGmb5UyHHoI1YFQ=; b=pAby72Q2mE1NVNA2/UrtoaQTr9hpK1SZdfvLt+Qk0qJlcy9TTu91yjs8ZEgYtrpY2v xhZI/38NBRJdlM5C7/ajctaOzOebikY5uBb+bG/+XVFTdLwUUvRTJpesTAWIQ/57lQmj JjP6Y8G/CLvsT8m24XaJ4c9Gqe5OOv8fMjY54= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:message-id:date:from:user-agent :mime-version:to:subject:x-original-authentication-results :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; b=bQMVjPvi5K6y24tBZCriSrjYm5GSgO8OA6FaEDvW1XRtojBxvFHTJ8PCjT6Ae/itdP UaHi8RRMKPQB5Kssn/0PDuQPSNTPglgJzZ+ev0MSjoH+tLnfOpxLZuZFfnguXcK4L5xe Xd3xhHcGTLU6tD5zvIvHIr7xvmc7oOQuur+Go= Received: by 10.141.124.10 with SMTP id b10mr1161100rvn.0.1275828179386; Sun, 06 Jun 2010 05:42:59 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.141.187.12 with SMTP id o12ls6278939rvp.0.p; Sun, 06 Jun 2010 05:42:58 -0700 (PDT) Received: by 10.141.124.13 with SMTP id b13mr85304rvn.8.1275828178919; Sun, 06 Jun 2010 05:42:58 -0700 (PDT) Received: by 10.141.124.13 with SMTP id b13mr85302rvn.8.1275828178719; Sun, 06 Jun 2010 05:42:58 -0700 (PDT) Received: from mail-pz0-f174.google.com (mail-pz0-f174.google.com [209.85.222.174]) by gmr-mx.google.com with ESMTP id 24si529222pzk.9.2010.06.06.05.42.57; Sun, 06 Jun 2010 05:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of mcuos.com@gmail.com designates 209.85.222.174 as permitted sender) client-ip=209.85.222.174; Received: by pzk4 with SMTP id 4so1569485pzk.7 for ; Sun, 06 Jun 2010 05:42:57 -0700 (PDT) Received: by 10.114.187.11 with SMTP id k11mr10494626waf.153.1275828176945; Sun, 06 Jun 2010 05:42:56 -0700 (PDT) Received: from [192.168.1.3] ([114.95.211.215]) by mx.google.com with ESMTPS id n29sm28570672wae.16.2010.06.06.05.42.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 06 Jun 2010 05:42:55 -0700 (PDT) Message-ID: <4C0B97C0.4010504@gmail.com> Date: Sun, 06 Jun 2010 20:42:40 +0800 From: Wan ZongShun User-Agent: Thunderbird 2.0.0.24 (X11/20100411) MIME-Version: 1.0 To: Andrew Morton , Alessandro Zummo , rtc-linux , LKML Subject: [rtc-linux] [PATCH] rtc/nuc900: patch for tm_year to add 'if' condition. X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of mcuos.com@gmail.com designates 209.85.222.174 as permitted sender) smtp.mail=mcuos.com@gmail.com; dkim=pass (test mode) header.i=@gmail.com X-Original-Sender: mcuos.com@gmail.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Andrew, When user application wants to set rtc time, RTC subsystem takes advantage of 'rtc_valid_tm(tm)' to check 'rtc_time *tm' value validity, it make sure the 'tm->tm_year' is larger than 70,so if '70< tm_year < 100', the '(settm->tm_year - 100)' will be negative. ' Setting the negative value to hardware register will be invalid, so I add the 'if' condition to make sure set a valid value to register. Signed-off-by: Wan ZongShun --- drivers/rtc/rtc-nuc900.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c index 21d1330..20bc70b 100644 --- a/drivers/rtc/rtc-nuc900.c +++ b/drivers/rtc/rtc-nuc900.c @@ -116,12 +116,18 @@ static void nuc900_rtc_bcd2bin(unsigned int timereg, rtc_valid_tm(tm); } -static void nuc900_rtc_bin2bcd(struct rtc_time *settm, +static void nuc900_rtc_bin2bcd(struct device *dev, struct rtc_time *settm, struct nuc900_bcd_time *gettm) { gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0; gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8; - gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16; + + if (settm->tm_year < 100) { + dev_warn(dev, "The year will be between 1970-1999, right?\n"); + gettm->bcd_year = bin2bcd(settm->tm_year) << 16; + } else { + gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16; + } gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0; gettm->bcd_min = bin2bcd(settm->tm_min) << 8; @@ -176,7 +182,7 @@ static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm) unsigned long val; int *err; - nuc900_rtc_bin2bcd(tm, &gettm); + nuc900_rtc_bin2bcd(dev, tm, &gettm); err = check_rtc_access_enable(rtc); if (IS_ERR(err)) @@ -211,7 +217,7 @@ static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) unsigned long val; int *err; - nuc900_rtc_bin2bcd(&alrm->time, &tm); + nuc900_rtc_bin2bcd(dev, &alrm->time, &tm); err = check_rtc_access_enable(rtc); if (IS_ERR(err))