]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
coresight: Get parent device reference after sink ID map allocation
authorLeo Yan <leo.yan@arm.com>
Mon, 9 Feb 2026 12:44:34 +0000 (12:44 +0000)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Wed, 25 Feb 2026 11:14:44 +0000 (11:14 +0000)
The parent device's reference count is incremented before allocating the
sink ID map.  If the allocation fails, the reference count is not
decremented, preventing proper cleanup.

Fix this by incrementing the reference count only after the sink ID map
is successfully allocated.

Fixes: 5ad628a76176 ("coresight: Use per-sink trace ID maps for Perf sessions")
Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20260209-arm_coresight_refactor_dev_register-v4-2-62d6042f76f7@arm.com
drivers/hwtracing/coresight/coresight-core.c

index 6881fdc5da928637e1404a5db18c537ddf8de776..e2c0f971eccffb303995e0af854d6d92448e4ff9 100644 (file)
@@ -1349,12 +1349,6 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
        csdev->dev.parent = desc->dev;
        csdev->dev.release = coresight_device_release;
        csdev->dev.bus = &coresight_bustype;
-       /*
-        * Hold the reference to our parent device. This will be
-        * dropped only in coresight_device_release().
-        */
-       csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev));
-       dev_set_name(&csdev->dev, "%s", desc->name);
 
        if (csdev->type == CORESIGHT_DEV_TYPE_SINK ||
            csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) {
@@ -1366,6 +1360,14 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
                        goto err_out;
                }
        }
+
+       /*
+        * Hold the reference to our parent device. This will be
+        * dropped only in coresight_device_release().
+        */
+       csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev));
+       dev_set_name(&csdev->dev, "%s", desc->name);
+
        /*
         * Make sure the device registration and the connection fixup
         * are synchronised, so that we don't see uninitialised devices