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 3B290C54EBC for ; Sun, 8 Jan 2023 03:02:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C4D83856EB; Sun, 8 Jan 2023 03:57:22 +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="P1AtwfhV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9144B856A6; Sun, 8 Jan 2023 03:56:43 +0100 (CET) Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) (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 ED5C585660 for ; Sun, 8 Jan 2023 03:51:31 +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-x130.google.com with SMTP id c20so3284627ilj.10 for ; Sat, 07 Jan 2023 18:51:31 -0800 (PST) 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=8OR9KswrPtnhqQhSg3FMOyeUBO7KQyEL7BcqaNKf61c=; b=P1AtwfhVwrbzTkFwPlkvZ/RGDL1wccF7/hT53w1mgFQVolhZxvt3FmBGTDMQS0Ilp8 lWUWJ8snwtSLDG4Vl9SSdVu/1r67VhEe2uP3G7lOvApy/8lOMvKLFg1oyBdIo6rHCvJU /qv217CQL0yONdGpUt/cSR7ScqfmIpyVZHVzg= 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=8OR9KswrPtnhqQhSg3FMOyeUBO7KQyEL7BcqaNKf61c=; b=LgvBGr0VL7rnUoWr5gVmdPkrPQx7PKELgcu6d2/rVC/eZwiQ3/UY4hLw1Y1p6pSSdv P/5yVFOWtkLY59ovikJJE/9w7ff66MWLwP31Gtm+x2z9Tbz8XlEKMDzss5r2Kw4/6sdR pdQc5ZK4Un9KfZd1f898H2X1rqprxbh+X5o/HwQgfygsJyPZ+eBksX4mf4zbjmIMfW+b UsTK7q0IOnjRYvMeHy2AykOYUx6bw7WcPconpWJVybR+drxfSR8Tu5zJuvC14ej5ujM0 zK868sX3XyTo4wIDb1wyFL8PTETG12xXkTRfJqXGIa13iQi3CJAzjxD+gzZKkrchpCea UHbg== X-Gm-Message-State: AFqh2kpjvmNrhSRw3YgEY0PZoxCmkjNkf1Wo2wNq+seash2/n4428ExY Ry1/SGv5jl9IvIHb7AcgI0bkLF5hnZCNSubH X-Google-Smtp-Source: AMrXdXsA8FlOQ0UyLOVsspcmayNEos2O8O0viI9Fku+4ywZoDPh7jNqgnwDtBSttRlJZzfoHSOrY4A== X-Received: by 2002:a92:ad10:0:b0:30b:b982:7632 with SMTP id w16-20020a92ad10000000b0030bb9827632mr39731388ilh.23.1673146291358; Sat, 07 Jan 2023 18:51:31 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id c17-20020a92bd11000000b00302a00aaefasm1622174ile.26.2023.01.07.18.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:31 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH v2 51/71] bootstd: Move label parsing into its own function Date: Sat, 7 Jan 2023 19:50:27 -0700 Message-Id: <20230108025047.522240-52-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230108025047.522240-1-sjg@chromium.org> References: <20230108025047.522240-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 This is complicated enough to merit its own function, particularly as we are about to add to it. Create a new label_to_uclass() function to decode a label. Also update the code to ignore an empty label or one consisting of just a number. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootdev-uclass.c | 48 ++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index 3dcf317c150..f43307d006d 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -354,6 +354,37 @@ int bootdev_unbind_dev(struct udevice *parent) return 0; } +/** + * label_to_uclass() - Convert a label to a uclass and sequence number + * + * @label: Label to look up (e.g. "mmc1" or "mmc0") + * @seqp: Returns the sequence number, or -1 if none + * Returns: sequence number on success, else -ve error code + */ +static int label_to_uclass(const char *label, int *seqp) +{ + enum uclass_id id; + const char *end; + int seq, len; + + seq = trailing_strtoln_end(label, NULL, &end); + len = end - label; + if (!len) + return -EINVAL; + id = uclass_get_by_namelen(label, len); + log_debug("find %s: seq=%d, id=%d/%s\n", label, seq, id, + uclass_get_name(id)); + if (id == UCLASS_INVALID) { + log_warning("Unknown uclass '%s' in label\n", label); + return -EINVAL; + } + if (id == UCLASS_USB) + id = UCLASS_MASS_STORAGE; + *seqp = seq; + + return id; +} + /** * bootdev_find_by_label() - Convert a label string to a bootdev device * @@ -372,19 +403,12 @@ int bootdev_find_by_label(const char *label, struct udevice **devp) struct udevice *media; struct uclass *uc; enum uclass_id id; - const char *end; - int seq; + int seq, ret; - seq = trailing_strtoln_end(label, NULL, &end); - id = uclass_get_by_namelen(label, end - label); - log_debug("find %s: seq=%d, id=%d/%s\n", label, seq, id, - uclass_get_name(id)); - if (id == UCLASS_INVALID) { - log_warning("Unknown uclass '%s' in label\n", label); - return -EINVAL; - } - if (id == UCLASS_USB) - id = UCLASS_MASS_STORAGE; + ret = label_to_uclass(label, &seq); + if (ret < 0) + return log_msg_ret("uc", ret); + id = ret; /* Iterate through devices in the media uclass (e.g. UCLASS_MMC) */ uclass_id_foreach_dev(id, media, uc) { -- 2.39.0.314.g84b9a713c41-goog