diff mbox series

[v5,01/13] coresight: Fix loss of connection info when a module is unloaded

Message ID 20230404155121.1824126-2-james.clark@arm.com (mailing list archive)
State New, archived
Headers show
Series coresight: Fix CTI module refcount leak by making it a helper device | expand

Commit Message

James Clark April 4, 2023, 3:51 p.m. UTC
child_fwnode should be a read only property based on the DT or ACPI. If
it's cleared on the parent device when a child is unloaded, then when
the child is loaded again the connection won't be remade.

child_dev should be cleared instead which signifies that the connection
should be remade when the child_fwnode registers a new coresight_device.

Similarly the reference count shouldn't be decremented as long as the
parent device exists. The correct place to drop the reference is in
coresight_release_platform_data() which is already done.

Reproducible on Juno with the following steps:

  # load all coresight modules.
  $ cd /sys/bus/coresight/devices/
  $ echo 1 > tmc_etr0/enable_sink
  $ echo 1 > etm0/enable_source
  # Works fine ^

  $ echo 0 > etm0/enable_source
  $ rmmod coresight-funnel
  $ modprobe coresight-funnel
  $ echo 1 > etm0/enable_source
  -bash: echo: write error: Invalid argument

Fixes: 37ea1ffddffa ("coresight: Use fwnode handle instead of device names")
Fixes: 2af89ebacf29 ("coresight: Clear the connection field properly")
Tested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: James Clark <james.clark@arm.com>
---
 drivers/hwtracing/coresight/coresight-core.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Mike Leach April 12, 2023, 1:12 p.m. UTC | #1
On Tue, 4 Apr 2023 at 16:51, James Clark <james.clark@arm.com> wrote:
>
> child_fwnode should be a read only property based on the DT or ACPI. If
> it's cleared on the parent device when a child is unloaded, then when
> the child is loaded again the connection won't be remade.
>
> child_dev should be cleared instead which signifies that the connection
> should be remade when the child_fwnode registers a new coresight_device.
>
> Similarly the reference count shouldn't be decremented as long as the
> parent device exists. The correct place to drop the reference is in
> coresight_release_platform_data() which is already done.
>
> Reproducible on Juno with the following steps:
>
>   # load all coresight modules.
>   $ cd /sys/bus/coresight/devices/
>   $ echo 1 > tmc_etr0/enable_sink
>   $ echo 1 > etm0/enable_source
>   # Works fine ^
>
>   $ echo 0 > etm0/enable_source
>   $ rmmod coresight-funnel
>   $ modprobe coresight-funnel
>   $ echo 1 > etm0/enable_source
>   -bash: echo: write error: Invalid argument
>
> Fixes: 37ea1ffddffa ("coresight: Use fwnode handle instead of device names")
> Fixes: 2af89ebacf29 ("coresight: Clear the connection field properly")
> Tested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> Signed-off-by: James Clark <james.clark@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-core.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> index d3bf82c0de1d..5733294ce5cd 100644
> --- a/drivers/hwtracing/coresight/coresight-core.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -1419,13 +1419,8 @@ static int coresight_remove_match(struct device *dev, void *data)
>                 if (csdev->dev.fwnode == conn->child_fwnode) {
>                         iterator->orphan = true;
>                         coresight_remove_links(iterator, conn);
> -                       /*
> -                        * Drop the reference to the handle for the remote
> -                        * device acquired in parsing the connections from
> -                        * platform data.
> -                        */
> -                       fwnode_handle_put(conn->child_fwnode);
> -                       conn->child_fwnode = NULL;
> +
> +                       conn->child_dev = NULL;
>                         /* No need to continue */
>                         break;
>                 }
> --
> 2.34.1
>

Reviewed-by: Mike Leach <mike.leach@linaro.org>
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index d3bf82c0de1d..5733294ce5cd 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1419,13 +1419,8 @@  static int coresight_remove_match(struct device *dev, void *data)
 		if (csdev->dev.fwnode == conn->child_fwnode) {
 			iterator->orphan = true;
 			coresight_remove_links(iterator, conn);
-			/*
-			 * Drop the reference to the handle for the remote
-			 * device acquired in parsing the connections from
-			 * platform data.
-			 */
-			fwnode_handle_put(conn->child_fwnode);
-			conn->child_fwnode = NULL;
+
+			conn->child_dev = NULL;
 			/* No need to continue */
 			break;
 		}