[PATCH] accel/rocket: Count a core only after it is initialized

From: Sidong Yang

Date: Sat Dec 05 2026 - 21:54:31 EST


rocket_probe() increments rdev->num_cores before rocket_core_init() has
called drm_sched_init() for that core, and the DRM device is registered
when the first core probes. An open() during the probe of a later core
therefore passes an uninitialized scheduler to drm_sched_entity_init().
That is accepted today, but [1] is going to reject it with -EINVAL.

rocket_job_open() also reads num_cores separately for allocating the
scheduler list, for filling it and for passing it on, while a probe can
change it in between.

Count the core once rocket_core_init() has succeeded and read num_cores
once in rocket_job_open(). A file that is opened while cores are still
probing only gets the cores that are ready at that time.

Link: https://lore.kernel.org/r/20261203140128.6813-7-tvrtko.ursulin@xxxxxxxxxx [1]
Signed-off-by: Sidong Yang <sidong.yang@xxxxxxxxxx>
---
drivers/accel/rocket/rocket_drv.c | 14 +++++++++-----
drivers/accel/rocket/rocket_job.c | 10 ++++++----
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index 5d7805c41dc3..9252bf51ba34 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -181,19 +181,23 @@ static int rocket_probe(struct platform_device *pdev)
rdev->cores[core].dev = &pdev->dev;
rdev->cores[core].index = core;

- rdev->num_cores++;
-
ret = rocket_core_init(&rdev->cores[core]);
if (ret) {
- rdev->num_cores--;
-
if (rdev->num_cores == 0) {
rocket_device_fini(rdev);
rdev = NULL;
}
+
+ return ret;
}

- return ret;
+ /*
+ * The DRM device is already registered: count the core only now that
+ * it can run jobs.
+ */
+ smp_store_release(&rdev->num_cores, core + 1);
+
+ return 0;
}

static int find_core_for_dev(struct device *dev);
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 9dc3c1814ceb..c9aca3fcd2f0 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -533,21 +533,23 @@ void rocket_job_fini(struct rocket_core *core)
int rocket_job_open(struct rocket_file_priv *rocket_priv)
{
struct rocket_device *rdev = rocket_priv->rdev;
- struct drm_gpu_scheduler **scheds = kmalloc_objs(*scheds,
- rdev->num_cores);
+ /* Cores can still be probing, list the ones that are ready. */
+ unsigned int num_cores = smp_load_acquire(&rdev->num_cores);
+ struct drm_gpu_scheduler **scheds;
unsigned int core;
int ret;

+ scheds = kmalloc_objs(*scheds, num_cores);
if (!scheds)
return -ENOMEM;

- for (core = 0; core < rdev->num_cores; core++)
+ for (core = 0; core < num_cores; core++)
scheds[core] = &rdev->cores[core].sched;

ret = drm_sched_entity_init(&rocket_priv->sched_entity,
DRM_SCHED_PRIORITY_NORMAL,
scheds,
- rdev->num_cores, NULL);
+ num_cores, NULL);
if (ret)
kfree(scheds);
else
--
2.53.0