linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: James Clark <james.clark@arm.com>,
	coresight@lists.linaro.org, quic_jinlmao@quicinc.com,
	mike.leach@linaro.org
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>,
	Leo Yan <leo.yan@linaro.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH v3 08/13] coresight: Simplify connection fixup mechanism
Date: Mon, 3 Apr 2023 10:18:02 +0100	[thread overview]
Message-ID: <2c3e8332-e964-91d0-51e9-649e09d9187c@arm.com> (raw)
In-Reply-To: <20230329115329.2747724-9-james.clark@arm.com>

On 29/03/2023 12:53, James Clark wrote:
> There is some duplication between coresight_fixup_device_conns() and
> coresight_fixup_orphan_conns(). They both do the same thing except for
> the fact that coresight_fixup_orphan_conns() can't handle iterating over
> itself.
> 
> By making it able to handle fixing up it's own connections the other
> function can be removed.
> 
> Signed-off-by: James Clark <james.clark@arm.com>
> ---
>   drivers/hwtracing/coresight/coresight-core.c | 72 +++++++-------------
>   1 file changed, 26 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> index 389f6203c8f0..2f4aa15ef8f9 100644
> --- a/drivers/hwtracing/coresight/coresight-core.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -1316,38 +1316,42 @@ static int coresight_orphan_match(struct device *dev, void *data)
>   {
>   	int i, ret = 0;
>   	bool still_orphan = false;
> -	struct coresight_device *csdev, *i_csdev;
> +	struct coresight_device *csdev = data;
> +	struct coresight_device *i_csdev = to_coresight_device(dev);
>   	struct coresight_connection *conn;
>   
> -	csdev = data;
> -	i_csdev = to_coresight_device(dev);
> -
> -	/* No need to check oneself */
> -	if (csdev == i_csdev)
> -		return 0;
> -
>   	/* Move on to another component if no connection is orphan */
>   	if (!i_csdev->orphan)
>   		return 0;
>   	/*
> -	 * Circle throuch all the connection of that component.  If we find
> +	 * Circle through all the connections of that component.  If we find
>   	 * an orphan connection whose name matches @csdev, link it.
>   	 */
>   	for (i = 0; i < i_csdev->pdata->nr_outconns; i++) {
>   		conn = i_csdev->pdata->out_conns[i];
>   
> -		/* We have found at least one orphan connection */
> -		if (conn->dest_dev == NULL) {
> -			/* Does it match this newly added device? */
> -			if (conn->dest_fwnode == csdev->dev.fwnode) {
> -				ret = coresight_make_links(i_csdev,
> -							   conn, csdev);
> -				if (ret)
> -					return ret;
> -			} else {
> -				/* This component still has an orphan */
> -				still_orphan = true;
> -			}


To be honest, this unification makes it really hard to follow.

> +		/* Skip the port if it's already connected. */
> +		if (conn->dest_dev)
> +			continue;
> +
> +		/*
> +		 * When connecting the newly registered device, we need to find
> +		 * the remote instead of using the *data shortcut that avoids
> +		 * the need for this search.
> +		 */
> +		if (csdev == i_csdev)
> +			csdev = coresight_find_csdev_by_fwnode(
> +				conn->dest_fwnode);

And this is overwriting the csdev, and I am struggling to follow, how
further connections are being fixed up after the first one, because the
condition wouldn't be true after the first one.

One way to do that would be, doing something like:

Rename the variables as follow:

	csdev => dst_dev
	i_csdev => src_dev

	bool fixup_self = (src_dev == dst_dev);


	for (i = 0; i ....) {
		...

		/*
		 * If we are at the "new" device, which triggered
		 * this search, we must find the remote device
		 * from the fwnode in the connection.
		 */
		if (fixup_self) {
			dst_dev = find_by_fwnode(...);
		}

> +
> +		/* Does it match this newly added device? */
> +		if (csdev && conn->dest_fwnode == csdev->dev.fwnode) {
> +			ret = coresight_make_links(i_csdev, conn, csdev);
> +			if (ret)
> +				return ret;
> +
> +		} else {
> +			/* This component still has an orphan */
> +			still_orphan = true;
>   		}
>   	}


Suzuki


>   
> @@ -1366,28 +1370,6 @@ static int coresight_fixup_orphan_conns(struct coresight_device *csdev)
>   			 csdev, coresight_orphan_match);
>   }
>   
> -
> -static int coresight_fixup_device_conns(struct coresight_device *csdev)
> -{
> -	int i, ret = 0;
> -
> -	for (i = 0; i < csdev->pdata->nr_outconns; i++) {
> -		struct coresight_connection *conn = csdev->pdata->out_conns[i];
> -
> -		conn->dest_dev =
> -			coresight_find_csdev_by_fwnode(conn->dest_fwnode);
> -		if (conn->dest_dev && conn->dest_dev->has_conns_grp) {
> -			ret = coresight_make_links(csdev, conn, conn->dest_dev);
> -			if (ret)
> -				break;
> -		} else {
> -			csdev->orphan = true;
> -		}
> -	}
> -
> -	return ret;
> -}
> -
>   static int coresight_remove_match(struct device *dev, void *data)
>   {
>   	int i;
> @@ -1594,7 +1576,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
>   	csdev->subtype = desc->subtype;
>   	csdev->ops = desc->ops;
>   	csdev->access = desc->access;
> -	csdev->orphan = false;
> +	csdev->orphan = true;
>   
>   	csdev->dev.type = &coresight_dev_type[desc->type];
>   	csdev->dev.groups = desc->groups;
> @@ -1644,8 +1626,6 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
>   	registered = true;
>   
>   	ret = coresight_create_conns_sysfs_group(csdev);
> -	if (!ret)
> -		ret = coresight_fixup_device_conns(csdev);
>   	if (!ret)
>   		ret = coresight_fixup_orphan_conns(csdev);
>   


  reply	other threads:[~2023-04-03  9:19 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29 11:53 [PATCH v3 00/13] coresight: Fix CTI module refcount leak by making it a helper device James Clark
2023-03-29 11:53 ` [PATCH v3 01/13] coresight: Use enum type for cs_mode wherever possible James Clark
2023-03-29 11:53 ` [PATCH v3 02/13] coresight: Change name of pdata->conns James Clark
2023-03-29 11:53 ` [PATCH v3 03/13] coresight: Rename nr_outports to nr_outconns James Clark
2023-03-29 11:53 ` [PATCH v3 04/13] coresight: Rename connection members to make the direction explicit James Clark
2023-03-29 11:53 ` [PATCH v3 05/13] coresight: Dynamically add connections James Clark
2023-03-29 11:53 ` [PATCH v3 06/13] coresight: Fix loss of connection info when a module is unloaded James Clark
2023-03-30 12:42   ` Suzuki K Poulose
2023-03-30 14:01     ` Suzuki K Poulose
2023-03-29 11:53 ` [PATCH v3 07/13] coresight: Store pointers to connections rather than an array of them James Clark
2023-04-03  8:46   ` Suzuki K Poulose
2023-04-03 10:16     ` James Clark
2023-04-03 11:11       ` Suzuki K Poulose
2023-03-29 11:53 ` [PATCH v3 08/13] coresight: Simplify connection fixup mechanism James Clark
2023-04-03  9:18   ` Suzuki K Poulose [this message]
2023-03-29 11:53 ` [PATCH v3 09/13] coresight: Store in-connections as well as out-connections James Clark
2023-04-03 10:17   ` Suzuki K Poulose
2023-03-29 11:53 ` [PATCH v3 10/13] coresight: Make refcount a property of the connection James Clark
2023-04-03 11:47   ` Suzuki K Poulose
2023-04-03 14:13     ` James Clark
2023-03-29 11:53 ` [PATCH v3 11/13] coresight: Refactor out buffer allocation function for ETR James Clark
2023-03-29 11:53 ` [PATCH v3 12/13] coresight: Enable and disable helper devices adjacent to the path James Clark
2023-04-03 17:54   ` Suzuki K Poulose
2023-03-29 11:53 ` [PATCH v3 13/13] coresight: Fix CTI module refcount leak by making it a helper device James Clark
2023-04-04  9:21   ` Suzuki K Poulose
2023-04-04 12:55     ` James Clark
2023-04-04 13:04       ` James Clark
2023-04-04 13:59         ` Suzuki K Poulose

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2c3e8332-e964-91d0-51e9-649e09d9187c@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@arm.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mike.leach@linaro.org \
    --cc=quic_jinlmao@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).