From 3923aec1fbd09970b3155c3cbbc1221a7d4bb5ca Mon Sep 17 00:00:00 2001 From: Jie Gan Date: Tue, 12 May 2026 09:56:07 +0800 Subject: [PATCH 1/2] BACKPORT: coresight: fix missing error code when trace ID is invalid 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 Reviewed-by: Richard Cheng Signed-off-by: Jie Gan Reviewed-by: Leo Yan Signed-off-by: Suzuki K Poulose Link: https://lore.kernel.org/r/20260512-fix-trace-id-error-v4-1-eb3de789767a@oss.qualcomm.com --- drivers/hwtracing/coresight/coresight-core.c | 23 +++++++++++-------- .../hwtracing/coresight/coresight-etm-perf.c | 5 ++-- drivers/hwtracing/coresight/coresight-priv.h | 2 +- drivers/hwtracing/coresight/coresight-sysfs.c | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index 7db1801d74320..94842691ce9d1 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -792,8 +792,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; @@ -803,15 +803,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; } /** diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 5c256af6e54af..accf101779de8 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -321,6 +321,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) @@ -418,8 +419,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; diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index f80122827934d..c55890aadc2d9 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -154,7 +154,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); int coresight_get_in_port_dest(struct coresight_device *src, struct coresight_device *dest); diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c index 5e52324aa9ac7..c5f3fc2b5135f 100644 --- a/drivers/hwtracing/coresight/coresight-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-sysfs.c @@ -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, NULL); From f56247525af148c1250de9cbd63fc86e1cb123a2 Mon Sep 17 00:00:00 2001 From: Jie Gan Date: Wed, 2 Sep 2026 17:41:43 +0800 Subject: [PATCH 2/2] FROMLIST: coresight: tnoc: fix trace ID path assignment failure on non-AMBA tnoc For a tnoc device not on the AMBA bus, atid was set to -EOPNOTSUPP. trace_noc_id() returns this value directly to coresight_path_assign_trace_id(), which only treats a literal 0 return as "this device has no ID, keep searching the path" - any other value is checked against IS_VALID_CS_TRACE_ID() and rejected. A negative atid therefore made path assignment fail with -EINVAL instead of falling through to the next device in the path that could supply a valid trace ID. Use 0, the same sentinel coresight_path_assign_trace_id() already recognizes as "not allocated", instead of -EOPNOTSUPP. Link: https://lore.kernel.org/all/20260902-fix-trace-id-error-in-tnoc-driver-v2-1-73669a947297@oss.qualcomm.com/ Fixes: 5799dee92dc2 ("coresight-tnoc: add platform driver to support Interconnect TNOC") Signed-off-by: Jie Gan --- drivers/hwtracing/coresight/coresight-tnoc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tnoc.c b/drivers/hwtracing/coresight/coresight-tnoc.c index e832233420592..80a7c3b2f1416 100644 --- a/drivers/hwtracing/coresight/coresight-tnoc.c +++ b/drivers/hwtracing/coresight/coresight-tnoc.c @@ -53,8 +53,8 @@ static void trace_noc_enable_hw(struct trace_noc_drvdata *drvdata) { u32 val; - /* No valid ATID, simply enable the unit */ - if (drvdata->atid == -EOPNOTSUPP) { + /* 0 means no ID assignment, simply enable the unit */ + if (drvdata->atid == 0) { writel(TRACE_NOC_CTRL_PORTEN, drvdata->base + TRACE_NOC_CTRL); return; } @@ -133,10 +133,8 @@ static int trace_noc_init_default_data(struct trace_noc_drvdata *drvdata) { int atid; - if (of_device_is_compatible(drvdata->dev->of_node, "qcom,coresight-itnoc")) { - drvdata->atid = -EOPNOTSUPP; + if (of_device_is_compatible(drvdata->dev->of_node, "qcom,coresight-itnoc")) return 0; - } atid = coresight_trace_id_get_system_id(); if (atid < 0) @@ -169,7 +167,7 @@ static umode_t trace_id_is_visible(struct kobject *kobj, struct device *dev = kobj_to_dev(kobj); struct trace_noc_drvdata *drvdata = dev_get_drvdata(dev->parent); - if (attr == &dev_attr_traceid.attr && drvdata->atid < 0) + if (attr == &dev_attr_traceid.attr && drvdata->atid == 0) return 0; return attr->mode;