Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933194AbdDGLfA (ORCPT ); Fri, 7 Apr 2017 07:35:00 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:36745 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932165AbdDGLew (ORCPT ); Fri, 7 Apr 2017 07:34:52 -0400 Message-ID: <58e77955.09c3620a.bb125.3e20@mx.google.com> X-Google-Original-Message-ID: <20170407113441.GA2845@> Date: Fri, 7 Apr 2017 17:04:41 +0530 From: Varsha Rao To: Matthew Wilcox , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator. References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1823 Lines: 63 Replace bit operation functions with IDA allocator functions. As IDA allocation is simpler. Signed-off-by: Varsha Rao --- drivers/char/misc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/char/misc.c b/drivers/char/misc.c index c9cd1ea..5786281 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -60,7 +60,7 @@ static DEFINE_MUTEX(misc_mtx); * Assigned numbers, used for dynamic minors */ #define DYNAMIC_MINORS 64 /* like dynamic majors */ -static DECLARE_BITMAP(misc_minors, DYNAMIC_MINORS); +static DEFINE_IDA(misc_minors_ida); #ifdef CONFIG_PROC_FS static void *misc_seq_start(struct seq_file *seq, loff_t *pos) @@ -193,14 +193,18 @@ int misc_register(struct miscdevice *misc) mutex_lock(&misc_mtx); if (is_dynamic) { - int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS); + int i = ida_simple_get(&misc_minors_ida, 0, + DYNAMIC_MINORS, GFP_KERNEL); if (i >= DYNAMIC_MINORS) { err = -EBUSY; goto out; - } + } else if (i < 0) { + err = i; + goto out; + } else { misc->minor = DYNAMIC_MINORS - i - 1; - set_bit(i, misc_minors); + } } else { struct miscdevice *c; @@ -222,7 +226,7 @@ int misc_register(struct miscdevice *misc) int i = DYNAMIC_MINORS - misc->minor - 1; if (i < DYNAMIC_MINORS && i >= 0) - clear_bit(i, misc_minors); + ida_simple_remove(&misc_minors_ida, i); misc->minor = MISC_DYNAMIC_MINOR; } err = PTR_ERR(misc->this_device); @@ -258,7 +262,7 @@ void misc_deregister(struct miscdevice *misc) list_del(&misc->list); device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); if (i < DYNAMIC_MINORS && i >= 0) - clear_bit(i, misc_minors); + ida_simple_remove(&misc_minors_ida, i); mutex_unlock(&misc_mtx); } -- 2.9.3