diff mbox

[1/1] btrfs-progs: fix uninitialized copy of btrfs_fs_devices list

Message ID 1445486019-1173-1-git-send-email-anand.jain@oracle.com (mailing list archive)
State Accepted
Headers show

Commit Message

Anand Jain Oct. 22, 2015, 3:53 a.m. UTC
Noticed that at print_one_uuid() some of the members of btrfs_fs_devices
contained some junk values. It took a while to dig this further, and found
that we make a local copy of the btrfs_fs_devices list at
search_umounted_fs_uuids() and wasn't initialized properly.

Fixed using using zalloc instead of malloc.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-filesystem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba Oct. 23, 2015, 9:48 a.m. UTC | #1
On Thu, Oct 22, 2015 at 11:53:39AM +0800, Anand Jain wrote:
> Noticed that at print_one_uuid() some of the members of btrfs_fs_devices
> contained some junk values. It took a while to dig this further, and found
> that we make a local copy of the btrfs_fs_devices list at
> search_umounted_fs_uuids() and wasn't initialized properly.
> 
> Fixed using using zalloc instead of malloc.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  cmds-filesystem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index 3663734..4d3a9a4 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -685,7 +685,7 @@ static int search_umounted_fs_uuids(struct list_head *all_uuids,
>  		if (is_seen_fsid(cur_fs->fsid))
>  			continue;
>  
> -		fs_copy = malloc(sizeof(*fs_copy));
> +		fs_copy = kzalloc(sizeof(*fs_copy), GFP_NOFS);

This is in purely userspace code, we can use malloc/calloc/free, I'll
update it and apply.
--
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/cmds-filesystem.c b/cmds-filesystem.c
index 3663734..4d3a9a4 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -685,7 +685,7 @@  static int search_umounted_fs_uuids(struct list_head *all_uuids,
 		if (is_seen_fsid(cur_fs->fsid))
 			continue;
 
-		fs_copy = malloc(sizeof(*fs_copy));
+		fs_copy = kzalloc(sizeof(*fs_copy), GFP_NOFS);
 		if (!fs_copy) {
 			ret = -ENOMEM;
 			goto out;