Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1618704 > unrolled thread

[PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator.

Started byVarsha Rao <rvarsha016@gmail.com>
First post2017-04-07 13:40 +0200
Last post2017-04-09 07:30 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 5/5] drivers: char: Replace bit operation functions with IDA  allocator. Varsha Rao <rvarsha016@gmail.com> - 2017-04-07 13:40 +0200
    Re: [PATCH 5/5] drivers: char: Replace bit operation functions with  IDA allocator. Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-07 17:50 +0200
      Re: [PATCH 5/5] drivers: char: Replace bit operation functions with  IDA allocator. Varsha Rao <rvarsha016@gmail.com> - 2017-04-09 07:30 +0200

#1618704 — [PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator.

FromVarsha Rao <rvarsha016@gmail.com>
Date2017-04-07 13:40 +0200
Subject[PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator.
Message-ID<ttApc-6sd-25@gated-at.bofh.it>
Replace bit operation functions with IDA allocator functions. As IDA
allocation is simpler.

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

[toc] | [next] | [standalone]


#1618917 — Re: [PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator.

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2017-04-07 17:50 +0200
SubjectRe: [PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator.
Message-ID<ttEj7-G4-9@gated-at.bofh.it>
In reply to#1618704
On Fri, Apr 07, 2017 at 05:04:41PM +0530, Varsha Rao wrote:
> Replace bit operation functions with IDA allocator functions. As IDA
> allocation is simpler.

But why does this matter?

> 
> 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);
> +		}

Your indentation is now incorrect :(

>  	} 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);

As much as I like the ida interface, I don't see why it is required to
use it here, you have not provided any justification for this patch at
all :(

thanks,

greg k-h

[toc] | [prev] | [next] | [standalone]


#1619441 — Re: [PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator.

FromVarsha Rao <rvarsha016@gmail.com>
Date2017-04-09 07:30 +0200
SubjectRe: [PATCH 5/5] drivers: char: Replace bit operation functions with IDA allocator.
Message-ID<tudAe-76X-1@gated-at.bofh.it>
In reply to#1618917
>> Replace bit operation functions with IDA allocator functions. As IDA
>> allocation is simpler.
>
> But why does this matter?

Few of the files in this driver is already using ida allocation. For maintaining
the uniformity I have used ida allocation.

Files using idr-ida interface
hw_random/virtio-rng.c
tpm/tpm-chip.c
ppdev.c
tpm/tpm-interface.c
tpm/tpm.h

>>       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);
>> +             }
>
> Your indentation is now incorrect :(

I don't know but in the patch it has correct indentation as below.
-               set_bit(i, misc_minors);
+               }
      } else {
                struct miscdevice *c;


>>       } 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);
>
> As much as I like the ida interface, I don't see why it is required to
> use it here, you have not provided any justification for this patch at
> all :(

Here by the usage of ida interface, allocation will be simpler, faster and
more space efficient. Also conversion  to it is simple. As I mentioned
earlier in this mail also to maintain uniformity of the driver.

Thanks,
Varsha Rao

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web