From 8efae021db1166ea07be0b2eda7f074d767843ea Mon Sep 17 00:00:00 2001
From: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
Date: Tue, 18 Dec 2018 20:03:49 +0200
Subject: [PATCH] api: storage: Fix enumeration of storage devices

dev_stor_get() is not able to find the next available device in the current
storage group when the previous enumerated device belongs to a different
group or class (e.g. network).

The root cause is the device group iterator not being reset after an
unsuccessful search for the last returned device so that the following
search for the next available device will start from beginning.

The issue has been identified by loading and booting GRUB in a QEMU
vexpress-a9 environment.

Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@iquestgroup.com>
---
 api/api_storage.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/api/api_storage.c b/api/api_storage.c
index 8aeeda2715f..2b90c18aaec 100644
--- a/api/api_storage.c
+++ b/api/api_storage.c
@@ -99,6 +99,7 @@ static int dev_stor_get(int type, int *more, struct device_info *di)
 {
 	struct blk_desc *dd;
 	int found = 0;
+	int found_last = 0;
 	int i = 0;
 
 	/* Wasn't configured for this type, return 0 directly */
@@ -111,9 +112,13 @@ static int dev_stor_get(int type, int *more, struct device_info *di)
 			if (di->cookie ==
 			    (void *)blk_get_dev(specs[type].name, i)) {
 				i += 1;
+				found_last = 1;
 				break;
 			}
 		}
+
+		if (!found_last)
+			i = 0;
 	}
 
 	for (; i < specs[type].max_dev; i++) {
-- 
GitLab