FAILED: patch "[PATCH] firmware: stratix10-svc: fix memory leaks and list corruption" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 9119ceb76e987c2ec2b549ea100e3268ce3a1c7c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072955-cranial-friend-2d3c@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9119ceb76e987c2ec2b549ea100e3268ce3a1c7c Mon Sep 17 00:00:00 2001
From: Tze Yee Ng <[email protected]>
Date: Wed, 24 Jun 2026 03:06:35 -0700
Subject: [PATCH] firmware: stratix10-svc: fix memory leaks and list corruption
bugs
Fix a memory leak when gen_pool_alloc() fails by freeing pmem on the error path. Switch pmem allocation from devm_kzalloc() to kzalloc() with explicit kfree() in the free path to match its list-managed lifetime. Remove the erroneous list_del(&svc_data_mem) which corrupted the list head on failed lookups.
drivers/firmware/stratix10-svc.c +6 -4
@@ -1857,14 +1857,16 @@ void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,struct gen_pool *genpool = chan->ctrl->genpool;size_t s =roundup (size,1 << genpool->min_alloc_order); - pmem =devm_kzalloc (chan->ctrl->dev,sizeof (*pmem),GFP_KERNEL ); + pmem =kzalloc_obj (*pmem);if (!pmem)return ERR_PTR (-ENOMEM );guard (mutex)(&svc_mem_lock); va =gen_pool_alloc (genpool, s); -if (!va) +if (!va) { +kfree (pmem);return ERR_PTR (-ENOMEM ); + }memset ((void *)va,0 , s); pa =gen_pool_virt_to_phys (genpool, va);
@@ -1890,6 +1892,7 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory);void stratix10_svc_free_memory (struct stratix10_svc_chan *chan,void *kaddr) {struct stratix10_svc_data_mem *pmem; +guard (mutex)(&svc_mem_lock);list_for_each_entry (pmem, &svc_data_mem, node)
@@ -1898,10 +1901,9 @@ void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr) (unsigned long)kaddr, pmem->size); pmem->vaddr =NULL ;list_del (&pmem->node); +kfree (pmem);return ; } - -list_del (&svc_data_mem); }EXPORT_SYMBOL_GPL (stratix10_svc_free_memory);
PATCH 1/1 firmware: stratix10-svc: fix memory leaks and list corruption bugs
From: Tze Yee Ng <[email protected]>
Fix a memory leak when gen_pool_alloc() fails by freeing pmem on the error path. Switch pmem allocation from devm_kzalloc() to kzalloc() with explicit kfree() in the free path to match its list-managed lifetime. Remove the erroneous list_del(&svc_data_mem) which corrupted the list head on failed lookups.
--- drivers/firmware/stratix10-svc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +7 -4
@@ -911,13 +911,15 @@ void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,struct gen_pool *genpool = chan->ctrl->genpool;size_t s =roundup (size,1 << genpool->min_alloc_order); - pmem =devm_kzalloc (chan->ctrl->dev,sizeof (*pmem),GFP_KERNEL ); + pmem =kzalloc_obj (*pmem);if (!pmem)return ERR_PTR (-ENOMEM ); va =gen_pool_alloc (genpool, s); -if (!va) +if (!va) { +kfree (pmem);return ERR_PTR (-ENOMEM ); + }memset ((void *)va,0 , s); pa =gen_pool_virt_to_phys (genpool, va);
@@ -944,16 +946,17 @@ void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr) {struct stratix10_svc_data_mem *pmem; +guard (mutex)(&svc_mem_lock); +list_for_each_entry (pmem, &svc_data_mem, node)if (pmem->vaddr == kaddr) {gen_pool_free (chan->ctrl->genpool, (unsigned long )kaddr, pmem->size); pmem->vaddr =NULL ;list_del (&pmem->node); +kfree (pmem);return ; } - -list_del (&svc_data_mem); }EXPORT_SYMBOL_GPL (stratix10_svc_free_memory);
Signature · 1 line
2.43.7
Quoted 76 lines · On 29/7/2026 9:28 pm, [email protected] wrote:
The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkoutFETCH_HEAD
git cherry-pick -x9119ceb76e987c2ec2b549ea100e3268ce3a1c7c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072955-cranial-friend-2d3c@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From
9119ceb76e987c2ec2b549ea100e3268ce3a1c7cMon Sep 17 00:00:00 2001
From: Tze Yee Ng <[email protected]>
Date: Wed, 24 Jun 2026 03:06:35 -0700
Subject: [PATCH] firmware: stratix10-svc: fix memory leaks and list corruption
bugsFix a memory leak when
gen_pool_alloc()fails by freeing pmem on the error path. Switch pmem allocation fromdevm_kzalloc()tokzalloc()with explicitkfree()in the free path to match its list-managed lifetime. Remove the erroneouslist_del(&svc_data_mem)which corrupted the list head on failed lookups.Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")Cc [email protected] # 5.0+Signed-off-by Tze Yee Ng <[email protected]>Signed-off-by Dinh Nguyen <[email protected]>drivers/firmware/stratix10-svc.c +5
-2@@ -1857,14 +1857,16 @@ void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,struct gen_pool *genpool = chan->ctrl->genpool;size_t s =roundup (size,1 << genpool->min_alloc_order); - pmem =devm_kzalloc (chan->ctrl->dev,sizeof (*pmem),GFP_KERNEL ); + pmem =kzalloc_obj (*pmem);if (!pmem)return ERR_PTR (-ENOMEM );guard (mutex)(&svc_mem_lock); va =gen_pool_alloc (genpool, s); -if (!va) +if (!va) { +kfree (pmem);return ERR_PTR (-ENOMEM ); + }memset ((void *)va,0 , s); pa =gen_pool_virt_to_phys (genpool, va);@@ -1890,6 +1892,7 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory);void stratix10_svc_free_memory (struct stratix10_svc_chan *chan,void *kaddr) {struct stratix10_svc_data_mem *pmem; +guard (mutex)(&svc_mem_lock);list_for_each_entry (pmem, &svc_data_mem, node)@@ -1898,10 +1901,9 @@ void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr) (unsigned long)kaddr, pmem->size);
drivers/firmware/stratix10-svc.c void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr) · line 1909
Quoted 10 lines
drivers/firmware/stratix10-svc.c +1
-2pmem->vaddr =NULL ;list_del (&pmem->node); +kfree (pmem);return ; } - -list_del (&svc_data_mem); }EXPORT_SYMBOL_GPL (stratix10_svc_free_memory);
Hi Greg,
Thanks for the detailed steps. I've resolved the conflict and resubmitted the patch.
https://lore.kernel.org/all/[email protected]/
Thanks,
Regards,
Tze Yee
PATCH v2 1/1 firmware: stratix10-svc: fix memory leaks and list corruption bugs
In reply to [email protected]From: Tze Yee Ng <[email protected]>
Fix a memory leak when gen_pool_alloc() fails by freeing pmem on the error path. Switch pmem allocation from devm_kzalloc() to kzalloc() with explicit kfree() in the free path to match its list-managed lifetime. Remove the erroneous list_del(&svc_data_mem) which corrupted the list head on failed lookups.
---
Changes in v2:
- Replaced kzalloc_obj() with kzalloc(sizeof(*pmem), GFP_KERNEL).
- Dropped the stray guard(mutex)(&svc_mem_lock) which is added accidentally when rebase.
--- drivers/firmware/stratix10-svc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +5 -4
@@ -911,13 +911,15 @@ void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,struct gen_pool *genpool = chan->ctrl->genpool;size_t s =roundup (size,1 << genpool->min_alloc_order); - pmem =devm_kzalloc (chan->ctrl->dev,sizeof (*pmem),GFP_KERNEL ); + pmem =kzalloc (sizeof (*pmem),GFP_KERNEL );if (!pmem)return ERR_PTR (-ENOMEM ); va =gen_pool_alloc (genpool, s); -if (!va) +if (!va) { +kfree (pmem);return ERR_PTR (-ENOMEM ); + }memset ((void *)va,0 , s); pa =gen_pool_virt_to_phys (genpool, va);
@@ -950,10 +952,9 @@ void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr) (unsigned long)kaddr, pmem->size); pmem->vaddr =NULL ;list_del (&pmem->node); +kfree (pmem);return ; } - -list_del (&svc_data_mem); }EXPORT_SYMBOL_GPL (stratix10_svc_free_memory);
Signature · 1 line
2.43.7