linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] kernel/sysctl.c: Switch to bitmap_zalloc()
@ 2019-03-04  9:40 Andy Shevchenko
  2019-03-04 15:16 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2019-03-04  9:40 UTC (permalink / raw)
  To: Luis Chamberlain, Kees Cook, linux-fsdevel, Andrew Morton; +Cc: Andy Shevchenko

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(-)

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


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

* Re: [PATCH v1] kernel/sysctl.c: Switch to bitmap_zalloc()
  2019-03-04  9:40 [PATCH v1] kernel/sysctl.c: Switch to bitmap_zalloc() Andy Shevchenko
@ 2019-03-04 15:16 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2019-03-04 15:16 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Luis Chamberlain, linux-fsdevel@vger.kernel.org, Andrew Morton

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
>


-- 
Kees Cook

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

end of thread, other threads:[~2019-03-04 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-04  9:40 [PATCH v1] kernel/sysctl.c: Switch to bitmap_zalloc() Andy Shevchenko
2019-03-04 15:16 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).