Skip to contentSkip to conversation

firmware: stratix10-svc: Fix devm memory leak in Intel service layer

PATCH New Kuhanh Murugasen Krishnan 1 participant 1 message Nov 4, 2025 1 message not in the archive Intel STRATIX10 firmware drivers

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 firmware: stratix10-svc: Fix devm memory leak in Intel service layer

In reply to a message not in the archive

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.

---
 drivers/firmware/stratix10-svc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +9 -4
index 3acfa067c5dd..17f4c9359dad 100644
@@ -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