From: Varsha Rao <rvarsha016@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Matthew Wilcox <mawilcox@microsoft.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] drivers: char: Replace bit operation functions with IDA allocator.
Date: Mon, 10 Apr 2017 12:28:59 +0530 [thread overview]
Message-ID: <58eb2d3c.e43aed0a.e6c99.eed5@mx.google.com> (raw)
In-Reply-To: <cover.1491806760.git.rvarsha016@gmail.com>
Replace bit operation functions with IDA allocator functions. As IDA
allocation is simpler, faster, more space efficient and it generates
small integer IDs which can be used as minor device numbers.
Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
---
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
next parent reply other threads:[~2017-04-10 6:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1491806760.git.rvarsha016@gmail.com>
2017-04-10 6:58 ` Varsha Rao [this message]
2017-04-10 13:45 ` [PATCH 1/2] drivers: char: Replace bit operation functions with IDA allocator Greg Kroah-Hartman
2017-04-10 6:59 ` [PATCH 2/2] drivers: char: Replace fail_printk with fail_print Varsha Rao
2017-04-10 13:43 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58eb2d3c.e43aed0a.e6c99.eed5@mx.google.com \
--to=rvarsha016@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mawilcox@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox