From: Markus Elfring <Markus.Elfring@web.de>
To: dri-devel@lists.freedesktop.org, Kees Cook <kees@kernel.org>,
Koby Elbaz <koby.elbaz@intel.com>,
Konstantin Sinyuk <konstantin.sinyuk@intel.com>,
Oded Gabbay <ogabbay@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] accel/habanalabs: Use common error handling code in hl_cb_alloc()
Date: Wed, 10 Jun 2026 20:35:46 +0200 [thread overview]
Message-ID: <c40e9f00-ac4d-4eb5-bbc4-a6c37bf630b8@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/accel/habanalabs/common/command_buffer.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/accel/habanalabs/common/command_buffer.c b/drivers/accel/habanalabs/common/command_buffer.c
index e929db8bc023..980c9e4f96c6 100644
--- a/drivers/accel/habanalabs/common/command_buffer.c
+++ b/drivers/accel/habanalabs/common/command_buffer.c
@@ -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 {
--
2.54.0
reply other threads:[~2026-06-10 18:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c40e9f00-ac4d-4eb5-bbc4-a6c37bf630b8@web.de \
--to=markus.elfring@web.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=kees@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=koby.elbaz@intel.com \
--cc=konstantin.sinyuk@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ogabbay@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®