2023-11-01 22:52:59

by Vishal Verma

[permalink] [raw]
Subject: [PATCH v8 1/3] mm/memory_hotplug: replace an open-coded kmemdup() in add_memory_resource()

A review of the memmap_on_memory modifications to add_memory_resource()
revealed an instance of an open-coded kmemdup(). Replace it with
kmemdup().

Cc: Andrew Morton <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Dan Williams <[email protected]>
Reported-by: Dan Williams <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
---
mm/memory_hotplug.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index f8d3e7427e32..6be7de9efa55 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1439,11 +1439,11 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
if (mhp_flags & MHP_MEMMAP_ON_MEMORY) {
if (mhp_supports_memmap_on_memory(size)) {
mhp_altmap.free = memory_block_memmap_on_memory_pages();
- params.altmap = kmalloc(sizeof(struct vmem_altmap), GFP_KERNEL);
+ params.altmap = kmemdup(&mhp_altmap,
+ sizeof(struct vmem_altmap),
+ GFP_KERNEL);
if (!params.altmap)
goto error;
-
- memcpy(params.altmap, &mhp_altmap, sizeof(mhp_altmap));
}
/* fallback to not using altmap */
}

--
2.41.0


2023-11-03 16:27:31

by fan

[permalink] [raw]
Subject: Re: [PATCH v8 1/3] mm/memory_hotplug: replace an open-coded kmemdup() in add_memory_resource()

On Wed, Nov 01, 2023 at 04:51:51PM -0600, Vishal Verma wrote:
> A review of the memmap_on_memory modifications to add_memory_resource()
> revealed an instance of an open-coded kmemdup(). Replace it with
> kmemdup().
>
> Cc: Andrew Morton <[email protected]>
> Cc: David Hildenbrand <[email protected]>
> Cc: Michal Hocko <[email protected]>
> Cc: Oscar Salvador <[email protected]>
> Cc: Dan Williams <[email protected]>
> Reported-by: Dan Williams <[email protected]>
> Reviewed-by: David Hildenbrand <[email protected]>
> Signed-off-by: Vishal Verma <[email protected]>
> ---

Reviewed-by: Fan Ni <[email protected]>

> mm/memory_hotplug.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index f8d3e7427e32..6be7de9efa55 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1439,11 +1439,11 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
> if (mhp_flags & MHP_MEMMAP_ON_MEMORY) {
> if (mhp_supports_memmap_on_memory(size)) {
> mhp_altmap.free = memory_block_memmap_on_memory_pages();
> - params.altmap = kmalloc(sizeof(struct vmem_altmap), GFP_KERNEL);
> + params.altmap = kmemdup(&mhp_altmap,
> + sizeof(struct vmem_altmap),
> + GFP_KERNEL);
> if (!params.altmap)
> goto error;
> -
> - memcpy(params.altmap, &mhp_altmap, sizeof(mhp_altmap));
> }
> /* fallback to not using altmap */
> }
>
> --
> 2.41.0
>