[v2,1/1] net: core: Use the bitmap API to allocate bitmaps

Message ID 20230913110957.485237-1-andriy.shevchenko@linux.intel.com
State New
Headers
Series [v2,1/1] net: core: Use the bitmap API to allocate bitmaps |

Commit Message

Andy Shevchenko Sept. 13, 2023, 11:09 a.m. UTC
  Use bitmap_zalloc() and bitmap_free() instead of hand-writing them.
It is less verbose and it improves the type checking and semantic.

While at it, add missing header inclusion (should be bitops.h,
but with the above change it becomes bitmap.h).

Suggested-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20230911154534.4174265-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: added tags (Simon), sent separately from the series (Paolo)
 net/core/dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Przemek Kitszel Sept. 14, 2023, 2:01 p.m. UTC | #1
On 9/13/23 13:09, Andy Shevchenko wrote:
> Use bitmap_zalloc() and bitmap_free() instead of hand-writing them.
> It is less verbose and it improves the type checking and semantic.
> 
> While at it, add missing header inclusion (should be bitops.h,
> but with the above change it becomes bitmap.h).
> 
> Suggested-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
> Reviewed-by: Simon Horman <horms@kernel.org>
> Link: https://lore.kernel.org/r/20230911154534.4174265-1-andriy.shevchenko@linux.intel.com
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: added tags (Simon), sent separately from the series (Paolo)

Yeah, in any context it's hard to get people to agree to fix things when 
they started out of order :~

>   net/core/dev.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index ccff2b6ef958..85df22f05c38 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -69,7 +69,7 @@
>    */
>   
>   #include <linux/uaccess.h>
> -#include <linux/bitops.h>
> +#include <linux/bitmap.h>
>   #include <linux/capability.h>
>   #include <linux/cpu.h>
>   #include <linux/types.h>
> @@ -1080,7 +1080,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
>   			return -EINVAL;
>   
>   		/* Use one page as a bit array of possible slots */
> -		inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
> +		inuse = bitmap_zalloc(max_netdevices, GFP_ATOMIC);
>   		if (!inuse)
>   			return -ENOMEM;
>   
> @@ -1109,7 +1109,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
>   		}
>   
>   		i = find_first_zero_bit(inuse, max_netdevices);
> -		free_page((unsigned long) inuse);
> +		bitmap_free(inuse);
>   	}
>   
>   	snprintf(buf, IFNAMSIZ, name, i);

Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
  
patchwork-bot+netdevbpf@kernel.org Sept. 16, 2023, 12:40 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Wed, 13 Sep 2023 14:09:57 +0300 you wrote:
> Use bitmap_zalloc() and bitmap_free() instead of hand-writing them.
> It is less verbose and it improves the type checking and semantic.
> 
> While at it, add missing header inclusion (should be bitops.h,
> but with the above change it becomes bitmap.h).
> 
> Suggested-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
> Reviewed-by: Simon Horman <horms@kernel.org>
> Link: https://lore.kernel.org/r/20230911154534.4174265-1-andriy.shevchenko@linux.intel.com
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> [...]

Here is the summary with links:
  - [v2,1/1] net: core: Use the bitmap API to allocate bitmaps
    https://git.kernel.org/netdev/net/c/aabb4af9bb29

You are awesome, thank you!
  

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index ccff2b6ef958..85df22f05c38 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -69,7 +69,7 @@ 
  */
 
 #include <linux/uaccess.h>
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
 #include <linux/capability.h>
 #include <linux/cpu.h>
 #include <linux/types.h>
@@ -1080,7 +1080,7 @@  static int __dev_alloc_name(struct net *net, const char *name, char *buf)
 			return -EINVAL;
 
 		/* Use one page as a bit array of possible slots */
-		inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
+		inuse = bitmap_zalloc(max_netdevices, GFP_ATOMIC);
 		if (!inuse)
 			return -ENOMEM;
 
@@ -1109,7 +1109,7 @@  static int __dev_alloc_name(struct net *net, const char *name, char *buf)
 		}
 
 		i = find_first_zero_bit(inuse, max_netdevices);
-		free_page((unsigned long) inuse);
+		bitmap_free(inuse);
 	}
 
 	snprintf(buf, IFNAMSIZ, name, i);