coresight: etm-perf: Fix reference count leak in etm_setup_aux
PATCH v2 1/1 coresight: etm-perf: Fix reference count leak in etm_setup_aux
In etm_setup_aux(), when a user sink is obtained via coresight_get_sink_by_id(), it increments the reference count of the sink device. However, if the sink is used in path building, the path holds a reference, but the initial reference from coresight_get_sink_by_id() is not released, causing a reference count leak. We should release the initial reference after the path is built.
Found by code review.
---
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
@@ -454,6 +454,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.17.1
Leo Yan
reviewerdrivers/hwtracing/coresight/coresight-etm-perf.c static void *etm_setup_aux(struct perf_event *event, void **pages, · line 460
Quoted 8 lines · Ma Ke
drivers/hwtracing/coresight/coresight-etm-perf.c +4
-0@@ -454,6 +454,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 ; + }
After searched kernel, I prefer to put device in coresight_get_sink_by_id(). Please refer acpi_dev_present() how to do that.
I would like Suzuki's confirmation in case I introduce noise.
Thanks,
Leo