From patchwork Tue Sep 22 18:15:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herton Ronaldo Krzesinski X-Patchwork-Id: 34093 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-vw0-f156.google.com (mail-vw0-f156.google.com [209.85.212.156]) by ozlabs.org (Postfix) with ESMTP id EC1A9B7B70 for ; Wed, 23 Sep 2009 04:15:39 +1000 (EST) Received: by vws28 with SMTP id 28so1370098vws.11 for ; Tue, 22 Sep 2009 11:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received:received-spf:received:x-virus-scanned :received:received:received:from:organization:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id:reply-to:sender:precedence :x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; bh=pcjbyRyTHhqGhTUwV/91GBC0XWccwqF4XZOd+3T1mB4=; b=kWiMxk28eOW9KhpRi6AOk6cl/SFEcKWS+0T3TafNdshQgzLxAvSNw8hPNkfnZF6C+t WQtUNIvxqQcCd9Pj7quBvSztCBYfnhN0eCf3UVFgjki5XPQdK2HtOec02jqvsk5vkqPS UsXnW7rBq+/rEpP6Lvh2C2qQSPlyOQx1jAvyo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results :x-virus-scanned:from:organization:to:subject:date:user-agent:cc :references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id:reply-to:sender:precedence :x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; b=5z+SayqlOxhQsrQ75syl1DetYEMkqNiwxzQ3kHCAKBGyzNCrC6nxO6dBxR+5oNWqVl oFfl4crZAH1COrnEpHPv5QVNo1YMWoDe+fisv7SRRZMMUGR4QB6I5mOWVIeaE3GkAcXJ huchK54mcnPH1tbGdR6m5+2WgCYYxfw0Wa6m8= Received: by 10.220.68.68 with SMTP id u4mr258324vci.25.1253643336853; Tue, 22 Sep 2009 11:15:36 -0700 (PDT) Received: by 10.230.9.105 with SMTP id k41gr2883vbk.0; Tue, 22 Sep 2009 11:15:36 -0700 (PDT) X-Sender: herton@mandriva.com.br X-Apparently-To: rtc-linux@googlegroups.com Received: by 10.220.11.134 with SMTP id t6mr474413vct.20.1253643335549; Tue, 22 Sep 2009 11:15:35 -0700 (PDT) Received: by 10.220.11.134 with SMTP id t6mr474409vct.20.1253643335455; Tue, 22 Sep 2009 11:15:35 -0700 (PDT) Received: from perninha.conectiva.com.br (perninha.conectiva.com.br [200.140.247.100]) by gmr-mx.google.com with ESMTP id 11si5706gxk.10.2009.09.22.11.15.33; Tue, 22 Sep 2009 11:15:34 -0700 (PDT) Received-SPF: neutral (google.com: 200.140.247.100 is neither permitted nor denied by best guess record for domain of herton@mandriva.com.br) client-ip=200.140.247.100; Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 200.140.247.100 is neither permitted nor denied by best guess record for domain of herton@mandriva.com.br) smtp.mail=herton@mandriva.com.br Received: from localhost (perninha.conectiva.com.br [127.0.0.1]) by perninha.conectiva.com.br (Postfix) with ESMTP id 3B5302EE4F; Tue, 22 Sep 2009 14:15:35 -0400 (EDT) X-Virus-Scanned: amavisd-new at conectiva.com.br Received: from perninha.conectiva.com.br ([127.0.0.1]) by localhost (perninha.conectiva.com.br [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 0LsbahKOXEPb; Tue, 22 Sep 2009 14:15:34 -0400 (EDT) Received: from fox.conectiva (fox.conectiva [10.0.2.195]) by perninha.conectiva.com.br (Postfix) with ESMTP id 5D3CB2EE48; Tue, 22 Sep 2009 14:15:29 -0400 (EDT) Received: from gotham.conectiva (gotham.conectiva [10.0.2.23]) by fox.conectiva (Postfix) with ESMTP id 0A39A2F0E5; Tue, 22 Sep 2009 15:15:26 -0300 (BRT) From: Herton Ronaldo Krzesinski Organization: Mandriva To: Alessandro Zummo Subject: [rtc-linux] Re: rtc_cmos oops in cmos_rtc_ioctl Date: Tue, 22 Sep 2009 15:15:26 -0300 User-Agent: KMail/1.12.1 (Linux/2.6.31-desktop-2mnb; KDE/4.3.1; i686; ; ) Cc: linux-kernel@vger.kernel.org, David Brownell , rtc-linux@googlegroups.com References: <200909211553.38409.herton@mandriva.com.br> <20090922124041.62abee25@i1501.lan.towertech.it> In-Reply-To: <20090922124041.62abee25@i1501.lan.towertech.it> Mime-Version: 1.0 Message-Id: <200909221515.26777.herton@mandriva.com.br> Reply-To: rtc-linux@googlegroups.com Sender: rtc-linux@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rtc-linux@googlegroups.com; contact rtc-linux+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rtc-linux@googlegroups.com X-BeenThere: rtc-linux@googlegroups.com Em Ter 22 Set 2009, às 07:40:41, Alessandro Zummo escreveu: > On Mon, 21 Sep 2009 15:53:38 -0300 > Herton Ronaldo Krzesinski wrote: > > > The problem here is the rtc char device being created early and acessible before > > rtc_cmos does dev_set_drvdata(dev, &cmos_rtc), so dev_get_drvdata in > > cmos_rtc_ioctl can return null, like in this example where hwclock is run right > > after char device creation that triggers the udev rule: > > ACTION=="add", SUBSYSTEM=="rtc", RUN+="/sbin/hwclock --hctosys --rtc=/dev/%k" > > And makes the oops possible, in this case hwclock looks to open and close the > > device fast enough. > > right. the best option would be to use the new irq api that was > introduced after the creation of rtc_cmos (and thus remove the whole > ioctl routine). > > [...] Something like this?: From a94365843ab40a1904c4bc244af4e551f2f2aca9 Mon Sep 17 00:00:00 2001 From: Herton Ronaldo Krzesinski Date: Tue, 22 Sep 2009 13:46:00 -0300 Subject: [PATCH] rtc-cmos: convert RTC_AIE/RTC_UIE to rtc irq API Drop ioctl function that handles RTC_AIE/RTC_UIE, and use instead the rtc subsystem API (alarm_irq_enable/update_irq_enable callbacks). Signed-off-by: Herton Ronaldo Krzesinski --- drivers/rtc/rtc-cmos.c | 75 ++++++++++++++++++++++------------------------- 1 files changed, 35 insertions(+), 40 deletions(-) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index f7a4701..a472242 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -420,49 +420,43 @@ static int cmos_irq_set_state(struct device *dev, int enabled) return 0; } -#if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE) - -static int -cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) +static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled) { struct cmos_rtc *cmos = dev_get_drvdata(dev); unsigned long flags; - switch (cmd) { - case RTC_AIE_OFF: - case RTC_AIE_ON: - case RTC_UIE_OFF: - case RTC_UIE_ON: - if (!is_valid_irq(cmos->irq)) - return -EINVAL; - break; - /* PIE ON/OFF is handled by cmos_irq_set_state() */ - default: - return -ENOIOCTLCMD; - } + if (!is_valid_irq(cmos->irq)) + return -EINVAL; spin_lock_irqsave(&rtc_lock, flags); - switch (cmd) { - case RTC_AIE_OFF: /* alarm off */ - cmos_irq_disable(cmos, RTC_AIE); - break; - case RTC_AIE_ON: /* alarm on */ + + if (enabled) cmos_irq_enable(cmos, RTC_AIE); - break; - case RTC_UIE_OFF: /* update off */ - cmos_irq_disable(cmos, RTC_UIE); - break; - case RTC_UIE_ON: /* update on */ - cmos_irq_enable(cmos, RTC_UIE); - break; - } + else + cmos_irq_disable(cmos, RTC_AIE); + spin_unlock_irqrestore(&rtc_lock, flags); return 0; } -#else -#define cmos_rtc_ioctl NULL -#endif +static int cmos_update_irq_enable(struct device *dev, unsigned int enabled) +{ + struct cmos_rtc *cmos = dev_get_drvdata(dev); + unsigned long flags; + + if (!is_valid_irq(cmos->irq)) + return -EINVAL; + + spin_lock_irqsave(&rtc_lock, flags); + + if (enabled) + cmos_irq_enable(cmos, RTC_UIE); + else + cmos_irq_disable(cmos, RTC_UIE); + + spin_unlock_irqrestore(&rtc_lock, flags); + return 0; +} #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) @@ -503,14 +497,15 @@ static int cmos_procfs(struct device *dev, struct seq_file *seq) #endif static const struct rtc_class_ops cmos_rtc_ops = { - .ioctl = cmos_rtc_ioctl, - .read_time = cmos_read_time, - .set_time = cmos_set_time, - .read_alarm = cmos_read_alarm, - .set_alarm = cmos_set_alarm, - .proc = cmos_procfs, - .irq_set_freq = cmos_irq_set_freq, - .irq_set_state = cmos_irq_set_state, + .read_time = cmos_read_time, + .set_time = cmos_set_time, + .read_alarm = cmos_read_alarm, + .set_alarm = cmos_set_alarm, + .proc = cmos_procfs, + .irq_set_freq = cmos_irq_set_freq, + .irq_set_state = cmos_irq_set_state, + .alarm_irq_enable = cmos_alarm_irq_enable, + .update_irq_enable = cmos_update_irq_enable, }; /*----------------------------------------------------------------*/