From patchwork Tue Jul 26 19:40:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9248767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 83A59607F2 for ; Tue, 26 Jul 2016 19:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 671C4271FD for ; Tue, 26 Jul 2016 19:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B059272AA; Tue, 26 Jul 2016 19:40:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00594271FD for ; Tue, 26 Jul 2016 19:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756073AbcGZTkg (ORCPT ); Tue, 26 Jul 2016 15:40:36 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=WwmjE0sxdFjYa4+eBeWoucxYPSjRJuocOJ+AV//dosk=; b=YEKqgpZX2rsyYF/2961sAB319m3zISdx3gzu4v86CBbUXU6+LeuLdKYILjzTNIJZdA +rK/wEzkCiaRfGXQxHwY/M15Pt8/HLNqYh7OIpyDafObACi/IQt3nkP6PAtyiEAoOJjF S15SZ7Pa/nMDNKgjVj0IEnIVbldEpfZBDcboZkCknKxQbJEQ49bJqGW6zYECq0ZF8Z4g KREMAnZgxttkiNO5i9OX35RntCMRepInazm82mUhCgHa5o0DJo0rWIfj8GOZv6LmbTDr 32nw//kEODJiqieixUtyIAXoYgoTDsjxVyLXhd56bLhzfKCKZqTpFhvd6RvQt+d+9FJp Cu1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=WwmjE0sxdFjYa4+eBeWoucxYPSjRJuocOJ+AV//dosk=; b=UgwFTC+8t63uIOF9ydYLyIzLeRvJxP67kutbrxqiD3EXDORcmeeo9ZpWBdR97J6TmX yDXljyRU/ydOgS+6ctzWVtbF6pmNGKBNsKgWd7leAcyJ7HJZKxGnns1hnPOfHdbBhU/R wj6r/7vpiBN37lsO1mJT60dgKKBh3tjvjGhdX3cRcKirLLkzCeTIr3XoWJj/eFF1VdK+ y369BWPhtuqSD6HVgXIQOZTlqTRx7XNF9XFUGKKbOEd6mtu/Q6W18McQXQjpuQpHwnJf LYZX3kIHQgx2FMZSzUHwsa5lX1xrSu1scUHgjhILmGXqILQH7/wRD7qacnsXxsMZk9oq sJbA== X-Gm-Message-State: AEkoouvV4ey5Vw10lZk1sJhYt2ysByiPRMXGPK6qkClD5iN2oNjV/Yxsiqk29yZUJANtCg== X-Received: by 10.194.123.228 with SMTP id md4mr21653394wjb.91.1469562033799; Tue, 26 Jul 2016 12:40:33 -0700 (PDT) Received: from ?IPv6:2003:62:5f01:4400:fd2f:d963:36b:6ec9? (p200300625F014400FD2FD963036B6EC9.dip0.t-ipconnect.de. [2003:62:5f01:4400:fd2f:d963:36b:6ec9]) by smtp.googlemail.com with ESMTPSA id he3sm2523752wjc.6.2016.07.26.12.40.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jul 2016 12:40:33 -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 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); } /*