Skip to contentSkip to conversation

btrfs: fix memdup.cocci warnings

PATCH In review Julia Lawall 4 participants 4 messages Sep 22, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix memdup.cocci warnings

From: kernel test robot <[email protected]>

fs/btrfs/send.c:3854:8-15: WARNING opportunity for kmemdup

Use kmemdup rather than duplicating its implementation

Generated by: scripts/coccinelle/api/memdup.cocci

Fixes 28314eb24e6c ("btrfs: send, recompute reference path after orphanization of a directory")

---

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/fdmanana/linux.git misc-next
head:   28314eb24e6cb8124d1e5da2ef2ccb90ec44cc06
commit: 28314eb24e6cb8124d1e5da2ef2ccb90ec44cc06 [2/2] btrfs: send, recompute reference path after orphanization of a directory

:::::: branch date: 17 hours ago
:::::: commit date: 17 hours ago

 send.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/send.c +1 -2
@@ -3851,10 +3851,9 @@ static int refresh_ref_path(struct send_
 	char *name;
 	int ret;
 
-	name = kmalloc(ref->name_len, GFP_KERNEL);
+	name = kmemdup(ref->name, ref->name_len, GFP_KERNEL);
 	if (!name)
 		return -ENOMEM;
-	memcpy(name, ref->name, ref->name_len);
 
 	fs_path_reset(ref->full_path);
 	ret = get_cur_path(sctx, ref->dir, ref->dir_gen, ref->full_path);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Julia Lawall

From: kernel test robot <[email protected]>

fs/btrfs/send.c:3854:8-15: WARNING opportunity for kmemdup

Use kmemdup rather than duplicating its implementation

Generated by: scripts/coccinelle/api/memdup.cocci

Fixes 28314eb24e6c ("btrfs: send, recompute reference path after orphanization of a directory")

Thanks,

Josef

#2 lore raw
In reply to Julia Lawall
Quoted 5 lines · Julia Lawall

From: kernel test robot <[email protected]>

fs/btrfs/send.c:3854:8-15: WARNING opportunity for kmemdup

Quoted 7 lines

Use kmemdup rather than duplicating its implementation

Generated by: scripts/coccinelle/api/memdup.cocci

Fixes 28314eb24e6c ("btrfs: send, recompute reference path after orphanization of a directory")

Since this is not in Linus' tree yet, it can be folded in the original patch. David, can you do that when you pick it?

Btw, isn't the Fixes tag meant only for bug fixes? This is a pure cleanup afaics.

Thanks.

Quoted 26 lines

---

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/fdmanana/linux.git misc-next
head:   28314eb24e6cb8124d1e5da2ef2ccb90ec44cc06
commit: 28314eb24e6cb8124d1e5da2ef2ccb90ec44cc06 [2/2] btrfs: send, recompute reference path after orphanization of a directory

:::::: branch date: 17 hours ago
:::::: commit date: 17 hours ago

 send.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/send.c +1 -2
@@ -3851,10 +3851,9 @@ static int refresh_ref_path(struct send_
        char *name;
        int ret;
 
-       name = kmalloc(ref->name_len, GFP_KERNEL);
+       name = kmemdup(ref->name, ref->name_len, GFP_KERNEL);
        if (!name)
                return -ENOMEM;
-       memcpy(name, ref->name, ref->name_len);
 
        fs_path_reset(ref->full_path);
        ret = get_cur_path(sctx, ref->dir, ref->dir_gen, ref->full_path);
Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#3 lore raw
Quoted 8 lines · Filipe Manana
Quoted 7 lines · Julia Lawall

From: kernel test robot <[email protected]>

fs/btrfs/send.c:3854:8-15: WARNING opportunity for kmemdup

Use kmemdup rather than duplicating its implementation

Quoted 8 lines
Quoted 5 lines

Generated by: scripts/coccinelle/api/memdup.cocci

Fixes 28314eb24e6c ("btrfs: send, recompute reference path after orphanization of a directory")

Since this is not in Linus' tree yet, it can be folded in the original patch. David, can you do that when you pick it?

Yes, I'll do that.

Quoted 2 lines

Btw, isn't the Fixes tag meant only for bug fixes? This is a pure cleanup afaics.

Agreed.