From nobody Wed Sep 10 11:03:50 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79AC5C77B7C for ; Tue, 25 Apr 2023 14:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234316AbjDYOh2 (ORCPT ); Tue, 25 Apr 2023 10:37:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234337AbjDYOgw (ORCPT ); Tue, 25 Apr 2023 10:36:52 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37BA213C05 for ; Tue, 25 Apr 2023 07:36:48 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EACACC14; Tue, 25 Apr 2023 07:37:31 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 652BD3F587; Tue, 25 Apr 2023 07:36:46 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, quic_jinlmao@quicinc.com, mike.leach@linaro.org, suzuki.poulose@arm.com Cc: James Clark , Leo Yan , Alexander Shishkin , Mathieu Poirier , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 08/13] coresight: Simplify connection fixup mechanism Date: Tue, 25 Apr 2023 15:35:35 +0100 Message-Id: <20230425143542.2305069-9-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230425143542.2305069-1-james.clark@arm.com> References: <20230425143542.2305069-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Mike Leach Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-core.c | 84 ++++++++------------ 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 0b738960973b..8d377a59e0be 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1316,42 +1316,46 @@ static int coresight_orphan_match(struct device *de= v, void *data) { int i, ret =3D 0; bool still_orphan =3D false; - struct coresight_device *csdev, *i_csdev; + struct coresight_device *dst_csdev =3D data; + struct coresight_device *src_csdev =3D to_coresight_device(dev); struct coresight_connection *conn; - - csdev =3D data; - i_csdev =3D to_coresight_device(dev); - - /* No need to check oneself */ - if (csdev =3D=3D i_csdev) - return 0; + bool fixup_self =3D (src_csdev =3D=3D dst_csdev); =20 /* Move on to another component if no connection is orphan */ - if (!i_csdev->orphan) + if (!src_csdev->orphan) return 0; /* - * Circle throuch all the connection of that component. If we find - * an orphan connection whose name matches @csdev, link it. + * Circle through all the connections of that component. If we find + * an orphan connection whose name matches @dst_csdev, link it. */ - for (i =3D 0; i < i_csdev->pdata->nr_outconns; i++) { - conn =3D i_csdev->pdata->out_conns[i]; - - /* We have found at least one orphan connection */ - if (conn->dest_dev =3D=3D NULL) { - /* Does it match this newly added device? */ - if (conn->dest_fwnode =3D=3D csdev->dev.fwnode) { - ret =3D coresight_make_links(i_csdev, - conn, csdev); - if (ret) - return ret; - } else { - /* This component still has an orphan */ - still_orphan =3D true; - } + for (i =3D 0; i < src_csdev->pdata->nr_outconns; i++) { + conn =3D src_csdev->pdata->out_conns[i]; + + /* Skip the port if it's already connected. */ + if (conn->dest_dev) + continue; + + /* + * 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_csdev =3D coresight_find_csdev_by_fwnode( + conn->dest_fwnode); + + /* Does it match this newly added device? */ + if (dst_csdev && conn->dest_fwnode =3D=3D dst_csdev->dev.fwnode) { + ret =3D coresight_make_links(src_csdev, conn, dst_csdev); + if (ret) + return ret; + } else { + /* This component still has an orphan */ + still_orphan =3D true; } } =20 - i_csdev->orphan =3D still_orphan; + src_csdev->orphan =3D still_orphan; =20 /* * Returning '0' in case we didn't encounter any error, @@ -1366,28 +1370,6 @@ static int coresight_fixup_orphan_conns(struct cores= ight_device *csdev) csdev, coresight_orphan_match); } =20 - -static int coresight_fixup_device_conns(struct coresight_device *csdev) -{ - int i, ret =3D 0; - - for (i =3D 0; i < csdev->pdata->nr_outconns; i++) { - struct coresight_connection *conn =3D csdev->pdata->out_conns[i]; - - conn->dest_dev =3D - coresight_find_csdev_by_fwnode(conn->dest_fwnode); - if (conn->dest_dev && conn->dest_dev->has_conns_grp) { - ret =3D coresight_make_links(csdev, conn, conn->dest_dev); - if (ret) - break; - } else { - csdev->orphan =3D true; - } - } - - return ret; -} - static int coresight_remove_match(struct device *dev, void *data) { int i; @@ -1595,7 +1577,7 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) csdev->subtype =3D desc->subtype; csdev->ops =3D desc->ops; csdev->access =3D desc->access; - csdev->orphan =3D false; + csdev->orphan =3D true; =20 csdev->dev.type =3D &coresight_dev_type[desc->type]; csdev->dev.groups =3D desc->groups; @@ -1645,8 +1627,6 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) registered =3D true; =20 ret =3D coresight_create_conns_sysfs_group(csdev); - if (!ret) - ret =3D coresight_fixup_device_conns(csdev); if (!ret) ret =3D coresight_fixup_orphan_conns(csdev); =20 --=20 2.34.1