Skip to contentSkip to conversation

btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy

PATCH In review Kai Song 3 participants 3 messages Oct 3, 2021 – Oct 6, 2021 Btrfs file system

lore
Share & tools
lore

Kai Song

author
#0 lore raw

PATCH 1/1 btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy

fix memdup.cocci warning:
fs/btrfs/zoned.c:1198:23-30: WARNING opportunity for kmemdup

---
 fs/btrfs/zoned.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/zoned.c +1 -3
index 1433ee220c94..cfa25f5ede0d 100644
@@ -1195,14 +1195,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 
 	map = em->map_lookup;
 
-	cache->physical_map = kmalloc(map_lookup_size(map->num_stripes), GFP_NOFS);
+	cache->physical_map = kmemdup(map, map_lookup_size(map->num_stripes), GFP_NOFS);
 	if (!cache->physical_map) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
-	memcpy(cache->physical_map, map, map_lookup_size(map->num_stripes));
-
 	alloc_offsets = kcalloc(map->num_stripes, sizeof(*alloc_offsets), GFP_NOFS);
 	if (!alloc_offsets) {
 		ret = -ENOMEM;
Signature · 1 line
2.27.0