All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drivers: char: Replace bit operation functions with IDA allocator.
       [not found] <cover.1491806760.git.rvarsha016@gmail.com>
@ 2017-04-10  6:58 ` Varsha Rao
  2017-04-10 13:45   ` Greg Kroah-Hartman
  2017-04-10  6:59 ` [PATCH 2/2] drivers: char: Replace fail_printk with fail_print Varsha Rao
  1 sibling, 1 reply; 4+ messages in thread
From: Varsha Rao @ 2017-04-10  6:58 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Matthew Wilcox; +Cc: linux-kernel

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] drivers: char: Replace fail_printk with fail_print.
       [not found] <cover.1491806760.git.rvarsha016@gmail.com>
  2017-04-10  6:58 ` [PATCH 1/2] drivers: char: Replace bit operation functions with IDA allocator Varsha Rao
@ 2017-04-10  6:59 ` Varsha Rao
  2017-04-10 13:43   ` Greg Kroah-Hartman
  1 sibling, 1 reply; 4+ messages in thread
From: Varsha Rao @ 2017-04-10  6:59 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Matthew Wilcox; +Cc: linux-kernel

As printk is no longer used here, rename the label fail_printk as
fail_print.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
---
 drivers/char/misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 5786281..0fed477 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -293,11 +293,11 @@ static int __init misc_init(void)
 
 	err = -EIO;
 	if (register_chrdev(MISC_MAJOR, "misc", &misc_fops))
-		goto fail_printk;
+		goto fail_print;
 	misc_class->devnode = misc_devnode;
 	return 0;
 
-fail_printk:
+fail_print:
 	pr_err("unable to get major %d for misc devices\n", MISC_MAJOR);
 	class_destroy(misc_class);
 fail_remove:
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] drivers: char: Replace fail_printk with fail_print.
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-04-10 13:43 UTC (permalink / raw)
  To: Varsha Rao; +Cc: Arnd Bergmann, Matthew Wilcox, linux-kernel

On Mon, Apr 10, 2017 at 12:29:56PM +0530, Varsha Rao wrote:
> As printk is no longer used here, rename the label fail_printk as
> fail_print.
> 
> Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
> ---
>  drivers/char/misc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index 5786281..0fed477 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -293,11 +293,11 @@ static int __init misc_init(void)
>  
>  	err = -EIO;
>  	if (register_chrdev(MISC_MAJOR, "misc", &misc_fops))
> -		goto fail_printk;
> +		goto fail_print;
>  	misc_class->devnode = misc_devnode;
>  	return 0;
>  
> -fail_printk:
> +fail_print:
>  	pr_err("unable to get major %d for misc devices\n", MISC_MAJOR);
>  	class_destroy(misc_class);

That's really a pointless change, don't you think?

sorry,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] drivers: char: Replace bit operation functions with IDA allocator.
  2017-04-10  6:58 ` [PATCH 1/2] drivers: char: Replace bit operation functions with IDA allocator Varsha Rao
@ 2017-04-10 13:45   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-04-10 13:45 UTC (permalink / raw)
  To: Varsha Rao; +Cc: Arnd Bergmann, Matthew Wilcox, linux-kernel

On Mon, Apr 10, 2017 at 12:28:59PM +0530, Varsha Rao wrote:
> 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.

The allocation is different than the bitfield searching is?  How
exactly?  What is the old result vs. the new result of this change?

How did you test this?

You have to really sell this change, right now it looks pretty
pointless...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-10 13:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1491806760.git.rvarsha016@gmail.com>
2017-04-10  6:58 ` [PATCH 1/2] drivers: char: Replace bit operation functions with IDA allocator Varsha Rao
2017-04-10 13:45   ` 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.