Skip to contentSkip to conversation

kernel/sysctl.c: Switch to bitmap_zalloc()

PATCH In review Andy Shevchenko 2 participants 2 messages Mar 4, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/sysctl.c: Switch to bitmap_zalloc()

Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.

---
 kernel/sysctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/sysctl.c +2 -4
index 46a0d0a14a66..cea18c7c2594 100644
@@ -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;
 }
 
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · 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 *.

-Kees

Quoted 31 lines
---
 kernel/sysctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/sysctl.c +2 -5
index 46a0d0a14a66..cea18c7c2594 100644
@@ -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

Signature · 1 line
Kees Cook