]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
coresight: fix missing error code when trace ID is invalid
authorJie Gan <jie.gan@oss.qualcomm.com>
Tue, 12 May 2026 01:56:07 +0000 (09:56 +0800)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Tue, 12 May 2026 15:33:23 +0000 (16:33 +0100)
When coresight_path_assign_trace_id() cannot assign a valid trace ID,
coresight_enable_sysfs() takes the err_path goto with ret still 0,
returning success to the caller despite no trace session being started.

Change coresight_path_assign_trace_id() to return int, moving the
IS_VALID_CS_TRACE_ID() check inside it so it returns -EINVAL on failure
and 0 on success. Update both callers to propagate this return value
directly instead of inspecting path->trace_id after the call.

Fixes: d87d76d823d1 ("Coresight: Allocate trace ID after building the path")
Reviewed-by: James Clark <james.clark@linaro.org>
Reviewed-by: Richard Cheng <icheng@nvidia.com>
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
Reviewed-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20260512-fix-trace-id-error-v4-1-eb3de789767a@oss.qualcomm.com
drivers/hwtracing/coresight/coresight-core.c
drivers/hwtracing/coresight/coresight-etm-perf.c
drivers/hwtracing/coresight/coresight-priv.h
drivers/hwtracing/coresight/coresight-sysfs.c

index 46f247f73cf64a97b9353b84ba5b76b991676f5f..2105bb8139407bb579ed2517c1eecccda0a9c2d7 100644 (file)
@@ -739,8 +739,8 @@ static int coresight_get_trace_id(struct coresight_device *csdev,
  * Call this after creating the path and before enabling it. This leaves
  * the trace ID set on the path, or it remains 0 if it couldn't be assigned.
  */
-void coresight_path_assign_trace_id(struct coresight_path *path,
-                                   enum cs_mode mode)
+int coresight_path_assign_trace_id(struct coresight_path *path,
+                                  enum cs_mode mode)
 {
        struct coresight_device *sink = coresight_get_sink(path);
        struct coresight_node *nd;
@@ -750,15 +750,18 @@ void coresight_path_assign_trace_id(struct coresight_path *path,
                /* Assign a trace ID to the path for the first device that wants to do it */
                trace_id = coresight_get_trace_id(nd->csdev, mode, sink);
 
-               /*
-                * 0 in this context is that it didn't want to assign so keep searching.
-                * Non 0 is either success or fail.
-                */
-               if (trace_id != 0) {
-                       path->trace_id = trace_id;
-                       return;
-               }
+               /* 0 means the device has no ID assignment, so keep searching */
+               if (trace_id == 0)
+                       continue;
+
+               if (!IS_VALID_CS_TRACE_ID(trace_id))
+                       return -EINVAL;
+
+               path->trace_id = trace_id;
+               return 0;
        }
+
+       return -EINVAL;
 }
 
 /**
index f85dedf89a3f9e85d568ca4c320fa6fa6d9059ff..89ba7c9a66137007a9f39efb3f04d55e8237eacb 100644 (file)
@@ -324,6 +324,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
        struct coresight_device *sink = NULL;
        struct coresight_device *user_sink = NULL, *last_sink = NULL;
        struct etm_event_data *event_data = NULL;
+       int ret;
 
        event_data = alloc_event_data(cpu);
        if (!event_data)
@@ -420,8 +421,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
                }
 
                /* ensure we can allocate a trace ID for this CPU */
-               coresight_path_assign_trace_id(path, CS_MODE_PERF);
-               if (!IS_VALID_CS_TRACE_ID(path->trace_id)) {
+               ret = coresight_path_assign_trace_id(path, CS_MODE_PERF);
+               if (ret) {
                        cpumask_clear_cpu(cpu, mask);
                        coresight_release_path(path);
                        continue;
index 1ea882dffd703b2873e41b4ce0c2564d2ce9bbad..34c7e792adbd9933e48ab710b7b5894f22c72eb8 100644 (file)
@@ -153,7 +153,7 @@ int coresight_make_links(struct coresight_device *orig,
 void coresight_remove_links(struct coresight_device *orig,
                            struct coresight_connection *conn);
 u32 coresight_get_sink_id(struct coresight_device *csdev);
-void coresight_path_assign_trace_id(struct coresight_path *path,
+int coresight_path_assign_trace_id(struct coresight_path *path,
                                   enum cs_mode mode);
 
 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X)
index d2a6ed8bcc74d64dccc735463f14790b4e80d101..b6a870399e83419dce0552099562fa3ae7b2bd69 100644 (file)
@@ -211,8 +211,8 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
                goto out;
        }
 
-       coresight_path_assign_trace_id(path, CS_MODE_SYSFS);
-       if (!IS_VALID_CS_TRACE_ID(path->trace_id))
+       ret = coresight_path_assign_trace_id(path, CS_MODE_SYSFS);
+       if (ret)
                goto err_path;
 
        ret = coresight_enable_path(path, CS_MODE_SYSFS);