From patchwork Mon Feb 29 15:13:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 589997 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-vk0-x239.google.com (mail-vk0-x239.google.com [IPv6:2607:f8b0:400c:c05::239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9531B140770 for ; Tue, 1 Mar 2016 02:14:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=ggxV/Io+; dkim-atps=neutral Received: by mail-vk0-x239.google.com with SMTP id e6sf30152656vkh.1 for ; Mon, 29 Feb 2016 07:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references: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=ms+hWG0yaEwpq2BxPhHWnafVTldQv265I3l6egAd7tc=; b=ggxV/Io+xEX/fEy59EJvYv7RgI0hz5F298+WLcpTkKrBDOvavBkdUK8oTa1purTObw jOPRVJamvPhBI/UgoKaexrkZJiTf+C7TPR8r2sU2kUinNkU+3dh5mLrudiKCw7rp17gx YDG1hOHTvQIpv7+gbyRp8TtJzt8e3xalbjdnxrkjrPssWdOKAZFlgj4anCr5pWttHkHB KKvhnQDLWunKtwC0r5qiLJqBoKsSvJ24wjvpXIIboQ7FWFWHcza9TQyN80tidmWGnN0l B6u+x0R5x/GfbzShxZvIYiOjeqW9eQ+AkwePX394+ssZVowOUTMn1Ju6Ryl+k6aYaqa9 w36w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references: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=ms+hWG0yaEwpq2BxPhHWnafVTldQv265I3l6egAd7tc=; b=fd0dq68VKIbpMExqvlNoMq5sGQbtxi72lXZ73EME9lvDpuwRV7yoUsekv1N4iqoRfz I/KMOgjnzhM/HJNexOABHVJEi3zB6K2Cl1gRAgunPkIgfAHb21tM4/1xCH9jJSs3jpcy wUxCbW2x9JAVvDci+gR8d9x6fpqipcE6ld+fOvPLa0n0TSoxN28kC+4dXeTtnHU93yOG L0bLXQ64Ch/3ODiwh3H2IguNiX+P0rSEeUlduDvNoc726xiHQIr0oM8Y9P3p7LljpU4r SDvkfTsFZc8P9/QG95z08sot4fjYrLPf3H2m9fgkQhbPb4BswkjupUbLyVr22veVsCTJ ieXw== X-Gm-Message-State: AD7BkJJeuUqnXmhtunNjhE1rtIZbVEtXJgLUpi6vqTEKla2k15HkoZEbGypiAILY0K+p+A== X-Received: by 10.140.42.197 with SMTP id c63mr299462qga.5.1456758862618; Mon, 29 Feb 2016 07:14:22 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.140.99.18 with SMTP id p18ls2520839qge.86.gmail; Mon, 29 Feb 2016 07:14:22 -0800 (PST) X-Received: by 10.140.30.99 with SMTP id c90mr29945049qgc.2.1456758862209; Mon, 29 Feb 2016 07:14:22 -0800 (PST) Received: from mail-pa0-x236.google.com (mail-pa0-x236.google.com. [2607:f8b0:400e:c03::236]) by gmr-mx.google.com with ESMTPS id r75si2050666pfr.0.2016.02.29.07.14.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Feb 2016 07:14:22 -0800 (PST) Received-SPF: pass (google.com: domain of akinobu.mita@gmail.com designates 2607:f8b0:400e:c03::236 as permitted sender) client-ip=2607:f8b0:400e:c03::236; Received: by mail-pa0-x236.google.com with SMTP id yy13so93445657pab.3 for ; Mon, 29 Feb 2016 07:14:22 -0800 (PST) X-Received: by 10.66.90.136 with SMTP id bw8mr22580396pab.52.1456758861905; Mon, 29 Feb 2016 07:14:21 -0800 (PST) Received: from localhost.localdomain (KD113159139091.ppp-bb.dion.ne.jp. [113.159.139.91]) by smtp.gmail.com with ESMTPSA id g10sm38866329pfd.92.2016.02.29.07.14.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Feb 2016 07:14:20 -0800 (PST) From: Akinobu Mita To: rtc-linux@googlegroups.com Cc: Akinobu Mita , Alessandro Zummo , Alexandre Belloni , Dennis Aberilla Subject: [rtc-linux] [PATCH v3 4/8] rtc: ds3232-core: fix read on /dev/rtc after RTC_AIE_ON Date: Tue, 1 Mar 2016 00:13:48 +0900 Message-Id: <1456758832-10590-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456758832-10590-1-git-send-email-akinobu.mita@gmail.com> References: <1456758832-10590-1-git-send-email-akinobu.mita@gmail.com> X-Original-Sender: Akinobu.Mita@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of akinobu.mita@gmail.com designates 2607:f8b0:400e:c03::236 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com; dkim=pass header.i=@gmail.com; dmarc=pass (p=NONE dis=NONE) header.from=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: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , The rtctest (tools/testing/selftests/timers/rtctest.c) found that reading ds3232 rtc device immediately return the value 0x20 (RTC_AF) without waiting alarm interrupt. This is because alarm_irq_enable() of ds3232 driver changes RTC_AF flag in rtc->irq_data. So calling ioctl with RTC_AIE_ON generates invalid value in rtc device. The lower-level driver should not touch rtc->irq_data directly. Signed-off-by: Akinobu Mita Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: Dennis Aberilla --- * No changes since v1 drivers/rtc/rtc-ds3232-core.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-ds3232-core.c b/drivers/rtc/rtc-ds3232-core.c index d44c84e..7de30b3 100644 --- a/drivers/rtc/rtc-ds3232-core.c +++ b/drivers/rtc/rtc-ds3232-core.c @@ -271,7 +271,7 @@ out: return ret; } -static void ds3232_update_alarm(struct device *dev) +static void ds3232_update_alarm(struct device *dev, unsigned int enabled) { struct ds3232 *ds3232 = dev_get_drvdata(dev); int control; @@ -301,7 +301,7 @@ static void ds3232_update_alarm(struct device *dev) if (ret) goto unlock; - if (ds3232->rtc->irq_data & (RTC_AF | RTC_UF)) + if (enabled || (ds3232->rtc->irq_data & RTC_UF)) /* enable alarm1 interrupt */ control |= DS3232_REG_CR_A1IE; else @@ -320,12 +320,8 @@ static int ds3232_alarm_irq_enable(struct device *dev, unsigned int enabled) if (ds3232->irq <= 0) return -EINVAL; - if (enabled) - ds3232->rtc->irq_data |= RTC_AF; - else - ds3232->rtc->irq_data &= ~RTC_AF; + ds3232_update_alarm(dev, enabled); - ds3232_update_alarm(dev); return 0; }