coresight: etm-perf: Fix reference count leak in etm_setup_aux
PATCH RESEND v3 1/1 coresight: etm-perf: Fix reference count leak in etm_setup_aux
bus_find_device() returns a device with its reference count incremented. When a user-selected sink is obtained through coresight_get_sink_by_id(), etm_setup_aux() keeps using the returned sink while building the path and allocating the sink buffer.
Therefore the lookup reference must remain valid while etm_setup_aux() is still using the sink, otherwise the sink could be removed under the caller. Drop the lookup reference on the common exit path, after etm_setup_aux() no longer directly uses the user-selected sink.
The CoreSight path code takes the references it needs for built paths, so the initial lookup reference from coresight_get_sink_by_id() is no longer needed after setup_aux finishes.
Found by code review.
---
Changes in v3:
- do not drop the lookup reference in coresight_get_sink_by_id(), as that would return a sink pointer without keeping the device reference while etm_setup_aux() is still using it.
- dropped the lookup reference in etm_setup_aux on the common exit path, as suggested by Suzuki.
- updated the commit message to describe why the reference is kept until etm_setup_aux() finishes using the sink.
Changes in v2:
- modified the patch as suggestions.
--- drivers/hwtracing/coresight/coresight-etm-perf.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/hwtracing/coresight/coresight-etm-perf.c +5 -0
@@ -456,6 +456,11 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, goto err; out: +if (user_sink) { +put_device (&user_sink->dev); + user_sink =NULL ; + } +return event_data; err:
Signature · 1 line
2.43.0