diff mbox series

[v5,04/17] menu: menu_get_choice() return -ENOENT if menu item is empty

Message ID 20220428080950.23509-5-masahisa.kojima@linaro.org
State Accepted
Commit 7f67525f99d8158f668af8198cc1d089a3dc4ee8
Headers show
Series enable menu-driven boot device selection | expand

Commit Message

Masahisa Kojima April 28, 2022, 8:09 a.m. UTC
menu_get_choice() needs to handle the case that menu item
is empty. In this case, menu_get_choice() returns -ENOENT.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
---
Newly created in v5

 common/menu.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Heinrich Schuchardt April 29, 2022, 7:38 p.m. UTC | #1
On 4/28/22 10:09, Masahisa Kojima wrote:
> menu_get_choice() needs to handle the case that menu item
> is empty. In this case, menu_get_choice() returns -ENOENT.
>
> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> ---
> Newly created in v5
>
>   common/menu.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/common/menu.c b/common/menu.c
> index b577d80b4f..4118c6dc3c 100644
> --- a/common/menu.c
> +++ b/common/menu.c
> @@ -271,6 +271,9 @@ int menu_get_choice(struct menu *m, void **choice)
>   	if (!m || !choice)
>   		return -EINVAL;
>
> +	if (m->item_cnt == 0)

nits:

We tend to use (!m->item_cnt).

Best regards

Heinrich

> +		return -ENOENT;
> +
>   	if (!m->prompt)
>   		return menu_default_choice(m, choice);
>
diff mbox series

Patch

diff --git a/common/menu.c b/common/menu.c
index b577d80b4f..4118c6dc3c 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -271,6 +271,9 @@  int menu_get_choice(struct menu *m, void **choice)
 	if (!m || !choice)
 		return -EINVAL;
 
+	if (m->item_cnt == 0)
+		return -ENOENT;
+
 	if (!m->prompt)
 		return menu_default_choice(m, choice);