[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250512154108.23920-2-leo.yan@arm.com>
Date: Mon, 12 May 2025 16:41:04 +0100
From: Leo Yan <leo.yan@....com>
To: Suzuki K Poulose <suzuki.poulose@....com>,
Mike Leach <mike.leach@...aro.org>,
James Clark <james.clark@...aro.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Mao Jinlong <quic_jinlmao@...cinc.com>,
coresight@...ts.linaro.org,
linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org
Cc: Leo Yan <leo.yan@....com>
Subject: [PATCH v1 1/5] coresight: Correct sink ID map allocation failure handling
When registering a CoreSight device, it first increase the reference
counter for the associated device and then allocates sink ID map. The
problem happens when the sink ID map allocation fails - the flow misses
decreasing the device's reference counter. As a result, the device can
never be properly cleaned up after the memory allocation failure.
To fix the issue, the allocation of the sink ID map is moved before
increasing the reference counter. With this change, if sink ID map
allocation fails, the function can exit without holding a reference to
the device. Afterwords, any subsequent failures will invoke
coresight_device_release() to release the device's resource, including
decrementing the reference counter.
Fixes: 5ad628a76176 ("coresight: Use per-sink trace ID maps for Perf sessions")
Signed-off-by: Leo Yan <leo.yan@....com>
---
drivers/hwtracing/coresight/coresight-core.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index 5632bcb8feb6..3e3823d9f991 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1318,12 +1318,6 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
csdev->dev.parent = desc->dev;
csdev->dev.release = coresight_device_release;
csdev->dev.bus = &coresight_bustype;
- /*
- * Hold the reference to our parent device. This will be
- * dropped only in coresight_device_release().
- */
- csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev));
- dev_set_name(&csdev->dev, "%s", desc->name);
if (csdev->type == CORESIGHT_DEV_TYPE_SINK ||
csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) {
@@ -1335,6 +1329,14 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
goto err_out;
}
}
+
+ /*
+ * Hold the reference to our parent device. This will be
+ * dropped only in coresight_device_release().
+ */
+ csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev));
+ dev_set_name(&csdev->dev, "%s", desc->name);
+
/*
* Make sure the device registration and the connection fixup
* are synchronised, so that we don't see uninitialised devices
--
2.34.1
Powered by blists - more mailing lists