Return-Path: Received: from mail-wm0-f65.google.com ([74.125.82.65]:35697 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752416AbcGZTkf (ORCPT ); Tue, 26 Jul 2016 15:40:35 -0400 Received: by mail-wm0-f65.google.com with SMTP id i5so3249736wmg.2 for ; Tue, 26 Jul 2016 12:40:35 -0700 (PDT) To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org From: Heiner Kallweit Subject: [PATCH] fs: proc: switch to ida_simple_get/remove Message-ID: <8d1cc9f7-5115-c9dc-028e-c0770b6bfe1f@gmail.com> Date: Tue, 26 Jul 2016 21:40:22 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: The code can be much simplified by switching to ida_simple_get/remove. Signed-off-by: Heiner Kallweit --- fs/proc/generic.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index c633476..83725d0 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -179,7 +179,6 @@ static int xlate_proc_name(const char *name, struct proc_dir_entry **ret, } static DEFINE_IDA(proc_inum_ida); -static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */ #define PROC_DYNAMIC_FIRST 0xF0000000U @@ -189,37 +188,20 @@ static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */ */ int proc_alloc_inum(unsigned int *inum) { - unsigned int i; - int error; + int i; -retry: - if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL)) - return -ENOMEM; + i = ida_simple_get(&proc_inum_ida, 0, UINT_MAX - PROC_DYNAMIC_FIRST + 1, + GFP_KERNEL); + if (i < 0) + return i; - spin_lock_irq(&proc_inum_lock); - error = ida_get_new(&proc_inum_ida, &i); - spin_unlock_irq(&proc_inum_lock); - if (error == -EAGAIN) - goto retry; - else if (error) - return error; - - if (i > UINT_MAX - PROC_DYNAMIC_FIRST) { - spin_lock_irq(&proc_inum_lock); - ida_remove(&proc_inum_ida, i); - spin_unlock_irq(&proc_inum_lock); - return -ENOSPC; - } - *inum = PROC_DYNAMIC_FIRST + i; + *inum = PROC_DYNAMIC_FIRST + (unsigned int)i; return 0; } void proc_free_inum(unsigned int inum) { - unsigned long flags; - spin_lock_irqsave(&proc_inum_lock, flags); - ida_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); - spin_unlock_irqrestore(&proc_inum_lock, flags); + ida_simple_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); } /* -- 2.9.0