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 501DFC4332F for ; Fri, 4 Nov 2022 22:50:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42EBB851C5; Fri, 4 Nov 2022 23:49:28 +0100 (CET) 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="GAoi7Vc4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5DDB5851EA; Fri, 4 Nov 2022 23:49:19 +0100 (CET) Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) (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 4D7D585191 for ; Fri, 4 Nov 2022 23:49:12 +0100 (CET) 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-x133.google.com with SMTP id d3so1287845ils.1 for ; Fri, 04 Nov 2022 15:49:12 -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=dh/ODZpkrvwS6b7Rz3DCF2bliap+SqzhqaUP4+4Didc=; b=GAoi7Vc4Vq3zeYaBt7VSNUJqunvH0D33qtEobD2RRI/hWCTI1DRmPhjd3nV5IPx7EZ a9O+gYszTkjuNlkIj2g7TZN4jQTp6zpv9xwlhlaK2wZ9t59uaE0J/wTOYsEauj0KrNrO 34HYy63VR7+NjpPK/RPBfxDoxq/3uskN8FP+w= 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=dh/ODZpkrvwS6b7Rz3DCF2bliap+SqzhqaUP4+4Didc=; b=gJWBzKvuR4Jg88unPgj89aBqIOvVx6Kv4OC8Yw7IOLqi70bUMpcm51ZXNGvrL4ec1A u7UXYpqC3UXDc5QjnM9TcvXcm+7s+Lvdgenr9mfQV2qmCxVBXc5NmAEtdlD/Q/gozXDI 52ZcBeg+maCoMtA+uXCkQ0GIxIO1WgrhKKyWx42kyMZavLngZidh+Ed0iDzU/xArzAqy jBaoqPcixacdsn6h/VDIwCoQo7gtGjF0RbmBdOh1hvPR7yKPHSzlKwBFQNClTpB+hTtV 0L/PgWonU8pXzYxWg9FTkeGUWsHQUe5pC/x8FfNj4XWvkKe/x6P2SnfG8+coHGVzNEBb WgOA== X-Gm-Message-State: ACrzQf2g84r17sfOlRzX/GkV71UpzrinwuPcjLVola91PXgErpPwBnvk PBLo3bjceTkILtdJdWSxX4Sh14DuGCjUPA== X-Google-Smtp-Source: AMsMyM6rssQNo4YpqwS4/Q/6r2gnCL28FsowvqmMastAjrNJ63kU5kyW6QYJGTkT/cOM+k4mjTWnGQ== X-Received: by 2002:a05:6e02:ca3:b0:300:c4e6:8493 with SMTP id 3-20020a056e020ca300b00300c4e68493mr270559ilg.233.1667602150635; Fri, 04 Nov 2022 15:49:10 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id w24-20020a05663800d800b003734c4d01d2sm95189jao.61.2022.11.04.15.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 15:49:10 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Anatolij Gustschin , Simon Glass , Ilias Apalodimas , Masahisa Kojima , Stefan Roese Subject: [PATCH v2 06/25] menu: Update bootmenu_loop() to return the code Date: Fri, 4 Nov 2022 16:48:24 -0600 Message-Id: <20221104224844.467576-7-sjg@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221104224844.467576-1-sjg@chromium.org> References: <20221104224844.467576-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 --- (no changes since v1) 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 bafc8470d7d..6842f5409d6 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.1.431.g37b22c650d-goog