diff mbox series

[-next] mm/memory_hotplug: fix error return code in add_memory_resource()

Message ID 20230809081552.1351184-1-yangyingliang@huawei.com (mailing list archive)
State New
Headers show
Series [-next] mm/memory_hotplug: fix error return code in add_memory_resource() | expand

Commit Message

Yang Yingliang Aug. 9, 2023, 8:15 a.m. UTC
Set error return code to -ENOMEM, when kmalloc() fails.

Fixes: ad3232df3e41 ("mm/memory_hotplug: embed vmem_altmap details in memory block")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 mm/memory_hotplug.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

David Hildenbrand Aug. 9, 2023, 8:39 a.m. UTC | #1
On 09.08.23 10:15, Yang Yingliang wrote:
> Set error return code to -ENOMEM, when kmalloc() fails.
> 
> Fixes: ad3232df3e41 ("mm/memory_hotplug: embed vmem_altmap details in memory block")

Commit id is not stable yet.

> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   mm/memory_hotplug.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index f8d3e7427e32..1b03f4ec6fd2 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1440,8 +1440,10 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
>   		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);
> -			if (!params.altmap)
> +			if (!params.altmap) {
> +				ret = -ENOMEM;
>   				goto error;
> +			}

LGTM, should be squashed into the original commit.

Thanks!
Aneesh Kumar K.V Aug. 9, 2023, 9:19 a.m. UTC | #2
Yang Yingliang <yangyingliang@huawei.com> writes:

> Set error return code to -ENOMEM, when kmalloc() fails.
>
> Fixes: ad3232df3e41 ("mm/memory_hotplug: embed vmem_altmap details in memory block")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

> ---
>  mm/memory_hotplug.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index f8d3e7427e32..1b03f4ec6fd2 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1440,8 +1440,10 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
>  		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);
> -			if (!params.altmap)
> +			if (!params.altmap) {
> +				ret = -ENOMEM;
>  				goto error;
> +			}
>  
>  			memcpy(params.altmap, &mhp_altmap, sizeof(mhp_altmap));
>  		}
> -- 
> 2.25.1
diff mbox series

Patch

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index f8d3e7427e32..1b03f4ec6fd2 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1440,8 +1440,10 @@  int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
 		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);
-			if (!params.altmap)
+			if (!params.altmap) {
+				ret = -ENOMEM;
 				goto error;
+			}
 
 			memcpy(params.altmap, &mhp_altmap, sizeof(mhp_altmap));
 		}