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 19990C4708E for ; Wed, 7 Dec 2022 09:06:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 787E385713; Wed, 7 Dec 2022 09:56:59 +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="BpTFvODs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3572D8566D; Wed, 7 Dec 2022 09:56:54 +0100 (CET) Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (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 EFE2D856ED for ; Wed, 7 Dec 2022 09:56:50 +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-pj1-x1034.google.com with SMTP id q17-20020a17090aa01100b002194cba32e9so852859pjp.1 for ; Wed, 07 Dec 2022 00:56:50 -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=ejaDGz4tw1lbpZ2QDY8dD+oO9TQrhAXNaI6ry8hOMf0=; b=BpTFvODs96UH4/62d5XybortJOr1BKFG0nWc5gOQLZuXRgR/ioFju6n9iy3K3ee6B4 6GmW77NTWw6tMlNhOnfOqIBhBuyCUj3kCC273YyGDk/DtTDo499oUAeteocUioJHb/iX E8Ni9UP/qUXeMvSndVU2IGeFuaHD96JIOejvg= 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=ejaDGz4tw1lbpZ2QDY8dD+oO9TQrhAXNaI6ry8hOMf0=; b=M9GFdw+s/CTTgQHqhmk9gDqcKWWcqVTTVguPC7Ctg4l7sAf51WQdStrWDfVYS3HtYh FtZAQwXMYdDpY9up0OFE1vu1y1ZQgDkWHxFmwBhurAzDnCooO+zDziP0TqDh8WTDbhe/ mk14GeoDNC1d1yy5gO757XSaDlJeo2LOJeKCUqhluKklb+CoFwI/xNPDvZCmNEe36B8r peUiEuOWhFLiYxm0SRLFERBZ6chnRSSYmjM1SmJ/lfdBJEAKS0BRLIi7itz81Rq2sUbe m36EeFoV/LL5shYfyRM0CAHYq2bKzEzy0tJIYr2w7ivENfPIFs38BHfQ6t+5v2ZQE6xV bt0g== X-Gm-Message-State: ANoB5plwsSTnqdPUthGF7G+iw2BMqo7tKQBFwbcbK6z8A9BWnhV5bi3q D9/aiNreYyaVnZvrUNNE2ow+bdcZDQBskew8 X-Google-Smtp-Source: AA0mqf523jvFFgtEi7A95PyIFBaDKdGOMWwOKN5AoH66jlY8aDBkVIa5/hOR/SKzUElI2IGjXC3lfQ== X-Received: by 2002:a17:902:ff02:b0:189:8795:ef75 with SMTP id f2-20020a170902ff0200b001898795ef75mr47489186plj.1.1670403409126; Wed, 07 Dec 2022 00:56:49 -0800 (PST) Received: from localhost.localdomain ([27.110.126.54]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b0018157b415dbsm14145514plh.63.2022.12.07.00.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:56:48 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH 51/71] bootstd: Move label parsing into its own function Date: Wed, 7 Dec 2022 21:51:17 +1300 Message-Id: <20221207085137.445249-52-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog In-Reply-To: <20221207085137.445249-1-sjg@chromium.org> References: <20221207085137.445249-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 --- 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.rc0.267.gcb52ba06e7-goog