public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: "dri-devel@linux-kernel"@vger.kernel.org
Cc: Koby Elbaz <koby.elbaz@intel.com>,
	Konstantin Sinyuk <konstantin.sinyuk@intel.com>,
	Oded Gabbay <ogabbay@kernel.org>,
	dri-devel@lists.freedesktop.org (open list:HABANALABS PCI DRIVER),
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] accel/habanalabs: kzalloc + kcalloc to kzalloc_flex
Date: Tue, 10 Mar 2026 17:44:59 -0700	[thread overview]
Message-ID: <20260311004459.32567-1-rosenp@gmail.com> (raw)

Simplifies allocation by using a flexible array member.

No need to free separately.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 .../habanalabs/common/command_submission.c    | 20 ++-----------------
 drivers/accel/habanalabs/common/habanalabs.h  |  2 +-
 2 files changed, 3 insertions(+), 19 deletions(-)

diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c
index ba4257bda77b..ba99329eacbd 100644
--- a/drivers/accel/habanalabs/common/command_submission.c
+++ b/drivers/accel/habanalabs/common/command_submission.c
@@ -809,7 +809,6 @@ static void cs_do_release(struct kref *ref)

 	hl_fence_put(cs->fence);

-	kfree(cs->jobs_in_queue_cnt);
 	kfree(cs);
 }

@@ -907,9 +906,9 @@ static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx,

 	cntr = &hdev->aggregated_cs_counters;

-	cs = kzalloc_obj(*cs, GFP_ATOMIC);
+	cs = kzalloc_flex(*cs, jobs_in_queue_cnt, hdev->asic_prop.max_queues, GFP_ATOMIC);
 	if (!cs)
-		cs = kzalloc_obj(*cs);
+		cs = kzalloc_flex(*cs, jobs_in_queue_cnt, hdev->asic_prop.max_queues);

 	if (!cs) {
 		atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
@@ -947,19 +946,6 @@ static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx,
 		goto free_cs;
 	}

-	cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues,
-			sizeof(*cs->jobs_in_queue_cnt), GFP_ATOMIC);
-	if (!cs->jobs_in_queue_cnt)
-		cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues,
-				sizeof(*cs->jobs_in_queue_cnt), GFP_KERNEL);
-
-	if (!cs->jobs_in_queue_cnt) {
-		atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
-		atomic64_inc(&cntr->out_of_mem_drop_cnt);
-		rc = -ENOMEM;
-		goto free_cs_cmpl;
-	}
-
 	cs_cmpl->hdev = hdev;
 	cs_cmpl->type = cs->type;
 	spin_lock_init(&cs_cmpl->lock);
@@ -1014,8 +1000,6 @@ static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx,

 free_fence:
 	spin_unlock(&ctx->cs_lock);
-	kfree(cs->jobs_in_queue_cnt);
-free_cs_cmpl:
 	kfree(cs_cmpl);
 free_cs:
 	kfree(cs);
diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h
index d94c2ba22a6a..dc13c8a6f242 100644
--- a/drivers/accel/habanalabs/common/habanalabs.h
+++ b/drivers/accel/habanalabs/common/habanalabs.h
@@ -2046,7 +2046,6 @@ struct hl_userptr {
  * @encaps_signals: true if this CS has encaps reserved signals.
  */
 struct hl_cs {
-	u16			*jobs_in_queue_cnt;
 	struct hl_ctx		*ctx;
 	struct list_head	job_list;
 	spinlock_t		job_lock;
@@ -2080,6 +2079,7 @@ struct hl_cs {
 	u8			staged_cs;
 	u8			skip_reset_on_timeout;
 	u8			encaps_signals;
+	u16			jobs_in_queue_cnt[];
 };

 /**
--
2.53.0


             reply	other threads:[~2026-03-11  0:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11  0:44 Rosen Penev [this message]
2026-03-11  2:54 ` Claude review: accel/habanalabs: kzalloc + kcalloc to kzalloc_flex Claude Code Review Bot
2026-03-11  2:54 ` Claude Code Review Bot

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=20260311004459.32567-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=dri-devel@lists.freedesktop.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