Skip to content

Commit cd115c0

Browse files
Saravana Kannangregkh
authored andcommitted
driver core: fw_devlink: Consolidate device link flag computation
Consolidate the code that computes the flags to be used when creating a device link from a fwnode link. Fixes: 2de9d8e ("driver core: fw_devlink: Improve handling of cyclic dependencies") Signed-off-by: Saravana Kannan <[email protected]> Tested-by: Colin Foster <[email protected]> Tested-by: Sudeep Holla <[email protected]> Tested-by: Douglas Anderson <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]> Tested-by: Luca Weiss <[email protected]> # qcom/sm7225-fairphone-fp4 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6a6dfdf commit cd115c0

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

drivers/base/core.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,8 +1727,11 @@ static int __init fw_devlink_strict_setup(char *arg)
17271727
}
17281728
early_param("fw_devlink.strict", fw_devlink_strict_setup);
17291729

1730-
u32 fw_devlink_get_flags(void)
1730+
static inline u32 fw_devlink_get_flags(u8 fwlink_flags)
17311731
{
1732+
if (fwlink_flags & FWLINK_FLAG_CYCLE)
1733+
return FW_DEVLINK_FLAGS_PERMISSIVE | DL_FLAG_CYCLE;
1734+
17321735
return fw_devlink_flags;
17331736
}
17341737

@@ -1938,7 +1941,7 @@ static bool fwnode_ancestor_init_without_drv(struct fwnode_handle *fwnode)
19381941
* fw_devlink_create_devlink - Create a device link from a consumer to fwnode
19391942
* @con: consumer device for the device link
19401943
* @sup_handle: fwnode handle of supplier
1941-
* @flags: devlink flags
1944+
* @link: fwnode link that's being converted to a device link
19421945
*
19431946
* This function will try to create a device link between the consumer device
19441947
* @con and the supplier device represented by @sup_handle.
@@ -1955,10 +1958,17 @@ static bool fwnode_ancestor_init_without_drv(struct fwnode_handle *fwnode)
19551958
* possible to do that in the future
19561959
*/
19571960
static int fw_devlink_create_devlink(struct device *con,
1958-
struct fwnode_handle *sup_handle, u32 flags)
1961+
struct fwnode_handle *sup_handle,
1962+
struct fwnode_link *link)
19591963
{
19601964
struct device *sup_dev;
19611965
int ret = 0;
1966+
u32 flags;
1967+
1968+
if (con->fwnode == link->consumer)
1969+
flags = fw_devlink_get_flags(link->flags);
1970+
else
1971+
flags = FW_DEVLINK_FLAGS_PERMISSIVE;
19621972

19631973
/*
19641974
* In some cases, a device P might also be a supplier to its child node
@@ -2091,7 +2101,6 @@ static void __fw_devlink_link_to_consumers(struct device *dev)
20912101
struct fwnode_link *link, *tmp;
20922102

20932103
list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) {
2094-
u32 dl_flags = fw_devlink_get_flags();
20952104
struct device *con_dev;
20962105
bool own_link = true;
20972106
int ret;
@@ -2121,14 +2130,13 @@ static void __fw_devlink_link_to_consumers(struct device *dev)
21212130
con_dev = NULL;
21222131
} else {
21232132
own_link = false;
2124-
dl_flags = FW_DEVLINK_FLAGS_PERMISSIVE;
21252133
}
21262134
}
21272135

21282136
if (!con_dev)
21292137
continue;
21302138

2131-
ret = fw_devlink_create_devlink(con_dev, fwnode, dl_flags);
2139+
ret = fw_devlink_create_devlink(con_dev, fwnode, link);
21322140
put_device(con_dev);
21332141
if (!own_link || ret == -EAGAIN)
21342142
continue;
@@ -2169,19 +2177,13 @@ static void __fw_devlink_link_to_suppliers(struct device *dev,
21692177
bool own_link = (dev->fwnode == fwnode);
21702178
struct fwnode_link *link, *tmp;
21712179
struct fwnode_handle *child = NULL;
2172-
u32 dl_flags;
2173-
2174-
if (own_link)
2175-
dl_flags = fw_devlink_get_flags();
2176-
else
2177-
dl_flags = FW_DEVLINK_FLAGS_PERMISSIVE;
21782180

21792181
list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) {
21802182
int ret;
21812183
struct device *sup_dev;
21822184
struct fwnode_handle *sup = link->supplier;
21832185

2184-
ret = fw_devlink_create_devlink(dev, sup, dl_flags);
2186+
ret = fw_devlink_create_devlink(dev, sup, link);
21852187
if (!own_link || ret == -EAGAIN)
21862188
continue;
21872189

include/linux/fwnode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
207207
fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
208208
}
209209

210-
extern u32 fw_devlink_get_flags(void);
211210
extern bool fw_devlink_is_strict(void);
212211
int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
213212
void fwnode_links_purge(struct fwnode_handle *fwnode);

0 commit comments

Comments
 (0)