2021-10-13 06:40:14

by Jiabing Wan

[permalink] [raw]
Subject: [PATCH] iommu/dart: use kmemdup instead of kzalloc and memcpy

Fix following coccicheck warning:
drivers/iommu/apple-dart.c:704:20-27: WARNING opportunity for kmemdup

Signed-off-by: Wan Jiabing <[email protected]>
---
drivers/iommu/apple-dart.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index 280ff8df728d..5eeb8d6b72e2 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -701,13 +701,12 @@ static struct iommu_group *apple_dart_device_group(struct device *dev)
if (!group)
goto out;

- group_master_cfg = kzalloc(sizeof(*group_master_cfg), GFP_KERNEL);
+ group_master_cfg = kmemdup(cfg, sizeof(*group_master_cfg), GFP_KERNEL);
if (!group_master_cfg) {
iommu_group_put(group);
goto out;
}

- memcpy(group_master_cfg, cfg, sizeof(*group_master_cfg));
iommu_group_set_iommudata(group, group_master_cfg,
apple_dart_release_group);

--
2.20.1


2021-10-13 13:22:20

by Alyssa Rosenzweig

[permalink] [raw]
Subject: Re: [PATCH] iommu/dart: use kmemdup instead of kzalloc and memcpy

Reviewed-by: Alyssa Rosenzweig <[email protected]>

On Wed, Oct 13, 2021 at 02:34:41AM -0400, Wan Jiabing wrote:
> Fix following coccicheck warning:
> drivers/iommu/apple-dart.c:704:20-27: WARNING opportunity for kmemdup
>
> Signed-off-by: Wan Jiabing <[email protected]>
> ---
> drivers/iommu/apple-dart.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index 280ff8df728d..5eeb8d6b72e2 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -701,13 +701,12 @@ static struct iommu_group *apple_dart_device_group(struct device *dev)
> if (!group)
> goto out;
>
> - group_master_cfg = kzalloc(sizeof(*group_master_cfg), GFP_KERNEL);
> + group_master_cfg = kmemdup(cfg, sizeof(*group_master_cfg), GFP_KERNEL);
> if (!group_master_cfg) {
> iommu_group_put(group);
> goto out;
> }
>
> - memcpy(group_master_cfg, cfg, sizeof(*group_master_cfg));
> iommu_group_set_iommudata(group, group_master_cfg,
> apple_dart_release_group);
>
> --
> 2.20.1
>

2021-10-18 03:36:07

by Sven Peter

[permalink] [raw]
Subject: Re: [PATCH] iommu/dart: use kmemdup instead of kzalloc and memcpy



On Wed, Oct 13, 2021, at 08:34, Wan Jiabing wrote:
> Fix following coccicheck warning:
> drivers/iommu/apple-dart.c:704:20-27: WARNING opportunity for kmemdup
>
> Signed-off-by: Wan Jiabing <[email protected]>
> ---
> drivers/iommu/apple-dart.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)

Looks good to me, thanks!

Acked-by: Sven Peter <[email protected]>


Sven

2021-10-18 11:40:10

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH] iommu/dart: use kmemdup instead of kzalloc and memcpy

On Wed, Oct 13, 2021 at 02:34:41AM -0400, Wan Jiabing wrote:
> Fix following coccicheck warning:
> drivers/iommu/apple-dart.c:704:20-27: WARNING opportunity for kmemdup
>
> Signed-off-by: Wan Jiabing <[email protected]>
> ---
> drivers/iommu/apple-dart.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)

Applied, thanks.