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 <geert+renesas@glider.be>
Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20210915172808.620546-3-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Saravana Kannan and committed by Greg Kroah-Hartman 76f13081 68223eee

+19 -16
+19 -16
drivers/base/core.c
··· 102 } 103 104 /** 105 * fwnode_links_purge_suppliers - Delete all supplier links of fwnode_handle. 106 * @fwnode: fwnode whose supplier links need to be deleted 107 * ··· 125 struct fwnode_link *link, *tmp; 126 127 mutex_lock(&fwnode_link_lock); 128 - list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) { 129 - list_del(&link->s_hook); 130 - list_del(&link->c_hook); 131 - kfree(link); 132 - } 133 mutex_unlock(&fwnode_link_lock); 134 } 135 ··· 141 struct fwnode_link *link, *tmp; 142 143 mutex_lock(&fwnode_link_lock); 144 - list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) { 145 - list_del(&link->s_hook); 146 - list_del(&link->c_hook); 147 - kfree(link); 148 - } 149 mutex_unlock(&fwnode_link_lock); 150 } 151 ··· 1894 if (!own_link || ret == -EAGAIN) 1895 continue; 1896 1897 - list_del(&link->s_hook); 1898 - list_del(&link->c_hook); 1899 - kfree(link); 1900 } 1901 } 1902 ··· 1946 if (!own_link || ret == -EAGAIN) 1947 continue; 1948 1949 - list_del(&link->s_hook); 1950 - list_del(&link->c_hook); 1951 - kfree(link); 1952 1953 /* If no device link was created, nothing more to do. */ 1954 if (ret)
··· 102 } 103 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 + 117 + /** 118 * fwnode_links_purge_suppliers - Delete all supplier links of fwnode_handle. 119 * @fwnode: fwnode whose supplier links need to be deleted 120 * ··· 112 struct fwnode_link *link, *tmp; 113 114 mutex_lock(&fwnode_link_lock); 115 + list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) 116 + __fwnode_link_del(link); 117 mutex_unlock(&fwnode_link_lock); 118 } 119 ··· 131 struct fwnode_link *link, *tmp; 132 133 mutex_lock(&fwnode_link_lock); 134 + list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) 135 + __fwnode_link_del(link); 136 mutex_unlock(&fwnode_link_lock); 137 } 138 ··· 1887 if (!own_link || ret == -EAGAIN) 1888 continue; 1889 1890 + __fwnode_link_del(link); 1891 } 1892 } 1893 ··· 1941 if (!own_link || ret == -EAGAIN) 1942 continue; 1943 1944 + __fwnode_link_del(link); 1945 1946 /* If no device link was created, nothing more to do. */ 1947 if (ret)