From: Saravana Kannan <saravanak@google.com>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Sudeep Holla" <sudeep.holla@arm.com>,
"Cristian Marussi" <cristian.marussi@arm.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Marc Zyngier" <maz@kernel.org>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"NXP Linux Team" <linux-imx@nxp.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Richard Weinberger" <richard@nod.at>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Rob Herring" <robh+dt@kernel.org>,
"Frank Rowand" <frowand.list@gmail.com>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Magnus Damm" <magnus.damm@gmail.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Daniel Scally" <djrscally@gmail.com>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Len Brown" <lenb@kernel.org>,
"Saravana Kannan" <saravanak@google.com>,
"Rafał Miłecki" <rafal@milecki.pl>
Cc: Abel Vesa <abel.vesa@linaro.org>,
Alexander Stein <alexander.stein@ew.tq-group.com>,
Tony Lindgren <tony@atomide.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
John Stultz <jstultz@google.com>,
Doug Anderson <dianders@chromium.org>,
Guenter Roeck <linux@roeck-us.net>,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
Maxim Kiselev <bigunclemax@gmail.com>,
Maxim Kochetkov <fido_max@inbox.ru>,
Luca Weiss <luca.weiss@fairphone.com>,
Colin Foster <colin.foster@in-advantage.com>,
Martin Kepplinger <martin.kepplinger@puri.sm>,
Jean-Philippe Brucker <jpb@kernel.org>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
kernel-team@android.com, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
linux-mtd@lists.infradead.org, devicetree@vger.kernel.org,
linux-renesas-soc@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: [PATCH v3 09/12] of: property: Simplify of_link_to_phandle()
Date: Mon, 6 Feb 2023 17:42:01 -0800 [thread overview]
Message-ID: <20230207014207.1678715-10-saravanak@google.com> (raw)
In-Reply-To: <20230207014207.1678715-1-saravanak@google.com>
The driver core now:
- Has the parent device of a supplier pick up the consumers if the
supplier never has a device created for it.
- Ignores a supplier if the supplier has no parent device and will never
be probed by a driver
And already prevents creating a device link with the consumer as a
supplier of a parent.
So, we no longer need to find the "compatible" node of the supplier or
do any other checks in of_link_to_phandle(). We simply need to make sure
that the supplier is available in DT.
Signed-off-by: Saravana Kannan <saravanak@google.com>
Tested-by: Colin Foster <colin.foster@in-advantage.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
---
drivers/of/property.c | 84 +++++++------------------------------------
1 file changed, 13 insertions(+), 71 deletions(-)
diff --git a/drivers/of/property.c b/drivers/of/property.c
index 134cfc980b70..c651aad6f34b 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1062,20 +1062,6 @@ of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
return of_device_get_match_data(dev);
}
-static bool of_is_ancestor_of(struct device_node *test_ancestor,
- struct device_node *child)
-{
- of_node_get(child);
- while (child) {
- if (child == test_ancestor) {
- of_node_put(child);
- return true;
- }
- child = of_get_next_parent(child);
- }
- return false;
-}
-
static struct device_node *of_get_compat_node(struct device_node *np)
{
of_node_get(np);
@@ -1106,71 +1092,27 @@ static struct device_node *of_get_compat_node_parent(struct device_node *np)
return node;
}
-/**
- * of_link_to_phandle - Add fwnode link to supplier from supplier phandle
- * @con_np: consumer device tree node
- * @sup_np: supplier device tree node
- *
- * Given a phandle to a supplier device tree node (@sup_np), this function
- * finds the device that owns the supplier device tree node and creates a
- * device link from @dev consumer device to the supplier device. This function
- * doesn't create device links for invalid scenarios such as trying to create a
- * link with a parent device as the consumer of its child device. In such
- * cases, it returns an error.
- *
- * Returns:
- * - 0 if fwnode link successfully created to supplier
- * - -EINVAL if the supplier link is invalid and should not be created
- * - -ENODEV if struct device will never be create for supplier
- */
-static int of_link_to_phandle(struct device_node *con_np,
+static void of_link_to_phandle(struct device_node *con_np,
struct device_node *sup_np)
{
- struct device *sup_dev;
- struct device_node *tmp_np = sup_np;
+ struct device_node *tmp_np = of_node_get(sup_np);
- /*
- * Find the device node that contains the supplier phandle. It may be
- * @sup_np or it may be an ancestor of @sup_np.
- */
- sup_np = of_get_compat_node(sup_np);
- if (!sup_np) {
- pr_debug("Not linking %pOFP to %pOFP - No device\n",
- con_np, tmp_np);
- return -ENODEV;
- }
+ /* Check that sup_np and its ancestors are available. */
+ while (tmp_np) {
+ if (of_fwnode_handle(tmp_np)->dev) {
+ of_node_put(tmp_np);
+ break;
+ }
- /*
- * Don't allow linking a device node as a consumer of one of its
- * descendant nodes. By definition, a child node can't be a functional
- * dependency for the parent node.
- */
- if (of_is_ancestor_of(con_np, sup_np)) {
- pr_debug("Not linking %pOFP to %pOFP - is descendant\n",
- con_np, sup_np);
- of_node_put(sup_np);
- return -EINVAL;
- }
+ if (!of_device_is_available(tmp_np)) {
+ of_node_put(tmp_np);
+ return;
+ }
- /*
- * Don't create links to "early devices" that won't have struct devices
- * created for them.
- */
- sup_dev = get_dev_from_fwnode(&sup_np->fwnode);
- if (!sup_dev &&
- (of_node_check_flag(sup_np, OF_POPULATED) ||
- sup_np->fwnode.flags & FWNODE_FLAG_NOT_DEVICE)) {
- pr_debug("Not linking %pOFP to %pOFP - No struct device\n",
- con_np, sup_np);
- of_node_put(sup_np);
- return -ENODEV;
+ tmp_np = of_get_next_parent(tmp_np);
}
- put_device(sup_dev);
fwnode_link_add(of_fwnode_handle(con_np), of_fwnode_handle(sup_np));
- of_node_put(sup_np);
-
- return 0;
}
/**
--
2.39.1.519.gcb327c4b5f-goog
next prev parent reply other threads:[~2023-02-07 1:43 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 1:41 [PATCH v3 00/12] fw_devlink improvements Saravana Kannan
2023-02-07 1:41 ` [PATCH v3 01/12] driver core: fw_devlink: Don't purge child fwnode's consumer links Saravana Kannan
2023-02-07 1:41 ` [PATCH v3 02/12] driver core: fw_devlink: Improve check for fwnode with no device/driver Saravana Kannan
2023-02-07 1:41 ` [PATCH v3 03/12] soc: renesas: Move away from using OF_POPULATED for fw_devlink Saravana Kannan
2023-02-07 7:56 ` Geert Uytterhoeven
2023-02-07 1:41 ` [PATCH v3 04/12] gpiolib: Clear the gpio_device's fwnode initialized flag before adding Saravana Kannan
2023-02-07 10:20 ` Andy Shevchenko
2023-02-07 10:28 ` Andy Shevchenko
2023-02-07 1:41 ` [PATCH v3 05/12] driver core: fw_devlink: Add DL_FLAG_CYCLE support to device links Saravana Kannan
2023-02-07 1:41 ` [PATCH v3 06/12] driver core: fw_devlink: Allow marking a fwnode link as being part of a cycle Saravana Kannan
2023-02-07 1:41 ` [PATCH v3 07/12] driver core: fw_devlink: Consolidate device link flag computation Saravana Kannan
2023-02-07 1:42 ` [PATCH v3 08/12] driver core: fw_devlink: Make cycle detection more robust Saravana Kannan
2023-02-07 1:42 ` Saravana Kannan [this message]
2023-02-07 20:57 ` [PATCH v3 09/12] of: property: Simplify of_link_to_phandle() Geert Uytterhoeven
2023-02-08 2:08 ` Saravana Kannan
2023-02-08 7:30 ` Geert Uytterhoeven
2023-02-08 7:31 ` Saravana Kannan
2023-02-08 7:56 ` Geert Uytterhoeven
2023-02-08 8:35 ` Saravana Kannan
2023-02-13 13:10 ` Geert Uytterhoeven
2023-02-08 13:37 ` Andy Shevchenko
2023-02-13 13:04 ` Geert Uytterhoeven
2023-02-08 7:33 ` Greg Kroah-Hartman
2023-02-08 7:50 ` Geert Uytterhoeven
2023-02-07 1:42 ` [PATCH v3 10/12] irqchip/irq-imx-gpcv2: Mark fwnode device as not initialized Saravana Kannan
2023-02-07 1:42 ` [PATCH v3 11/12] firmware: arm_scmi: Set fwnode for the scmi_device Saravana Kannan
2023-02-07 1:42 ` [PATCH v3 12/12] mtd: mtdpart: Don't create platform device that'll never probe Saravana Kannan
2023-02-07 7:51 ` Maxim Kiselev
2023-02-07 9:23 ` [PATCH v3 00/12] fw_devlink improvements Luca Weiss
2023-02-07 15:27 ` Doug Anderson
2023-02-07 18:15 ` Saravana Kannan
2023-02-07 21:35 ` Geert Uytterhoeven
2023-02-07 23:12 ` Saravana Kannan
2023-02-10 10:13 ` Vladimir Oltean
2023-02-10 19:27 ` Saravana Kannan
2023-02-10 21:08 ` Vladimir Oltean
2023-02-10 21:32 ` Saravana Kannan
2023-02-15 7:39 ` Tony Lindgren
2023-02-15 12:34 ` Jean-Philippe Brucker
2023-02-16 3:12 ` Dmitry Baryshkov
2023-02-25 6:24 ` Saravana Kannan
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=20230207014207.1678715-10-saravanak@google.com \
--to=saravanak@google.com \
--cc=abel.vesa@linaro.org \
--cc=alexander.stein@ew.tq-group.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bigunclemax@gmail.com \
--cc=brgl@bgdev.pl \
--cc=colin.foster@in-advantage.com \
--cc=cristian.marussi@arm.com \
--cc=devicetree@vger.kernel.org \
--cc=dianders@chromium.org \
--cc=djrscally@gmail.com \
--cc=dmitry.baryshkov@linaro.org \
--cc=festevam@gmail.com \
--cc=fido_max@inbox.ru \
--cc=frowand.list@gmail.com \
--cc=geert+renesas@glider.be \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jpb@kernel.org \
--cc=jstultz@google.com \
--cc=kernel-team@android.com \
--cc=kernel@pengutronix.de \
--cc=lenb@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=luca.weiss@fairphone.com \
--cc=magnus.damm@gmail.com \
--cc=martin.kepplinger@puri.sm \
--cc=maz@kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=rafael@kernel.org \
--cc=rafal@milecki.pl \
--cc=richard@nod.at \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=sakari.ailus@linux.intel.com \
--cc=shawnguo@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=tglx@linutronix.de \
--cc=tony@atomide.com \
--cc=vigneshr@ti.com \
--cc=vladimir.oltean@nxp.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).