Skip to contentSkip to conversation

accel/habanalabs: Use common error handling code in hl_cb_alloc()

PATCH New Markus Elfring 1 participant 1 message Jun 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 accel/habanalabs: Use common error handling code in hl_cb_alloc()

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jun 2026 20:30:23 +0200

Use an additional label so that a bit of exception handling can be better reused at the end of this function implementation.

This issue was detected by using the Coccinelle software.

---
 drivers/accel/habanalabs/common/command_buffer.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/accel/habanalabs/common/command_buffer.c +7 -6
index e929db8bc023..980c9e4f96c6 100644
@@ -126,10 +126,8 @@ static struct hl_cb *hl_cb_alloc(struct hl_device *hdev, u32 cb_size,
 
 	if (internal_cb) {
 		p = (void *) gen_pool_alloc(hdev->internal_cb_pool, cb_size);
-		if (!p) {
-			kfree(cb);
-			return NULL;
-		}
+		if (!p)
+			goto free_cb;
 
 		cb_offset = p - hdev->internal_cb_pool_virt_addr;
 		cb->is_internal = true;
@@ -147,14 +145,17 @@ static struct hl_cb *hl_cb_alloc(struct hl_device *hdev, u32 cb_size,
 		dev_err(hdev->dev,
 			"failed to allocate %d of dma memory for CB\n",
 			cb_size);
-		kfree(cb);
-		return NULL;
+		goto free_cb;
 	}
 
 	cb->kernel_address = p;
 	cb->size = cb_size;
 
 	return cb;
+
+free_cb:
+	kfree(cb);
+	return NULL;
 }
 
 struct hl_cb_mmap_mem_alloc_args {
Signature · 1 line
2.54.0