driver core: fw_devlink: Consolidate device link flag computation
authorSaravana Kannan <saravanak@google.com>
Tue, 7 Feb 2023 01:41:59 +0000 (17:41 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:33:37 +0000 (09:33 +0100)
[ Upstream commit cd115c0409f283edde94bd5a9a42dc42bee0aba8 ]

Consolidate the code that computes the flags to be used when creating a
device link from a fwnode link.

Fixes: 2de9d8e0d2fe ("driver core: fw_devlink: Improve handling of cyclic dependencies")
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>
Tested-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Luca Weiss <luca.weiss@fairphone.com> # qcom/sm7225-fairphone-fp4
Link: https://lore.kernel.org/r/20230207014207.1678715-8-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/base/core.c
include/linux/fwnode.h

index 24c48fe..f623ebc 100644 (file)
@@ -1726,8 +1726,11 @@ static int __init fw_devlink_strict_setup(char *arg)
 }
 early_param("fw_devlink.strict", fw_devlink_strict_setup);
 
-u32 fw_devlink_get_flags(void)
+static inline u32 fw_devlink_get_flags(u8 fwlink_flags)
 {
+       if (fwlink_flags & FWLINK_FLAG_CYCLE)
+               return FW_DEVLINK_FLAGS_PERMISSIVE | DL_FLAG_CYCLE;
+
        return fw_devlink_flags;
 }
 
@@ -1908,7 +1911,7 @@ static int fw_devlink_relax_cycle(struct device *con, void *sup)
  * fw_devlink_create_devlink - Create a device link from a consumer to fwnode
  * @con: consumer device for the device link
  * @sup_handle: fwnode handle of supplier
- * @flags: devlink flags
+ * @link: fwnode link that's being converted to a device link
  *
  * This function will try to create a device link between the consumer device
  * @con and the supplier device represented by @sup_handle.
@@ -1925,10 +1928,17 @@ static int fw_devlink_relax_cycle(struct device *con, void *sup)
  *  possible to do that in the future
  */
 static int fw_devlink_create_devlink(struct device *con,
-                                    struct fwnode_handle *sup_handle, u32 flags)
+                                    struct fwnode_handle *sup_handle,
+                                    struct fwnode_link *link)
 {
        struct device *sup_dev;
        int ret = 0;
+       u32 flags;
+
+       if (con->fwnode == link->consumer)
+               flags = fw_devlink_get_flags(link->flags);
+       else
+               flags = FW_DEVLINK_FLAGS_PERMISSIVE;
 
        /*
         * In some cases, a device P might also be a supplier to its child node
@@ -2054,7 +2064,6 @@ static void __fw_devlink_link_to_consumers(struct device *dev)
        struct fwnode_link *link, *tmp;
 
        list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) {
-               u32 dl_flags = fw_devlink_get_flags();
                struct device *con_dev;
                bool own_link = true;
                int ret;
@@ -2084,14 +2093,13 @@ static void __fw_devlink_link_to_consumers(struct device *dev)
                                con_dev = NULL;
                        } else {
                                own_link = false;
-                               dl_flags = FW_DEVLINK_FLAGS_PERMISSIVE;
                        }
                }
 
                if (!con_dev)
                        continue;
 
-               ret = fw_devlink_create_devlink(con_dev, fwnode, dl_flags);
+               ret = fw_devlink_create_devlink(con_dev, fwnode, link);
                put_device(con_dev);
                if (!own_link || ret == -EAGAIN)
                        continue;
@@ -2132,19 +2140,13 @@ static void __fw_devlink_link_to_suppliers(struct device *dev,
        bool own_link = (dev->fwnode == fwnode);
        struct fwnode_link *link, *tmp;
        struct fwnode_handle *child = NULL;
-       u32 dl_flags;
-
-       if (own_link)
-               dl_flags = fw_devlink_get_flags();
-       else
-               dl_flags = FW_DEVLINK_FLAGS_PERMISSIVE;
 
        list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) {
                int ret;
                struct device *sup_dev;
                struct fwnode_handle *sup = link->supplier;
 
-               ret = fw_devlink_create_devlink(dev, sup, dl_flags);
+               ret = fw_devlink_create_devlink(dev, sup, link);
                if (!own_link || ret == -EAGAIN)
                        continue;
 
index fdf2ee0..5700451 100644 (file)
@@ -207,7 +207,6 @@ static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
                fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
 }
 
-extern u32 fw_devlink_get_flags(void);
 extern bool fw_devlink_is_strict(void);
 int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
 void fwnode_links_purge(struct fwnode_handle *fwnode);