Skip to contentSkip to conversation

ubi: fastmap: use kmem_cache_free to deallocate memory

PATCH Pan Bian 2 participants 2 messages Oct 29, 2017 – Oct 30, 2017

Subsystems (3)
lore
Share & tools
lore

Pan Bian

author
#0 lore raw

Memory allocated by kmem_cache_alloc() should not be deallocated with kfree(). Use kmem_cache_free() instead.

---
 drivers/mtd/ubi/fastmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/ubi/fastmap.c +1 -1
index 5a832bc..717db749 100644
@@ -1063,7 +1063,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
 		e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
 		if (!e) {
 			while (i--)
-				kfree(fm->e[i]);
+				kmem_cache_free(ubi_wl_entry_slab, fm->e[i]);
 
 			ret = -ENOMEM;
 			goto free_hdr;
Signature · 1 line
1.9.1
Reviewed-by
#1 lore raw
Quoted 4 lines · On Sun, 29 Oct 2017 20:40:02 +0800 Pan Bian <[email protected]> wrote:

Memory allocated by kmem_cache_alloc() should not be deallocated with kfree(). Use kmem_cache_free() instead.

Richard, maybe you can add:

Fixes dbb7d2a88d2a ("UBI: Add fastmap core")
Quoted 17 lines
---
 drivers/mtd/ubi/fastmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/ubi/fastmap.c +1 -1
index 5a832bc..717db749 100644
@@ -1063,7 +1063,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
 		e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
 		if (!e) {
 			while (i--)
-				kfree(fm->e[i]);
+				kmem_cache_free(ubi_wl_entry_slab, fm->e[i]);
 
 			ret = -ENOMEM;
 			goto free_hdr;