diff mbox series

[v1] kernel/sysctl.c: Switch to bitmap_zalloc()

Message ID 20190304094037.57756-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1] kernel/sysctl.c: Switch to bitmap_zalloc() | expand

Commit Message

Andy Shevchenko March 4, 2019, 9:40 a.m. UTC
Switch to bitmap_zalloc() to show clearly what we are allocating.
Besides that it returns pointer of bitmap type instead of opaque void *.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/sysctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Kees Cook March 4, 2019, 3:16 p.m. UTC | #1
On Mon, Mar 4, 2019 at 1:40 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Switch to bitmap_zalloc() to show clearly what we are allocating.
> Besides that it returns pointer of bitmap type instead of opaque void *.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  kernel/sysctl.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 46a0d0a14a66..cea18c7c2594 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -3167,9 +3167,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
>                 if (IS_ERR(kbuf))
>                         return PTR_ERR(kbuf);
>
> -               tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
> -                                    sizeof(unsigned long),
> -                                    GFP_KERNEL);
> +               tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
>                 if (!tmp_bitmap) {
>                         kfree(kbuf);
>                         return -ENOMEM;
> @@ -3260,7 +3258,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
>                 *ppos += *lenp;
>         }
>
> -       kfree(tmp_bitmap);
> +       bitmap_free(tmp_bitmap);
>         return err;
>  }
>
> --
> 2.20.1
>
diff mbox series

Patch

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 46a0d0a14a66..cea18c7c2594 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -3167,9 +3167,7 @@  int proc_do_large_bitmap(struct ctl_table *table, int write,
 		if (IS_ERR(kbuf))
 			return PTR_ERR(kbuf);
 
-		tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
-				     sizeof(unsigned long),
-				     GFP_KERNEL);
+		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
 		if (!tmp_bitmap) {
 			kfree(kbuf);
 			return -ENOMEM;
@@ -3260,7 +3258,7 @@  int proc_do_large_bitmap(struct ctl_table *table, int write,
 		*ppos += *lenp;
 	}
 
-	kfree(tmp_bitmap);
+	bitmap_free(tmp_bitmap);
 	return err;
 }