aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>2016-01-22 18:11:02 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-22 20:02:18 -0500
commit1d5cfdb076288df5eb95545a547a39905e95c930 (patch)
treec644d2e609c3054833710b75ab1d0fe50fb17c01
parenteab95db69d334745d3034072f4a7204084136c88 (diff)
tree wide: use kvfree() than conditional kfree()/vfree()
There are many locations that do if (memory_was_allocated_by_vmalloc) vfree(ptr); else kfree(ptr); but kvfree() can handle both kmalloc()ed memory and vmalloc()ed memory using is_vmalloc_addr(). Unless callers have special reasons, we can replace this branch with kvfree(). Please check and reply if you found problems. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Jan Kara <jack@suse.com> Acked-by: Russell King <rmk+kernel@arm.linux.org.uk> Reviewed-by: Andreas Dilger <andreas.dilger@intel.com> Acked-by: "Rafael J. Wysocki" <rjw@rjwysocki.net> Acked-by: David Rientjes <rientjes@google.com> Cc: "Luck, Tony" <tony.luck@intel.com> Cc: Oleg Drokin <oleg.drokin@intel.com> Cc: Boris Petkov <bp@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/arm/mm/dma-mapping.c11
-rw-r--r--drivers/acpi/apei/erst.c6
-rw-r--r--drivers/block/drbd/drbd_bitmap.c26
-rw-r--r--drivers/block/drbd/drbd_int.h3
-rw-r--r--drivers/char/mspec.c15
-rw-r--r--drivers/gpu/drm/drm_hashtab.c5
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_private.h8
-rw-r--r--fs/coda/coda_linux.h3
-rw-r--r--fs/jffs2/build.c8
-rw-r--r--fs/jffs2/fs.c5
-rw-r--r--fs/jffs2/super.c5
-rw-r--r--fs/udf/super.c7
-rw-r--r--ipc/sem.c2
-rw-r--r--ipc/util.c11
-rw-r--r--ipc/util.h2
-rw-r--r--mm/percpu.c18
-rw-r--r--net/ipv4/fib_trie.c4
17 files changed, 36 insertions, 103 deletions
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 534a60ae282e..0eca3812527e 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1200,10 +1200,7 @@ error:
1200 while (i--) 1200 while (i--)
1201 if (pages[i]) 1201 if (pages[i])
1202 __free_pages(pages[i], 0); 1202 __free_pages(pages[i], 0);
1203 if (array_size <= PAGE_SIZE) 1203 kvfree(pages);
1204 kfree(pages);
1205 else
1206 vfree(pages);
1207 return NULL; 1204 return NULL;
1208} 1205}
1209 1206
@@ -1211,7 +1208,6 @@ static int __iommu_free_buffer(struct device *dev, struct page **pages,
1211 size_t size, struct dma_attrs *attrs) 1208 size_t size, struct dma_attrs *attrs)
1212{ 1209{
1213 int count = size >> PAGE_SHIFT; 1210 int count = size >> PAGE_SHIFT;
1214 int array_size = count * sizeof(struct page *);
1215 int i; 1211 int i;
1216 1212
1217 if (dma_get_attr(DMA_ATTR_FORCE_CONTIGUOUS, attrs)) { 1213 if (dma_get_attr(DMA_ATTR_FORCE_CONTIGUOUS, attrs)) {
@@ -1222,10 +1218,7 @@ static int __iommu_free_buffer(struct device *dev, struct page **pages,
1222 __free_pages(pages[i], 0); 1218 __free_pages(pages[i], 0);
1223 } 1219 }
1224 1220
1225 if (array_size <= PAGE_SIZE) 1221 kvfree(pages);
1226 kfree(pages);
1227 else
1228 vfree(pages);
1229 return 0; 1222 return 0;
1230} 1223}
1231 1224
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 6682c5daf742..6e6bc1059301 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -32,6 +32,7 @@
32#include <linux/hardirq.h> 32#include <linux/hardirq.h>
33#include <linux/pstore.h> 33#include <linux/pstore.h>
34#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
35#include <linux/mm.h> /* kvfree() */
35#include <acpi/apei.h> 36#include <acpi/apei.h>
36 37
37#include "apei-internal.h" 38#include "apei-internal.h"
@@ -532,10 +533,7 @@ retry:
532 return -ENOMEM; 533 return -ENOMEM;
533 memcpy(new_entries, entries, 534 memcpy(new_entries, entries,
534 erst_record_id_cache.len * sizeof(entries[0])); 535 erst_record_id_cache.len * sizeof(entries[0]));
535 if (erst_record_id_cache.size < PAGE_SIZE) 536 kvfree(entries);
536 kfree(entries);
537 else
538 vfree(entries);
539 erst_record_id_cache.entries = entries = new_entries; 537 erst_record_id_cache.entries = entries = new_entries;
540 erst_record_id_cache.size = new_size; 538 erst_record_id_cache.size = new_size;
541 } 539 }
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 0dabc9b93725..92d6fc020a65 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -364,12 +364,9 @@ static void bm_free_pages(struct page **pages, unsigned long number)
364 } 364 }
365} 365}
366 366
367static void bm_vk_free(void *ptr, int v) 367static inline void bm_vk_free(void *ptr)
368{ 368{
369 if (v) 369 kvfree(ptr);
370 vfree(ptr);
371 else
372 kfree(ptr);
373} 370}
374 371
375/* 372/*
@@ -379,7 +376,7 @@ static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want)
379{ 376{
380 struct page **old_pages = b->bm_pages; 377 struct page **old_pages = b->bm_pages;
381 struct page **new_pages, *page; 378 struct page **new_pages, *page;
382 unsigned int i, bytes, vmalloced = 0; 379 unsigned int i, bytes;
383 unsigned long have = b->bm_number_of_pages; 380 unsigned long have = b->bm_number_of_pages;
384 381
385 BUG_ON(have == 0 && old_pages != NULL); 382 BUG_ON(have == 0 && old_pages != NULL);
@@ -401,7 +398,6 @@ static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want)
401 PAGE_KERNEL); 398 PAGE_KERNEL);
402 if (!new_pages) 399 if (!new_pages)
403 return NULL; 400 return NULL;
404 vmalloced = 1;
405 } 401 }
406 402
407 if (want >= have) { 403 if (want >= have) {
@@ -411,7 +407,7 @@ static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want)
411 page = alloc_page(GFP_NOIO | __GFP_HIGHMEM); 407 page = alloc_page(GFP_NOIO | __GFP_HIGHMEM);
412 if (!page) { 408 if (!page) {
413 bm_free_pages(new_pages + have, i - have); 409 bm_free_pages(new_pages + have, i - have);
414 bm_vk_free(new_pages, vmalloced); 410 bm_vk_free(new_pages);
415 return NULL; 411 return NULL;
416 } 412 }
417 /* we want to know which page it is 413 /* we want to know which page it is
@@ -427,11 +423,6 @@ static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want)
427 */ 423 */
428 } 424 }
429 425
430 if (vmalloced)
431 b->bm_flags |= BM_P_VMALLOCED;
432 else
433 b->bm_flags &= ~BM_P_VMALLOCED;
434
435 return new_pages; 426 return new_pages;
436} 427}
437 428
@@ -469,7 +460,7 @@ void drbd_bm_cleanup(struct drbd_device *device)
469 if (!expect(device->bitmap)) 460 if (!expect(device->bitmap))
470 return; 461 return;
471 bm_free_pages(device->bitmap->bm_pages, device->bitmap->bm_number_of_pages); 462 bm_free_pages(device->bitmap->bm_pages, device->bitmap->bm_number_of_pages);
472 bm_vk_free(device->bitmap->bm_pages, (BM_P_VMALLOCED & device->bitmap->bm_flags)); 463 bm_vk_free(device->bitmap->bm_pages);
473 kfree(device->bitmap); 464 kfree(device->bitmap);
474 device->bitmap = NULL; 465 device->bitmap = NULL;
475} 466}
@@ -643,7 +634,6 @@ int drbd_bm_resize(struct drbd_device *device, sector_t capacity, int set_new_bi
643 unsigned long want, have, onpages; /* number of pages */ 634 unsigned long want, have, onpages; /* number of pages */
644 struct page **npages, **opages = NULL; 635 struct page **npages, **opages = NULL;
645 int err = 0, growing; 636 int err = 0, growing;
646 int opages_vmalloced;
647 637
648 if (!expect(b)) 638 if (!expect(b))
649 return -ENOMEM; 639 return -ENOMEM;
@@ -656,8 +646,6 @@ int drbd_bm_resize(struct drbd_device *device, sector_t capacity, int set_new_bi
656 if (capacity == b->bm_dev_capacity) 646 if (capacity == b->bm_dev_capacity)
657 goto out; 647 goto out;
658 648
659 opages_vmalloced = (BM_P_VMALLOCED & b->bm_flags);
660
661 if (capacity == 0) { 649 if (capacity == 0) {
662 spin_lock_irq(&b->bm_lock); 650 spin_lock_irq(&b->bm_lock);
663 opages = b->bm_pages; 651 opages = b->bm_pages;
@@ -671,7 +659,7 @@ int drbd_bm_resize(struct drbd_device *device, sector_t capacity, int set_new_bi
671 b->bm_dev_capacity = 0; 659 b->bm_dev_capacity = 0;
672 spin_unlock_irq(&b->bm_lock); 660 spin_unlock_irq(&b->bm_lock);
673 bm_free_pages(opages, onpages); 661 bm_free_pages(opages, onpages);
674 bm_vk_free(opages, opages_vmalloced); 662 bm_vk_free(opages);
675 goto out; 663 goto out;
676 } 664 }
677 bits = BM_SECT_TO_BIT(ALIGN(capacity, BM_SECT_PER_BIT)); 665 bits = BM_SECT_TO_BIT(ALIGN(capacity, BM_SECT_PER_BIT));
@@ -744,7 +732,7 @@ int drbd_bm_resize(struct drbd_device *device, sector_t capacity, int set_new_bi
744 732
745 spin_unlock_irq(&b->bm_lock); 733 spin_unlock_irq(&b->bm_lock);
746 if (opages != npages) 734 if (opages != npages)
747 bm_vk_free(opages, opages_vmalloced); 735 bm_vk_free(opages);
748 if (!growing) 736 if (!growing)
749 b->bm_set = bm_count_bits(b); 737 b->bm_set = bm_count_bits(b);
750 drbd_info(device, "resync bitmap: bits=%lu words=%lu pages=%lu\n", bits, words, want); 738 drbd_info(device, "resync bitmap: bits=%lu words=%lu pages=%lu\n", bits, words, want);
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index b6844feb9f9b..34bc84efc29e 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -536,9 +536,6 @@ struct drbd_bitmap; /* opaque for drbd_device */
536/* definition of bits in bm_flags to be used in drbd_bm_lock 536/* definition of bits in bm_flags to be used in drbd_bm_lock
537 * and drbd_bitmap_io and friends. */ 537 * and drbd_bitmap_io and friends. */
538enum bm_flag { 538enum bm_flag {
539 /* do we need to kfree, or vfree bm_pages? */
540 BM_P_VMALLOCED = 0x10000, /* internal use only, will be masked out */
541
542 /* currently locked for bulk operation */ 539 /* currently locked for bulk operation */
543 BM_LOCKED_MASK = 0xf, 540 BM_LOCKED_MASK = 0xf,
544 541
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index f1d7fa45c275..f3f92d5fcda0 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -93,14 +93,11 @@ struct vma_data {
93 spinlock_t lock; /* Serialize access to this structure. */ 93 spinlock_t lock; /* Serialize access to this structure. */
94 int count; /* Number of pages allocated. */ 94 int count; /* Number of pages allocated. */
95 enum mspec_page_type type; /* Type of pages allocated. */ 95 enum mspec_page_type type; /* Type of pages allocated. */
96 int flags; /* See VMD_xxx below. */
97 unsigned long vm_start; /* Original (unsplit) base. */ 96 unsigned long vm_start; /* Original (unsplit) base. */
98 unsigned long vm_end; /* Original (unsplit) end. */ 97 unsigned long vm_end; /* Original (unsplit) end. */
99 unsigned long maddr[0]; /* Array of MSPEC addresses. */ 98 unsigned long maddr[0]; /* Array of MSPEC addresses. */
100}; 99};
101 100
102#define VMD_VMALLOCED 0x1 /* vmalloc'd rather than kmalloc'd */
103
104/* used on shub2 to clear FOP cache in the HUB */ 101/* used on shub2 to clear FOP cache in the HUB */
105static unsigned long scratch_page[MAX_NUMNODES]; 102static unsigned long scratch_page[MAX_NUMNODES];
106#define SH2_AMO_CACHE_ENTRIES 4 103#define SH2_AMO_CACHE_ENTRIES 4
@@ -185,10 +182,7 @@ mspec_close(struct vm_area_struct *vma)
185 "failed to zero page %ld\n", my_page); 182 "failed to zero page %ld\n", my_page);
186 } 183 }
187 184
188 if (vdata->flags & VMD_VMALLOCED) 185 kvfree(vdata);
189 vfree(vdata);
190 else
191 kfree(vdata);
192} 186}
193 187
194/* 188/*
@@ -256,7 +250,7 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma,
256 enum mspec_page_type type) 250 enum mspec_page_type type)
257{ 251{
258 struct vma_data *vdata; 252 struct vma_data *vdata;
259 int pages, vdata_size, flags = 0; 253 int pages, vdata_size;
260 254
261 if (vma->vm_pgoff != 0) 255 if (vma->vm_pgoff != 0)
262 return -EINVAL; 256 return -EINVAL;
@@ -271,16 +265,13 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma,
271 vdata_size = sizeof(struct vma_data) + pages * sizeof(long); 265 vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
272 if (vdata_size <= PAGE_SIZE) 266 if (vdata_size <= PAGE_SIZE)
273 vdata = kzalloc(vdata_size, GFP_KERNEL); 267 vdata = kzalloc(vdata_size, GFP_KERNEL);
274 else { 268 else
275 vdata = vzalloc(vdata_size); 269 vdata = vzalloc(vdata_size);
276 flags = VMD_VMALLOCED;
277 }
278 if (!vdata) 270 if (!vdata)
279 return -ENOMEM; 271 return -ENOMEM;
280 272
281 vdata->vm_start = vma->vm_start; 273 vdata->vm_start = vma->vm_start;
282 vdata->vm_end = vma->vm_end; 274 vdata->vm_end = vma->vm_end;
283 vdata->flags = flags;
284 vdata->type = type; 275 vdata->type = type;
285 spin_lock_init(&vdata->lock); 276 spin_lock_init(&vdata->lock);
286 atomic_set(&vdata->refcnt, 1); 277 atomic_set(&vdata->refcnt, 1);
diff --git a/drivers/gpu/drm/drm_hashtab.c b/drivers/gpu/drm/drm_hashtab.c
index c3b80fd65d62..7b30b307674b 100644
--- a/drivers/gpu/drm/drm_hashtab.c
+++ b/drivers/gpu/drm/drm_hashtab.c
@@ -198,10 +198,7 @@ EXPORT_SYMBOL(drm_ht_remove_item);
198void drm_ht_remove(struct drm_open_hash *ht) 198void drm_ht_remove(struct drm_open_hash *ht)
199{ 199{
200 if (ht->table) { 200 if (ht->table) {
201 if ((PAGE_SIZE / sizeof(*ht->table)) >> ht->order) 201 kvfree(ht->table);
202 kfree(ht->table);
203 else
204 vfree(ht->table);
205 ht->table = NULL; 202 ht->table = NULL;
206 } 203 }
207} 204}
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
index d6273e143324..a80d993b882e 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
@@ -151,16 +151,12 @@ do { \
151 151
152#define LIBCFS_FREE(ptr, size) \ 152#define LIBCFS_FREE(ptr, size) \
153do { \ 153do { \
154 int s = (size); \
155 if (unlikely((ptr) == NULL)) { \ 154 if (unlikely((ptr) == NULL)) { \
156 CERROR("LIBCFS: free NULL '" #ptr "' (%d bytes) at " \ 155 CERROR("LIBCFS: free NULL '" #ptr "' (%d bytes) at " \
157 "%s:%d\n", s, __FILE__, __LINE__); \ 156 "%s:%d\n", (int)(size), __FILE__, __LINE__); \
158 break; \ 157 break; \
159 } \ 158 } \
160 if (unlikely(s > LIBCFS_VMALLOC_SIZE)) \ 159 kvfree(ptr); \
161 vfree(ptr); \
162 else \
163 kfree(ptr); \
164} while (0) 160} while (0)
165 161
166/******************************************************************************/ 162/******************************************************************************/
diff --git a/fs/coda/coda_linux.h b/fs/coda/coda_linux.h
index f829fe963f5b..5104d84c4f64 100644
--- a/fs/coda/coda_linux.h
+++ b/fs/coda/coda_linux.h
@@ -72,8 +72,7 @@ void coda_sysctl_clean(void);
72} while (0) 72} while (0)
73 73
74 74
75#define CODA_FREE(ptr,size) \ 75#define CODA_FREE(ptr, size) kvfree((ptr))
76 do { if (size < PAGE_SIZE) kfree((ptr)); else vfree((ptr)); } while (0)
77 76
78/* inode to cnode access functions */ 77/* inode to cnode access functions */
79 78
diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c
index a3750f902adc..0ae91ad6df2d 100644
--- a/fs/jffs2/build.c
+++ b/fs/jffs2/build.c
@@ -17,6 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/mm.h> /* kvfree() */
20#include "nodelist.h" 21#include "nodelist.h"
21 22
22static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *, 23static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *,
@@ -383,12 +384,7 @@ int jffs2_do_mount_fs(struct jffs2_sb_info *c)
383 return 0; 384 return 0;
384 385
385 out_free: 386 out_free:
386#ifndef __ECOS 387 kvfree(c->blocks);
387 if (jffs2_blocks_use_vmalloc(c))
388 vfree(c->blocks);
389 else
390#endif
391 kfree(c->blocks);
392 388
393 return ret; 389 return ret;
394} 390}
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 2caf1682036d..bead25ae8fe4 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -596,10 +596,7 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
596out_root: 596out_root:
597 jffs2_free_ino_caches(c); 597 jffs2_free_ino_caches(c);
598 jffs2_free_raw_node_refs(c); 598 jffs2_free_raw_node_refs(c);
599 if (jffs2_blocks_use_vmalloc(c)) 599 kvfree(c->blocks);
600 vfree(c->blocks);
601 else
602 kfree(c->blocks);
603 out_inohash: 600 out_inohash:
604 jffs2_clear_xattr_subsystem(c); 601 jffs2_clear_xattr_subsystem(c);
605 kfree(c->inocache_list); 602 kfree(c->inocache_list);
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index bb080c272149..0a9a114bb9d1 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -331,10 +331,7 @@ static void jffs2_put_super (struct super_block *sb)
331 331
332 jffs2_free_ino_caches(c); 332 jffs2_free_ino_caches(c);
333 jffs2_free_raw_node_refs(c); 333 jffs2_free_raw_node_refs(c);
334 if (jffs2_blocks_use_vmalloc(c)) 334 kvfree(c->blocks);
335 vfree(c->blocks);
336 else
337 kfree(c->blocks);
338 jffs2_flash_cleanup(c); 335 jffs2_flash_cleanup(c);
339 kfree(c->inocache_list); 336 kfree(c->inocache_list);
340 jffs2_clear_xattr_subsystem(c); 337 jffs2_clear_xattr_subsystem(c);
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 0fbb4c7c72e8..a522c15a0bfd 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -279,17 +279,12 @@ static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
279{ 279{
280 int i; 280 int i;
281 int nr_groups = bitmap->s_nr_groups; 281 int nr_groups = bitmap->s_nr_groups;
282 int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
283 nr_groups);
284 282
285 for (i = 0; i < nr_groups; i++) 283 for (i = 0; i < nr_groups; i++)
286 if (bitmap->s_block_bitmap[i]) 284 if (bitmap->s_block_bitmap[i])
287 brelse(bitmap->s_block_bitmap[i]); 285 brelse(bitmap->s_block_bitmap[i]);
288 286
289 if (size <= PAGE_SIZE) 287 kvfree(bitmap);
290 kfree(bitmap);
291 else
292 vfree(bitmap);
293} 288}
294 289
295static void udf_free_partition(struct udf_part_map *map) 290static void udf_free_partition(struct udf_part_map *map)
diff --git a/ipc/sem.c b/ipc/sem.c
index b471e5a3863d..cddd5b5fde51 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1493,7 +1493,7 @@ out_rcu_wakeup:
1493 wake_up_sem_queue_do(&tasks); 1493 wake_up_sem_queue_do(&tasks);
1494out_free: 1494out_free:
1495 if (sem_io != fast_sem_io) 1495 if (sem_io != fast_sem_io)
1496 ipc_free(sem_io, sizeof(ushort)*nsems); 1496 ipc_free(sem_io);
1497 return err; 1497 return err;
1498} 1498}
1499 1499
diff --git a/ipc/util.c b/ipc/util.c
index 0f401d94b7c6..798cad18dd87 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -414,17 +414,12 @@ void *ipc_alloc(int size)
414/** 414/**
415 * ipc_free - free ipc space 415 * ipc_free - free ipc space
416 * @ptr: pointer returned by ipc_alloc 416 * @ptr: pointer returned by ipc_alloc
417 * @size: size of block
418 * 417 *
419 * Free a block created with ipc_alloc(). The caller must know the size 418 * Free a block created with ipc_alloc().
420 * used in the allocation call.
421 */ 419 */
422void ipc_free(void *ptr, int size) 420void ipc_free(void *ptr)
423{ 421{
424 if (size > PAGE_SIZE) 422 kvfree(ptr);
425 vfree(ptr);
426 else
427 kfree(ptr);
428} 423}
429 424
430/** 425/**
diff --git a/ipc/util.h b/ipc/util.h
index 3a8a5a0eca62..51f7ca58ac67 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -118,7 +118,7 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg);
118 * both function can sleep 118 * both function can sleep
119 */ 119 */
120void *ipc_alloc(int size); 120void *ipc_alloc(int size);
121void ipc_free(void *ptr, int size); 121void ipc_free(void *ptr);
122 122
123/* 123/*
124 * For allocation that need to be freed by RCU. 124 * For allocation that need to be freed by RCU.
diff --git a/mm/percpu.c b/mm/percpu.c
index 8a943b97a053..998607adf6eb 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -305,16 +305,12 @@ static void *pcpu_mem_zalloc(size_t size)
305/** 305/**
306 * pcpu_mem_free - free memory 306 * pcpu_mem_free - free memory
307 * @ptr: memory to free 307 * @ptr: memory to free
308 * @size: size of the area
309 * 308 *
310 * Free @ptr. @ptr should have been allocated using pcpu_mem_zalloc(). 309 * Free @ptr. @ptr should have been allocated using pcpu_mem_zalloc().
311 */ 310 */
312static void pcpu_mem_free(void *ptr, size_t size) 311static void pcpu_mem_free(void *ptr)
313{ 312{
314 if (size <= PAGE_SIZE) 313 kvfree(ptr);
315 kfree(ptr);
316 else
317 vfree(ptr);
318} 314}
319 315
320/** 316/**
@@ -463,8 +459,8 @@ out_unlock:
463 * pcpu_mem_free() might end up calling vfree() which uses 459 * pcpu_mem_free() might end up calling vfree() which uses
464 * IRQ-unsafe lock and thus can't be called under pcpu_lock. 460 * IRQ-unsafe lock and thus can't be called under pcpu_lock.
465 */ 461 */
466 pcpu_mem_free(old, old_size); 462 pcpu_mem_free(old);
467 pcpu_mem_free(new, new_size); 463 pcpu_mem_free(new);
468 464
469 return 0; 465 return 0;
470} 466}
@@ -732,7 +728,7 @@ static struct pcpu_chunk *pcpu_alloc_chunk(void)
732 chunk->map = pcpu_mem_zalloc(PCPU_DFL_MAP_ALLOC * 728 chunk->map = pcpu_mem_zalloc(PCPU_DFL_MAP_ALLOC *
733 sizeof(chunk->map[0])); 729 sizeof(chunk->map[0]));
734 if (!chunk->map) { 730 if (!chunk->map) {
735 pcpu_mem_free(chunk, pcpu_chunk_struct_size); 731 pcpu_mem_free(chunk);
736 return NULL; 732 return NULL;
737 } 733 }
738 734
@@ -753,8 +749,8 @@ static void pcpu_free_chunk(struct pcpu_chunk *chunk)
753{ 749{
754 if (!chunk) 750 if (!chunk)
755 return; 751 return;
756 pcpu_mem_free(chunk->map, chunk->map_alloc * sizeof(chunk->map[0])); 752 pcpu_mem_free(chunk->map);
757 pcpu_mem_free(chunk, pcpu_chunk_struct_size); 753 pcpu_mem_free(chunk);
758} 754}
759 755
760/** 756/**
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 744e5936c10d..7aea0ccb6be6 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -289,10 +289,8 @@ static void __node_free_rcu(struct rcu_head *head)
289 289
290 if (!n->tn_bits) 290 if (!n->tn_bits)
291 kmem_cache_free(trie_leaf_kmem, n); 291 kmem_cache_free(trie_leaf_kmem, n);
292 else if (n->tn_bits <= TNODE_KMALLOC_MAX)
293 kfree(n);
294 else 292 else
295 vfree(n); 293 kvfree(n);
296} 294}
297 295
298#define node_free(n) call_rcu(&tn_info(n)->rcu, __node_free_rcu) 296#define node_free(n) call_rcu(&tn_info(n)->rcu, __node_free_rcu)