2023-01-29 04:13:14

by Tong Tiangen

[permalink] [raw]
Subject: [PATCH -next] memory tier: release the new_memtier in find_create_memory_tier()

In find_create_memory_tier(), if failed to register device, then we should
release new_memtier from the tier list and put device instead of memtier.

Fixes: 9832fb87834e ("mm/demotion: expose memory tier details via sysfs")
Signed-off-by: Tong Tiangen <[email protected]>
---
mm/memory-tiers.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index c734658c6242..e593e56e530b 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -211,8 +211,8 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty

ret = device_register(&new_memtier->dev);
if (ret) {
- list_del(&memtier->list);
- put_device(&memtier->dev);
+ list_del(&new_memtier->list);
+ put_device(&new_memtier->dev);
return ERR_PTR(ret);
}
memtier = new_memtier;
--
2.25.1



2023-01-30 08:19:00

by Huang, Ying

[permalink] [raw]
Subject: Re: [PATCH -next] memory tier: release the new_memtier in find_create_memory_tier()

Tong Tiangen <[email protected]> writes:

> In find_create_memory_tier(), if failed to register device, then we should
> release new_memtier from the tier list and put device instead of memtier.
>
> Fixes: 9832fb87834e ("mm/demotion: expose memory tier details via sysfs")
> Signed-off-by: Tong Tiangen <[email protected]>
> ---
> mm/memory-tiers.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
> index c734658c6242..e593e56e530b 100644
> --- a/mm/memory-tiers.c
> +++ b/mm/memory-tiers.c
> @@ -211,8 +211,8 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty
>
> ret = device_register(&new_memtier->dev);
> if (ret) {
> - list_del(&memtier->list);
> - put_device(&memtier->dev);
> + list_del(&new_memtier->list);
> + put_device(&new_memtier->dev);
> return ERR_PTR(ret);
> }
> memtier = new_memtier;

Good catch! Thanks!

I think that this should be in stable since v6.1.

Best Regards,
Huang, Ying