Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D69DC433FE for ; Mon, 17 Oct 2022 20:36:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 121D584FBF; Mon, 17 Oct 2022 22:32:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PR9jT8t9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A24584F53; Mon, 17 Oct 2022 22:30:35 +0200 (CEST) Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 80E8884F61 for ; Mon, 17 Oct 2022 22:30:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x135.google.com with SMTP id d14so6451101ilf.2 for ; Mon, 17 Oct 2022 13:30:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SDl6tg8XeIq7tXVfeBxWxXM/QOb2zElXpwa5kCS4HWw=; b=PR9jT8t9t0QKUKrkV604JCd6RjOKKk5rOcCHVtFzrZmyGXQEosQhwD4Pqbv50s6QEJ GmYFKLPLTGPPhvBvyOH6dX3aZW2yEiCl6pyWwnPx+jX12oTerQN7Wi1q2WnA3pUdSPyv QL82WZo/8CPke5PVe487u74k+6KSNl68sVk7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SDl6tg8XeIq7tXVfeBxWxXM/QOb2zElXpwa5kCS4HWw=; b=JZJM85tJpZYUt9Cq/CdgJ8bN019GyzEDEU4TneGxtqqCGA4rp/KlBafDEfvZMCOv0y kxwB0szssn3r9jyXg2vL8D5ID4PP9cdbGF2lgUcLZYG0CvBTkyJ1BBvIKdzcv2vhIhcp 5QKZXEi/j5vlY2R6I3j2xjWPvXQ1i1bAsLVKoaXU2nbVlhJCj04KDxALF7L4dvfMX2ox 0ga1w7WvXIU+cyTSEdAqJUrUApzWH3uBNBPb32nIii2BhNHFItf97iFwehmiTzr006zA 9TkMTo+IBOCLOpi6FmsFUTkCzpBZOJZs+JwMW/htKx3YXR/4C1rIul+7EpibYGOxCAuP XW6A== X-Gm-Message-State: ACrzQf2MOxP+xyV5zs4VruCPuomRj7MtqEyjGOZ/gI0lchcP4v33bNQx 1nQ8CeFAGeH3/XOMkAquMZSiAXRqAKpDsg== X-Google-Smtp-Source: AMsMyM7jXGNbHK2miuWv5UyqN0EWGCXeYJE7JTuoN5iTb7XFgvlYe63AfgSEwenyXZjDQ1Nw9WHWGQ== X-Received: by 2002:a05:6e02:1bed:b0:2f9:fd4e:e79a with SMTP id y13-20020a056e021bed00b002f9fd4ee79amr5783297ilv.133.1666038619513; Mon, 17 Oct 2022 13:30:19 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:91e:7804:2764:d161]) by smtp.gmail.com with ESMTPSA id j9-20020a926e09000000b002e939413e83sm258071ilc.48.2022.10.17.13.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 13:30:18 -0700 (PDT) From: Simon Glass To: u-boot@lists.denx.de Cc: Anatolij Gustschin , Tom Rini , Simon Glass , Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH 06/24] menu: Update bootmenu_loop() to return the code Date: Mon, 17 Oct 2022 14:29:42 -0600 Message-Id: <20221017203000.2207887-7-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221017203000.2207887-1-sjg@chromium.org> References: <20221017203000.2207887-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Use the return value to save having to pass around a pointer. This also resolves any ambiguity about what *key contains when the function is called. Signed-off-by: Simon Glass --- cmd/bootmenu.c | 2 +- cmd/eficonfig.c | 4 ++-- common/menu.c | 30 ++++++++++++++++-------------- include/menu.h | 11 +++++------ 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 0e22f504fe4..573afe16609 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -96,7 +96,7 @@ static char *bootmenu_choice_entry(void *data) key = bootmenu_autoboot_loop(menu, &esc); } else { /* Some key was pressed, so autoboot was stopped */ - bootmenu_loop(menu, &key, &esc); + key = bootmenu_loop(menu, &esc); } switch (key) { diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index de7ce24f5ac..18f173e33ab 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -197,7 +197,7 @@ static char *eficonfig_choice_entry(void *data) struct efimenu *efi_menu = data; while (1) { - bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc); + key = bootmenu_loop((struct bootmenu_data *)efi_menu, &esc); switch (key) { case BKEY_UP: @@ -1868,7 +1868,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) struct eficonfig_boot_order *entry; while (1) { - bootmenu_loop(NULL, &key, &esc); + key = bootmenu_loop(NULL, &esc); switch (key) { case BKEY_PLUS: diff --git a/common/menu.c b/common/menu.c index bccc104a39b..22947f5d693 100644 --- a/common/menu.c +++ b/common/menu.c @@ -476,9 +476,9 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) return key; } -void bootmenu_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc) +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc) { + enum bootmenu_key key = BKEY_NONE; int c; if (*esc == 1) { @@ -505,17 +505,17 @@ void bootmenu_loop(struct bootmenu_data *menu, /* First char of ANSI escape sequence '\e' */ if (c == '\e') { *esc = 1; - *key = BKEY_NONE; + key = BKEY_NONE; } break; case 1: /* Second char of ANSI '[' */ if (c == '[') { *esc = 2; - *key = BKEY_NONE; + key = BKEY_NONE; } else { /* Alone ESC key was pressed */ - *key = BKEY_QUIT; + key = BKEY_QUIT; *esc = (c == '\e') ? 1 : 0; } break; @@ -524,7 +524,7 @@ void bootmenu_loop(struct bootmenu_data *menu, /* Third char of ANSI (number '1') - optional */ if (*esc == 2 && c == '1') { *esc = 3; - *key = BKEY_NONE; + key = BKEY_NONE; break; } @@ -532,31 +532,33 @@ void bootmenu_loop(struct bootmenu_data *menu, /* ANSI 'A' - key up was pressed */ if (c == 'A') - *key = BKEY_UP; + key = BKEY_UP; /* ANSI 'B' - key down was pressed */ else if (c == 'B') - *key = BKEY_DOWN; + key = BKEY_DOWN; /* other key was pressed */ else - *key = BKEY_NONE; + key = BKEY_NONE; break; } /* enter key was pressed */ if (c == '\r') - *key = BKEY_SELECT; + key = BKEY_SELECT; /* ^C was pressed */ if (c == 0x3) - *key = BKEY_QUIT; + key = BKEY_QUIT; if (c == '+') - *key = BKEY_PLUS; + key = BKEY_PLUS; if (c == '-') - *key = BKEY_MINUS; + key = BKEY_MINUS; if (c == ' ') - *key = BKEY_SPACE; + key = BKEY_SPACE; + + return key; } diff --git a/include/menu.h b/include/menu.h index 9f30a3c1acd..8b9b36214f7 100644 --- a/include/menu.h +++ b/include/menu.h @@ -83,7 +83,10 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc); * character is recognised * * @menu: Menu being processed - * @key: Returns the code for the key the user pressed: + * @esc: On input, a non-zero value indicates that an escape sequence has + * resulted in that many characters so far. On exit this is updated to the + * new number of characters + * Returns: code for the key the user pressed: * enter: BKEY_SELECT * Ctrl-C: BKEY_QUIT * Up arrow: BKEY_UP @@ -92,11 +95,7 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc); * Plus: BKEY_PLUS * Minus: BKEY_MINUS * Space: BKEY_SPACE - * @esc: On input, a non-zero value indicates that an escape sequence has - * resulted in that many characters so far. On exit this is updated to the - * new number of characters */ -void bootmenu_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc); +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc); #endif /* __MENU_H__ */ -- 2.38.0.413.g74048e4d9e-goog