Move source helper disabling to coresight_disable_path() to pair it with coresight_enable_path().
In coresight_enable_path(), if enabling a node fails, iterate to the next node (which is the last successfully enabled node) and pass it to coresight_disable_path() for rollback. If the failed node is the last node on the path, no device is actually enabled, so bail out directly.
As a result, coresight_disable_source() only controls the source, leaving the associated helpers to be managed as part of path. Update the comment to reflect this change.
Signed-off-by: Leo Yan leo.yan@arm.com --- drivers/hwtracing/coresight/coresight-core.c | 32 ++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index 8384d1466b4cc74f7e463388862c58c86b74be79..e9fcb82a2abcd52d23a3bed14ca14823dc49df6b 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -388,19 +388,12 @@ static void coresight_disable_helpers(struct coresight_device *csdev, }
/* - * Helper function to call source_ops(csdev)->disable and also disable the - * helpers. - * - * There is an imbalance between coresight_enable_path() and - * coresight_disable_path(). Enabling also enables the source's helpers as part - * of the path, but disabling always skips the first item in the path (which is - * the source), so sources and their helpers don't get disabled as part of that - * function and we need the extra step here. + * coresight_disable_source() only disables the source, but do nothing for + * the associated helpers, which are controlled as part of the path. */ void coresight_disable_source(struct coresight_device *csdev, void *data) { source_ops(csdev)->disable(csdev, data); - coresight_disable_helpers(csdev, NULL); } EXPORT_SYMBOL_GPL(coresight_disable_source);
@@ -451,7 +444,7 @@ static void coresight_disable_path_from(struct coresight_path *path, if (!nd) nd = list_first_entry(&path->path_list, struct coresight_node, link);
- list_for_each_entry_continue(nd, &path->path_list, link) { + list_for_each_entry_from(nd, &path->path_list, link) { csdev = nd->csdev; type = csdev->type;
@@ -471,12 +464,6 @@ static void coresight_disable_path_from(struct coresight_path *path, coresight_disable_sink(csdev); break; case CORESIGHT_DEV_TYPE_SOURCE: - /* - * We skip the first node in the path assuming that it - * is the source. So we don't expect a source device in - * the middle of a path. - */ - WARN_ON(1); break; case CORESIGHT_DEV_TYPE_LINK: parent = list_prev_entry(nd, link)->csdev; @@ -523,12 +510,16 @@ int coresight_enable_path(struct coresight_path *path, enum cs_mode mode) { int ret = 0; u32 type; - struct coresight_node *nd; + struct coresight_node *nd, *last; struct coresight_device *csdev, *parent, *child; struct coresight_device *source;
source = coresight_get_source(path); - list_for_each_entry_reverse(nd, &path->path_list, link) { + + last = list_last_entry(&path->path_list, struct coresight_node, link); + + nd = last; + list_for_each_entry_from_reverse(nd, &path->path_list, link) { csdev = nd->csdev; type = csdev->type;
@@ -582,6 +573,11 @@ int coresight_enable_path(struct coresight_path *path, enum cs_mode mode) err_disable_helpers: coresight_disable_helpers(csdev, path); err_disable_path: + /* No device is actually enabled */ + if (nd == last) + goto out; + + nd = list_next_entry(nd, link); coresight_disable_path_from(path, nd); goto out; }