firmware: stratix10-svc: Fix devm memory leak in Intel service layer
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 firmware: stratix10-svc: Fix devm memory leak in Intel service layer
From: "Murugasen Krishnan, Kuhanh" <[email protected]>
The Intel service layer is a static driver that remains active for the entire runtime of the target device. Using devm_kzalloc() in this case is inappropriate, as the managed memory would be freed automatically when the device is removed, which never happens for this static driver.
Replace devm_kzalloc() with kzalloc() to ensure the allocated memory persists as long as the service layer is active. Also add corresponding kfree() calls on error and cleanup paths to avoid leaks.
Suggested-by Tanmay Kathpalia <[email protected]>
Reviewed-by Tanmay Kathpalia <[email protected]>
Signed-off-by Mahesh Rao <[email protected]>
Signed-off-by Murugasen Krishnan, Kuhanh <[email protected]>
--- drivers/firmware/stratix10-svc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +9 -4
@@ -1798,14 +1798,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 (sizeof (*pmem),GFP_KERNEL );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);
@@ -1831,6 +1833,10 @@ 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; + +if (!chan || !kaddr) +return ; +guard (mutex)(&svc_mem_lock);list_for_each_entry (pmem, &svc_data_mem, node)
@@ -1839,10 +1845,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.25.1