Skip to content

Commit 3d1cf43

Browse files
rafaeljwgregkh
authored andcommitted
driver core: Extend device_is_dependent()
If the device passed as the target (second argument) to device_is_dependent() is not completely registered (that is, it has been initialized, but not added yet), but the parent pointer of it is set, it may be missing from the list of the parent's children and device_for_each_child() called by device_is_dependent() cannot be relied on to catch that dependency. For this reason, modify device_is_dependent() to check the ancestors of the target device by following its parent pointer in addition to the device_for_each_child() walk. Fixes: 9ed9895 ("driver core: Functional dependencies tracking support") Reported-by: Stephan Gerhold <[email protected]> Tested-by: Stephan Gerhold <[email protected]> Reviewed-by: Saravana Kannan <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://lore.kernel.org/r/17705994.d592GUb2YH@kreacher Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f2d6c27 commit 3d1cf43

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

drivers/base/core.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ int device_links_read_lock_held(void)
208208
#endif
209209
#endif /* !CONFIG_SRCU */
210210

211+
static bool device_is_ancestor(struct device *dev, struct device *target)
212+
{
213+
while (target->parent) {
214+
target = target->parent;
215+
if (dev == target)
216+
return true;
217+
}
218+
return false;
219+
}
220+
211221
/**
212222
* device_is_dependent - Check if one device depends on another one
213223
* @dev: Device to check dependencies for.
@@ -221,7 +231,12 @@ int device_is_dependent(struct device *dev, void *target)
221231
struct device_link *link;
222232
int ret;
223233

224-
if (dev == target)
234+
/*
235+
* The "ancestors" check is needed to catch the case when the target
236+
* device has not been completely initialized yet and it is still
237+
* missing from the list of children of its parent device.
238+
*/
239+
if (dev == target || device_is_ancestor(dev, target))
225240
return 1;
226241

227242
ret = device_for_each_child(dev, target, device_is_dependent);

0 commit comments

Comments
 (0)