Commit f66529f998e59acbd64ccce3adfce8eedfa52da8

Authored by Simon Glass
1 parent 4f60166c90

dm: core: Correct bug introduced in uclass_first/next_device()

These functions now rely on uclass_find_first/next_device() and assume that
they will either return failure (-ve error code) or a device. In fact,
coming to the end of a list is not considered failure and they return 0
in that case.

The logic to deal with this was replaced in commit acb9ca2a with just using
uclass_get_device_tail(). Add back the missing logic. This bug was
caught by unit tests but since they were broken for other reasons at the
time, this was not noticed.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 1 changed file with 5 additions and 0 deletions Side-by-side Diff

drivers/core/uclass.c
... ... @@ -277,6 +277,7 @@
277 277 if (ret)
278 278 return ret;
279 279  
  280 + assert(dev);
280 281 ret = device_probe(dev);
281 282 if (ret)
282 283 return ret;
... ... @@ -342,6 +343,8 @@
342 343  
343 344 *devp = NULL;
344 345 ret = uclass_find_first_device(id, &dev);
  346 + if (!dev)
  347 + return 0;
345 348 return uclass_get_device_tail(dev, ret, devp);
346 349 }
347 350  
... ... @@ -352,6 +355,8 @@
352 355  
353 356 *devp = NULL;
354 357 ret = uclass_find_next_device(&dev);
  358 + if (!dev)
  359 + return 0;
355 360 return uclass_get_device_tail(dev, ret, devp);
356 361 }
357 362