From: sashiko-bot@kernel.org
To: "Mayuresh Chitale" <mayuresh.chitale@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v7 02/14] hwtracing: gtrace: Initial implementation of gtrace framework
Date: Thu, 26 Nov 2026 10:15:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-235261@kernel.org> (raw)
In-Reply-To: <50c430c6adecd57e4637c643ee3cf78309608d34.1795512532.git.mayuresh.chitale@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] hwtracing: gtrace: unchecked 0 return in
gtrace_setup_inconns_from_outconns()
- [Medium] hwtracing: gtrace: refcount leak overwriting
gtrace_cpu_source_comp
--
commit 8c67f8e6b67201b62b509964fb9df143def486d0
Author: Anup Patel <anup.patel@oss.qualcomm.com>
hwtracing: gtrace: Initial implementation of gtrace framework
This commit introduces the core generic hardware trace (gtrace) bus and
framework for registering trace components, building their connection
topology, and accessing hardware registers.
> diff --git a/drivers/hwtracing/gtrace/gtrace-core.c b/drivers/hwtracing/gtrace/gtrace-core.c
> new file mode 100644
> index 0000000000000..57554d5eb98d3
> --- /dev/null
> +++ b/drivers/hwtracing/gtrace/gtrace-core.c
> @@ -0,0 +1,524 @@
[ ... ]
> +static int gtrace_setup_inconn(struct device *dev, void *data)
> +{
> + struct gtrace_component *comp = to_gtrace_component(dev);
> + struct gtrace_platform_data *pdata = comp->pdata;
> + struct gtrace_connection *conn = data;
> + int i;
> +
> + if (device_match_fwnode(&comp->dev, conn->dest_fwnode)) {
> + for (i = 0; i < pdata->nr_inconns; i++) {
> + if (pdata->inconns[i])
> + continue;
> + pdata->inconns[i] = conn;
> + return 1;
> + }
> + return -ENOSPC;
> + }
> +
> + return 0;
> +}
> +
> +static int gtrace_setup_inconns_from_outconns(struct gtrace_component *comp)
> +{
> + struct gtrace_platform_data *pdata = comp->pdata;
> + struct gtrace_connection *conn;
> + int i, ret;
> +
> + lockdep_assert_held(>race_mutex);
> +
> + for (i = 0; i < pdata->nr_outconns; i++) {
> + conn = pdata->outconns[i];
> + ret = bus_for_each_dev(>race_bustype, NULL, conn, gtrace_setup_inconn);
> + if (ret < 0) {
> + gtrace_cleanup_inconns_from_outconns(comp);
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
[Severity: High]
Can gtrace_setup_inconns_from_outconns() silently succeed when
bus_for_each_dev() returns 0 because no registered component matched
conn->dest_fwnode?
The caller resolves conn->dest_comp via gtrace_find_by_fwnode() before
calling gtrace_register_component(), which drops gtrace_mutex in between.
If conn->dest_comp is unregistered in that window (or if conn->dest_fwnode
does not match any device on gtrace_bustype), bus_for_each_dev() returns 0.
Checking only ret < 0 lets registration succeed without linking conn into
any destination component's inconns[] array, leaving conn->dest_comp
pointing to an unregistered component whose pdata has been freed.
Also, gtrace_setup_inconn() and gtrace_cleanup_inconn() match devices only
by conn->dest_fwnode without checking comp == conn->dest_comp. If the
destination device was unbound and rebound in that window, conn is attached
to the new component while conn->dest_comp still holds a reference to the
old one; when gtrace_cleanup_inconns() later runs on the new component, it
calls gtrace_put_component(comp) and underflows the new component's
reference count while leaking the old conn->dest_comp reference.
[ ... ]
> + if (bound_cpu >= 0 && is_source) {
> + gtrace_get_component(comp);
> + per_cpu(gtrace_cpu_source_comp, bound_cpu) = comp;
> + }
> +
> + mutex_unlock(>race_mutex);
> +
> + return comp;
> +
> +err_out_unlock:
> + mutex_unlock(>race_mutex);
> +err_out:
> + return ERR_PTR(ret);
> +}
> +EXPORT_SYMBOL_GPL(gtrace_register_component);
> +
> +void gtrace_unregister_component(struct gtrace_component *comp)
> +{
> + struct gtrace_platform_data *pdata = comp->pdata;
> +
> + mutex_lock(>race_mutex);
> +
> + if (pdata->bound_cpu >= 0 &&
> + per_cpu(gtrace_cpu_source_comp, pdata->bound_cpu) == comp) {
> + per_cpu(gtrace_cpu_source_comp, pdata->bound_cpu) = NULL;
> + gtrace_put_component(comp);
> + }
[Severity: Medium]
Does gtrace_register_component() leak the existing component reference if a
second source component is registered for the same bound_cpu?
Each component gets a unique type_idx device name suffix, so
device_register() succeeds even if per_cpu(gtrace_cpu_source_comp,
bound_cpu) is already populated. Overwriting the per-CPU pointer without
checking if it is already non-NULL causes gtrace_unregister_component() on
the earlier component to see per_cpu(gtrace_cpu_source_comp,
pdata->bound_cpu) != comp and skip gtrace_put_component().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795512532.git.mayuresh.chitale@oss.qualcomm.com?part=2
next prev parent reply other threads:[~2026-11-26 10:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 9:55 [PATCH v7 00/14] Linux RISC-V trace framework and drivers Mayuresh Chitale
2026-11-26 9:55 ` [PATCH v7 01/14] dt-bindings: Add RISC-V trace component bindings Mayuresh Chitale
2026-11-26 10:07 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 02/14] hwtracing: gtrace: Initial implementation of gtrace framework Mayuresh Chitale
2026-11-26 10:15 ` sashiko-bot [this message]
2026-11-26 9:55 ` [PATCH v7 03/14] gtrace: Add RISC-V platform driver for the " Mayuresh Chitale
2026-11-26 10:12 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 04/14] gtrace: Add functions to create/destroy a trace component path Mayuresh Chitale
2026-11-26 10:07 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 05/14] gtrace: Add functions to start/stop tracing on a " Mayuresh Chitale
2026-11-26 10:05 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 06/14] gtrace: Add RISC-V Trace encoder driver Mayuresh Chitale
2026-11-26 10:09 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 07/14] gtrace: Add function to copy into perf AUX buffer Mayuresh Chitale
2026-11-26 10:05 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 08/14] perf: Add gtrace AUX buffer trace format type Mayuresh Chitale
2026-11-26 9:55 ` [PATCH v7 09/14] gtrace: Add RISC-V Trace ramsink driver Mayuresh Chitale
2026-11-26 10:13 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 10/14] riscv: Enable DMA_RESTRICTED_POOL in defconfig Mayuresh Chitale
2026-11-26 9:55 ` [PATCH v7 11/14] gtrace: Add perf driver for tracing using perf tool Mayuresh Chitale
2026-11-26 10:23 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 12/14] perf tools: Add RISC-V trace PMU record capabilities Mayuresh Chitale
2026-11-26 10:19 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 13/14] perf tools: Initial support for gtrace decoder Mayuresh Chitale
2026-11-26 10:17 ` sashiko-bot
2026-11-26 9:55 ` [PATCH v7 14/14] MAINTAINERS: Add entry for RISC-V trace framework Mayuresh Chitale
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-235261@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=mayuresh.chitale@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox