diff mbox

[U-Boot,v2,02/47] dm: core: Check for empty list in uclass_find_device()

Message ID 1438356724-6561-3-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass July 31, 2015, 3:31 p.m. UTC
This function needs to check the list has entries before traversing it.
Fix this bug.

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

Changes in v2:
- Correct the return code to avoid a test failure

 drivers/core/uclass.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Bin Meng Aug. 2, 2015, 12:57 p.m. UTC | #1
On Fri, Jul 31, 2015 at 11:31 PM, Simon Glass <sjg@chromium.org> wrote:
> This function needs to check the list has entries before traversing it.
> Fix this bug.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2:
> - Correct the return code to avoid a test failure
>
>  drivers/core/uclass.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
> index aba9880..ffe6995 100644
> --- a/drivers/core/uclass.c
> +++ b/drivers/core/uclass.c
> @@ -153,6 +153,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
>         ret = uclass_get(id, &uc);
>         if (ret)
>                 return ret;
> +       if (list_empty(&uc->dev_head))
> +               return -ENODEV;
>
>         list_for_each_entry(dev, &uc->dev_head, uclass_node) {
>                 if (!index--) {
> --

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Simon Glass Aug. 2, 2015, 11:36 p.m. UTC | #2
On 2 August 2015 at 06:57, Bin Meng <bmeng.cn@gmail.com> wrote:
> On Fri, Jul 31, 2015 at 11:31 PM, Simon Glass <sjg@chromium.org> wrote:
>> This function needs to check the list has entries before traversing it.
>> Fix this bug.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>> Changes in v2:
>> - Correct the return code to avoid a test failure
>>
>>  drivers/core/uclass.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
>> index aba9880..ffe6995 100644
>> --- a/drivers/core/uclass.c
>> +++ b/drivers/core/uclass.c
>> @@ -153,6 +153,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
>>         ret = uclass_get(id, &uc);
>>         if (ret)
>>                 return ret;
>> +       if (list_empty(&uc->dev_head))
>> +               return -ENODEV;
>>
>>         list_for_each_entry(dev, &uc->dev_head, uclass_node) {
>>                 if (!index--) {
>> --
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot-x86.
diff mbox

Patch

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index aba9880..ffe6995 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -153,6 +153,8 @@  int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
 	ret = uclass_get(id, &uc);
 	if (ret)
 		return ret;
+	if (list_empty(&uc->dev_head))
+		return -ENODEV;
 
 	list_for_each_entry(dev, &uc->dev_head, uclass_node) {
 		if (!index--) {