[PATCH v1 3/5] coresight: Explicitly use the parent device handler

Leo Yan posted 5 patches 9 months ago
There is a newer version of this series
[PATCH v1 3/5] coresight: Explicitly use the parent device handler
Posted by Leo Yan 9 months ago
A CoreSight device is present on the CoreSight bus, and its device node
in the DT binding is assigned as the parent device.  Comments are added
to document this relationship.

The code is refined to explicitly use the parent device handle, making
it more readable and clearly indicating which device handle is being
used.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 drivers/hwtracing/coresight/coresight-core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index 3eacdcf638df..4f51ce152ac7 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1313,9 +1313,13 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 	csdev->access = desc->access;
 	csdev->orphan = true;
 
+	/*
+	 * 'csdev->dev' is a device present on the CoreSight bus. The device
+	 * node in the device tree is assigned as the parent device.
+	 */
+	csdev->dev.parent = desc->dev;
 	csdev->dev.type = &coresight_dev_type[desc->type];
 	csdev->dev.groups = desc->groups;
-	csdev->dev.parent = desc->dev;
 	csdev->dev.release = coresight_device_release;
 	csdev->dev.bus = &coresight_bustype;
 
@@ -1334,7 +1338,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 	 * 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));
+	csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(csdev->dev.parent));
 	dev_set_name(&csdev->dev, "%s", desc->name);
 
 	/*
@@ -1393,7 +1397,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 
 err_out:
 	/* Cleanup the connection information */
-	coresight_release_platform_data(NULL, desc->dev, desc->pdata);
+	coresight_release_platform_data(NULL, csdev->dev.parent, desc->pdata);
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(coresight_register);
-- 
2.34.1
Re: [PATCH v1 3/5] coresight: Explicitly use the parent device handler
Posted by Suzuki K Poulose 5 months ago
On 12/05/2025 16:41, Leo Yan wrote:
> A CoreSight device is present on the CoreSight bus, and its device node
> in the DT binding is assigned as the parent device.  Comments are added
> to document this relationship.
> 
> The code is refined to explicitly use the parent device handle, making
> it more readable and clearly indicating which device handle is being
> used.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
>   drivers/hwtracing/coresight/coresight-core.c | 10 +++++++---
>   1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> index 3eacdcf638df..4f51ce152ac7 100644
> --- a/drivers/hwtracing/coresight/coresight-core.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -1313,9 +1313,13 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
>   	csdev->access = desc->access;
>   	csdev->orphan = true;
>   
> +	/*
> +	 * 'csdev->dev' is a device present on the CoreSight bus. The device
> +	 * node in the device tree is assigned as the parent device.
> +	 */
> +	csdev->dev.parent = desc->dev;
>   	csdev->dev.type = &coresight_dev_type[desc->type];
>   	csdev->dev.groups = desc->groups;
> -	csdev->dev.parent = desc->dev;
>   	csdev->dev.release = coresight_device_release;
>   	csdev->dev.bus = &coresight_bustype;
>   
> @@ -1334,7 +1338,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
>   	 * 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));
> +	csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(csdev->dev.parent));
>   	dev_set_name(&csdev->dev, "%s", desc->name);
>   
>   	/*
> @@ -1393,7 +1397,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
>   
>   err_out:
>   	/* Cleanup the connection information */
> -	coresight_release_platform_data(NULL, desc->dev, desc->pdata);
> +	coresight_release_platform_data(NULL, csdev->dev.parent, desc->pdata);

This may be problematic, as the csdev could be NULL ?

Suzuki

>   	return ERR_PTR(ret);
>   }
>   EXPORT_SYMBOL_GPL(coresight_register);
Re: [PATCH v1 3/5] coresight: Explicitly use the parent device handler
Posted by Leo Yan 5 months ago
On Thu, Sep 11, 2025 at 09:52:20AM +0100, Suzuki Kuruppassery Poulose wrote:

[...]

> > @@ -1393,7 +1397,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
> >   err_out:
> >   	/* Cleanup the connection information */
> > -	coresight_release_platform_data(NULL, desc->dev, desc->pdata);
> > +	coresight_release_platform_data(NULL, csdev->dev.parent, desc->pdata);
> 
> This may be problematic, as the csdev could be NULL ?

Indeed. I will drop this change in next version.

Thanks,
Leo