public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: accel: ethosu: Fix job submit error clean-up refcount underflows
Date: Thu, 19 Feb 2026 09:57:30 +1000	[thread overview]
Message-ID: <review-patch1-20260218-ethos-fixes-v1-1-be3fa3ea9a30@kernel.org> (raw)
In-Reply-To: <20260218-ethos-fixes-v1-1-be3fa3ea9a30@kernel.org>

Patch Review

The commit message accurately describes the problem: when job submit fails before the job is queued (e.g. during GEM buffer bounds checks), calling `ethosu_job_put` leads to `ethosu_job_cleanup` which calls `pm_runtime_put_autosuspend` without a corresponding `pm_runtime_resume_and_get`. The fix correctly splits the cleanup into `ethosu_job_err_cleanup` (for pre-queue failures) and `ethosu_job_cleanup` (for post-queue teardown via kref).

However, there is a memory leak. `done_fence` is separately allocated:

> +	ejob->done_fence = kzalloc(sizeof(*ejob->done_fence), GFP_KERNEL);
> +	if (!ejob->done_fence) {
> +		ret = -ENOMEM;
> +		goto out_cleanup_job;
> +	}

But `ethosu_job_err_cleanup` does not free it:

> +static void ethosu_job_err_cleanup(struct ethosu_job *job)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < job->region_cnt; i++)
> +		drm_gem_object_put(job->region_bo[i]);
> +
> +	drm_gem_object_put(job->cmd_bo);
> +
> +	kfree(job);
> +}

Every error path through `out_cleanup_job` or `out_put_job` will leak the `done_fence` allocation. A `kfree(job->done_fence)` should be added to `ethosu_job_err_cleanup` before `kfree(job)`. (This was also leaked in the original code since `dma_fence_put` on a never-initialized fence doesn't actually free it, but this patch should fix it while it's restructuring the cleanup.)

A second concern is the `out_cleanup_job` label when reached from the `done_fence` allocation failure:

> out_cleanup_job:
> 	if (ret)
> 		drm_sched_job_cleanup(&ejob->base);

When `done_fence` allocation fails, we jump to `out_cleanup_job` and call `drm_sched_job_cleanup(&ejob->base)` even though `drm_sched_job_init` has not yet been called. The job was kzalloc'd so `ejob->base` is zeroed, but calling `drm_sched_job_cleanup` on an uninitialized scheduler job is at best relying on implementation details. This is a pre-existing issue not introduced by this patch, but it might be worth fixing while restructuring the error paths — perhaps by jumping to `out_put_job` instead.

The success path change looks correct:

> 	ret = ethosu_job_push(ejob);
> +	if (!ret) {
> +		ethosu_job_put(ejob);
> +		return 0;
> +	}

On success, `ethosu_job_push` has already called `pm_runtime_resume_and_get` and taken a kref, so `ethosu_job_put` drops the initial reference correctly.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-02-18 23:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18 22:21 [PATCH 0/3] accel: ethosu: Runtime PM refcounting and cmd stream validation fixes Rob Herring (Arm)
2026-02-18 22:21 ` [PATCH 1/3] accel: ethosu: Fix job submit error clean-up refcount underflows Rob Herring (Arm)
2026-02-18 23:57   ` Claude Code Review Bot [this message]
2026-02-18 22:21 ` [PATCH 2/3] accel: ethosu: Fix NPU_OP_ELEMENTWISE validation with scalar Rob Herring (Arm)
2026-02-18 23:57   ` Claude review: " Claude Code Review Bot
2026-02-18 22:21 ` [PATCH 3/3] accel: ethosu: Handle possible underflow in IFM size calculations Rob Herring (Arm)
2026-02-18 23:57   ` Claude review: " Claude Code Review Bot
2026-02-18 23:57 ` Claude review: accel: ethosu: Runtime PM refcounting and cmd stream validation fixes 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=review-patch1-20260218-ethos-fixes-v1-1-be3fa3ea9a30@kernel.org \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /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