From patchwork Fri Jul 22 16:41:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 106333 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ww0-f56.google.com (mail-ww0-f56.google.com [74.125.82.56]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id B5CFEB6F71 for ; Sat, 23 Jul 2011 02:41:35 +1000 (EST) Received: by wwf22 with SMTP id 22sf4102662wwf.11 for ; Fri, 22 Jul 2011 09:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:x-cam-antivirus :x-cam-spamdetails:x-cam-scannerinfo:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=g1V1mnv7JeOlOd0q7RPRrI/C+uziZ8ZVO97pmfu8ckA=; b=r6opukGAzr+G5Vyz878GatpPfrVn2I/K3iLNqnXPuD4VKQuCksZv/6hgrY0Ed4ERf2 QwrL4h0hKcxmNCwZ6mtWix+JzRwumv3hrAba3w5y0/GonZNcYlUOBPXDSvh3+o9GT21/ EIFrJw51cY4p0DQiZvOOWH+T9V7hmomW9dr/c= Received: by 10.216.9.147 with SMTP id 19mr771385wet.16.1311352890217; Fri, 22 Jul 2011 09:41:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.217.6.11 with SMTP id x11ls529799wes.3.gmail; Fri, 22 Jul 2011 09:41:29 -0700 (PDT) Received: by 10.216.64.140 with SMTP id c12mr109695wed.14.1311352889370; Fri, 22 Jul 2011 09:41:29 -0700 (PDT) Received: by 10.216.64.140 with SMTP id c12mr109694wed.14.1311352889353; Fri, 22 Jul 2011 09:41:29 -0700 (PDT) Received: from ppsw-51.csi.cam.ac.uk (ppsw-51.csi.cam.ac.uk [131.111.8.151]) by gmr-mx.google.com with ESMTP id c25si2631198wbp.1.2011.07.22.09.41.29; Fri, 22 Jul 2011 09:41:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of jic23@cam.ac.uk designates 131.111.8.151 as permitted sender) client-ip=131.111.8.151; X-Cam-AntiVirus: no malware found X-Cam-SpamDetails: not scanned X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from arcturus.eng.cam.ac.uk ([129.169.154.73]:58777 helo=localhost.eng.cam.ac.uk) by ppsw-51.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.158]:465) with esmtpsa (LOGIN:jic23) (TLSv1:DHE-RSA-AES256-SHA:256) id 1QkImz-0004Oy-XB (Exim 4.72) (return-path ); Fri, 22 Jul 2011 17:41:25 +0100 From: Jonathan Cameron To: linux-kernel@vger.kernel.org Cc: lm-sensors@lm-sensors.org, rtc-linux@googlegroups.com, osd-dev@open-osd.org, linux-scsi@vger.kernel.org, dri-devel@lists.freedesktop.org, jkosina@suse.cz, naota@elisp.net, rusty@rustcorp.com.au, paulmck@linux.vnet.ibm.com, namhyung@gmail.com, randy.dunlap@oracle.com, tj@kernel.org, cabarnes@indesign-llc.com, akpm@linux-foundation.org, airlied@redhat.com, thellstrom@vmware.com, johnpol@2ka.mipt.ru, JBottomley@parallels.com, bhalevy@panasas.com, bharrosh@panasas.com, a.zummo@towertech.it, guenter.roeck@ericsson.com, khali@linux-fr.org, airlied@linux.ie, Jonathan Cameron Subject: [rtc-linux] [PATCH 8/8] rtc: class idr converted to ida and ida_simple_get used. Date: Fri, 22 Jul 2011 17:41:26 +0100 Message-Id: <1311352886-4047-18-git-send-email-jic23@cam.ac.uk> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1311352886-4047-1-git-send-email-jic23@cam.ac.uk> References: <1311352886-4047-1-git-send-email-jic23@cam.ac.uk> X-Original-Sender: jic23@cam.ac.uk X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of jic23@cam.ac.uk designates 131.111.8.151 as permitted sender) smtp.mail=jic23@cam.ac.uk Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , This is the one use of an ida that doesn't retry on receiving -EAGAIN. I'm assuming do so will cause no harm and may help on a rare occasion. Signed-off-by: Jonathan Cameron --- drivers/rtc/class.c | 32 +++++++++----------------------- 1 files changed, 9 insertions(+), 23 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 4194e59..68ae46f 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -21,16 +21,13 @@ #include "rtc-core.h" -static DEFINE_IDR(rtc_idr); -static DEFINE_MUTEX(idr_lock); +static DEFINE_IDA(rtc_ida); struct class *rtc_class; static void rtc_device_release(struct device *dev) { struct rtc_device *rtc = to_rtc_device(dev); - mutex_lock(&idr_lock); - idr_remove(&rtc_idr, rtc->id); - mutex_unlock(&idr_lock); + ida_simple_remove(&rtc_ida, rtc->id); kfree(rtc); } @@ -115,25 +112,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, struct rtc_wkalrm alrm; int id, err; - if (idr_pre_get(&rtc_idr, GFP_KERNEL) == 0) { - err = -ENOMEM; + id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); + if (id < 0) { + err = id; goto exit; } - - mutex_lock(&idr_lock); - err = idr_get_new(&rtc_idr, NULL, &id); - mutex_unlock(&idr_lock); - - if (err < 0) - goto exit; - - id = id & MAX_ID_MASK; - rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL); if (rtc == NULL) { err = -ENOMEM; - goto exit_idr; + goto exit_ida; } rtc->id = id; @@ -191,10 +179,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, exit_kfree: kfree(rtc); -exit_idr: - mutex_lock(&idr_lock); - idr_remove(&rtc_idr, id); - mutex_unlock(&idr_lock); +exit_ida: + ida_simple_remove(&rtc_ida, id); exit: dev_err(dev, "rtc core: unable to register %s, err = %d\n", @@ -245,7 +231,7 @@ static void __exit rtc_exit(void) { rtc_dev_exit(); class_destroy(rtc_class); - idr_destroy(&rtc_idr); + ida_destroy(&rtc_ida); } subsys_initcall(rtc_init);