linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy
@ 2021-10-03  8:06 Kai Song
  2021-10-04  8:21 ` Johannes Thumshirn
  2021-10-06 12:17 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Kai Song @ 2021-10-03  8:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kai Song

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

Signed-off-by: Kai Song <songkai01@inspur.com>
---
 fs/btrfs/zoned.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 1433ee220c94..cfa25f5ede0d 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -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;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy
  2021-10-03  8:06 [PATCH] btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy Kai Song
@ 2021-10-04  8:21 ` Johannes Thumshirn
  2021-10-06 12:17 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2021-10-04  8:21 UTC (permalink / raw)
  To: Kai Song, clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy
  2021-10-03  8:06 [PATCH] btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy Kai Song
  2021-10-04  8:21 ` Johannes Thumshirn
@ 2021-10-06 12:17 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2021-10-06 12:17 UTC (permalink / raw)
  To: Kai Song; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel

On Sun, Oct 03, 2021 at 04:06:56PM +0800, Kai Song wrote:
> fix memdup.cocci warning:
> fs/btrfs/zoned.c:1198:23-30: WARNING opportunity for kmemdup
> 
> Signed-off-by: Kai Song <songkai01@inspur.com>

Added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-06 12:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-03  8:06 [PATCH] btrfs: zoned: Use kmemdup() to replace kmalloc + memcpy Kai Song
2021-10-04  8:21 ` Johannes Thumshirn
2021-10-06 12:17 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).