diff mbox

[1/2] Btrfs: use kmem_cache_free when freeing entry in inode cache

Message ID 1434174777-14409-1-git-send-email-fdmanana@kernel.org (mailing list archive)
State Accepted
Headers show

Commit Message

Filipe Manana June 13, 2015, 5:52 a.m. UTC
From: Filipe Manana <fdmanana@suse.com>

The free space entries are allocated using kmem_cache_zalloc(),
through __btrfs_add_free_space(), therefore we should use
kmem_cache_free() and not kfree() to avoid any confusion and
any potential problem. Looking at the kfree() definition at
mm/slab.c it has the following comment:

  /*
   * (...)
   *
   * Don't free memory not originally allocated by kmalloc()
   * or you will run into trouble.
   */

So better be safe and use kmem_cache_free().

Cc: stable@vger.kernel.org
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/inode-map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba June 15, 2015, 1:32 p.m. UTC | #1
On Sat, Jun 13, 2015 at 06:52:56AM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> The free space entries are allocated using kmem_cache_zalloc(),
> through __btrfs_add_free_space(), therefore we should use
> kmem_cache_free() and not kfree() to avoid any confusion and
> any potential problem. Looking at the kfree() definition at
> mm/slab.c it has the following comment:
> 
>   /*
>    * (...)
>    *
>    * Don't free memory not originally allocated by kmalloc()
>    * or you will run into trouble.
>    */
> 
> So better be safe and use kmem_cache_free().
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: David Sterba <dsterba@suse.cz>
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index f6a596d..218df70 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -271,7 +271,7 @@  void btrfs_unpin_free_ino(struct btrfs_root *root)
 		__btrfs_add_free_space(ctl, info->offset, count);
 free:
 		rb_erase(&info->offset_index, rbroot);
-		kfree(info);
+		kmem_cache_free(btrfs_free_space_cachep, info);
 	}
 }