Skip to content

Commit 76f1308

Browse files
Saravana Kannangregkh
authored andcommitted
driver core: Create __fwnode_link_del() helper function
The same code is repeated in multiple locations. Create a helper function for it. Reviewed-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Saravana Kannan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 68223ee commit 76f1308

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

drivers/base/core.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup)
101101
return ret;
102102
}
103103

104+
/**
105+
* __fwnode_link_del - Delete a link between two fwnode_handles.
106+
* @link: the fwnode_link to be deleted
107+
*
108+
* The fwnode_link_lock needs to be held when this function is called.
109+
*/
110+
static void __fwnode_link_del(struct fwnode_link *link)
111+
{
112+
list_del(&link->s_hook);
113+
list_del(&link->c_hook);
114+
kfree(link);
115+
}
116+
104117
/**
105118
* fwnode_links_purge_suppliers - Delete all supplier links of fwnode_handle.
106119
* @fwnode: fwnode whose supplier links need to be deleted
@@ -112,11 +125,8 @@ static void fwnode_links_purge_suppliers(struct fwnode_handle *fwnode)
112125
struct fwnode_link *link, *tmp;
113126

114127
mutex_lock(&fwnode_link_lock);
115-
list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) {
116-
list_del(&link->s_hook);
117-
list_del(&link->c_hook);
118-
kfree(link);
119-
}
128+
list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook)
129+
__fwnode_link_del(link);
120130
mutex_unlock(&fwnode_link_lock);
121131
}
122132

@@ -131,11 +141,8 @@ static void fwnode_links_purge_consumers(struct fwnode_handle *fwnode)
131141
struct fwnode_link *link, *tmp;
132142

133143
mutex_lock(&fwnode_link_lock);
134-
list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) {
135-
list_del(&link->s_hook);
136-
list_del(&link->c_hook);
137-
kfree(link);
138-
}
144+
list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook)
145+
__fwnode_link_del(link);
139146
mutex_unlock(&fwnode_link_lock);
140147
}
141148

@@ -1887,9 +1894,7 @@ static void __fw_devlink_link_to_consumers(struct device *dev)
18871894
if (!own_link || ret == -EAGAIN)
18881895
continue;
18891896

1890-
list_del(&link->s_hook);
1891-
list_del(&link->c_hook);
1892-
kfree(link);
1897+
__fwnode_link_del(link);
18931898
}
18941899
}
18951900

@@ -1941,9 +1946,7 @@ static void __fw_devlink_link_to_suppliers(struct device *dev,
19411946
if (!own_link || ret == -EAGAIN)
19421947
continue;
19431948

1944-
list_del(&link->s_hook);
1945-
list_del(&link->c_hook);
1946-
kfree(link);
1949+
__fwnode_link_del(link);
19471950

19481951
/* If no device link was created, nothing more to do. */
19491952
if (ret)

0 commit comments

Comments
 (0)