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 31F4BC19F2A for ; Sun, 7 Aug 2022 15:51:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 030B08498A; Sun, 7 Aug 2022 17:48:24 +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="buGtFO8c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 04DC98490F; Sun, 7 Aug 2022 17:48:16 +0200 (CEST) Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) (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 8DF56848CF for ; Sun, 7 Aug 2022 17:48:05 +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-oi1-x22a.google.com with SMTP id q184so7887104oif.1 for ; Sun, 07 Aug 2022 08:48:05 -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; bh=pd62P4THb429DwVR7MpXFVnpnH6xSedC3wnHw/RRMVw=; b=buGtFO8cvO1XViyG2awQiHnWMA7hTzcNH3ejMgTgFZuZSTcPfdDfvcbdPlEGFKZrkR xnPTekPNBxOiJWRDmRMjpUCh1wzoNA6FutwHD9NTb9Sbs9hbv3ZFjdx4XTkbCdvw6sir rk+SwVT+OHTxDc0c/UQx9wwG3f3nP2y7kgGys= 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; bh=pd62P4THb429DwVR7MpXFVnpnH6xSedC3wnHw/RRMVw=; b=RuWfIligxGxKITey39cR5hvXTAOE2cEXiB/2OmeQ7+QuUr3/slbQHNe60QfAGp7G/p MavWv25c75DpGctJ6JdY2ZVfFiuSJFtZQaeqAkgxZochg6WYKj4QVXMb3Kyb9ARSSyiM m7JoKJvnIqHHZAdxPKl7QPuvMA9IKwLaIUycfd6rajhajtzxhXmtWioCz0WSNixNqQ49 WNwnYSxd2BuJHxPZZs/QuhQeV/i8swUCCALS6mzWdEWbqV/FbqL+4My9Kljb+GJZD7Yz Or3aOLtd0XbySkpa+Wy2sYSsO2glkJ28KewcneqSZn8rATUDn+QjwjFCndbM4zgHXEC6 FcnA== X-Gm-Message-State: ACgBeo2m41Z6LR91M8S/klyO7GaeUmwGvaT05mm8nonWtUwH47vJRl21 D0Z6kWCAi0StSRRi4YK6sNSX5ryZxso82g== X-Google-Smtp-Source: AA6agR6yP7GpRw+Zx0erYXAuuuyOO7V7zoDPVaw3r9l2w3ZlOZKk2JpN5d2paS/cYHulgyPb7U1L0A== X-Received: by 2002:a05:6808:2121:b0:33a:5639:5bc6 with SMTP id r33-20020a056808212100b0033a56395bc6mr6321921oiw.160.1659887284974; Sun, 07 Aug 2022 08:48:04 -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 y18-20020a056808131200b0034290c4ed01sm1553412oiv.41.2022.08.07.08.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 08:48:04 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , AKASHI Takahiro Subject: [PATCH 19/23] blk: Rewrite if_type to name functions Date: Sun, 7 Aug 2022 09:47:04 -0600 Message-Id: <20220807154708.1418967-20-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220807154708.1418967-1-sjg@chromium.org> References: <20220807154708.1418967-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 These are currently using a simple array lookup in one direction, and relying on if_type being sequential. With the move to uclass IDs this needs to change. Update the code to prepare for the new way. This patch is intended to introduce no functional change. The returning of "(none)" from blk_get_if_type_name() is handling a case that should not happen in either case. Signed-off-by: Simon Glass --- drivers/block/blk-uclass.c | 45 +++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 3738517d8d0..a68158c3f25 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -17,18 +17,21 @@ #include #include -static const char *if_typename_str[IF_TYPE_COUNT] = { - [IF_TYPE_IDE] = "ide", - [IF_TYPE_SCSI] = "scsi", - [IF_TYPE_USB] = "usb", - [IF_TYPE_MMC] = "mmc", - [IF_TYPE_SATA] = "sata", - [IF_TYPE_HOST] = "host", - [IF_TYPE_NVME] = "nvme", - [IF_TYPE_EFI_MEDIA] = "efi", - [IF_TYPE_EFI_LOADER] = "efiloader", - [IF_TYPE_VIRTIO] = "virtio", - [IF_TYPE_PVBLOCK] = "pvblock", +static struct { + enum uclass_id id; + const char *name; +} if_typename_str[] = { + { IF_TYPE_IDE, "ide" }, + { IF_TYPE_SCSI, "scsi" }, + { IF_TYPE_USB, "usb" }, + { IF_TYPE_MMC, "mmc" }, + { IF_TYPE_SCSI, "sata" }, + { IF_TYPE_HOST, "host" }, + { IF_TYPE_NVME, "nvme" }, + { IF_TYPE_EFI_MEDIA, "efi" }, + { IF_TYPE_EFI_LOADER, "efiloader" }, + { IF_TYPE_VIRTIO, "virtio" }, + { IF_TYPE_PVBLOCK, "pvblock" }, }; static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = { @@ -49,10 +52,9 @@ static enum if_type if_typename_to_iftype(const char *if_typename) { int i; - for (i = 0; i < IF_TYPE_COUNT; i++) { - if (if_typename_str[i] && - !strcmp(if_typename, if_typename_str[i])) - return i; + for (i = 0; i < ARRAY_SIZE(if_typename_str); i++) { + if (!strcmp(if_typename, if_typename_str[i].name)) + return if_typename_str[i].id; } return IF_TYPE_UNKNOWN; @@ -65,7 +67,14 @@ static enum uclass_id if_type_to_uclass_id(enum if_type if_type) const char *blk_get_if_type_name(enum if_type if_type) { - return if_typename_str[if_type]; + int i; + + for (i = 0; i < ARRAY_SIZE(if_typename_str); i++) { + if ((int)if_typename_str[i].id == if_type) + return if_typename_str[i].name; + } + + return "(none)"; } struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum) @@ -104,7 +113,7 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum) uclass_id = if_type_to_uclass_id(type); if (uclass_id == UCLASS_INVALID) { debug("%s: Unknown uclass for interface type'\n", - if_typename_str[type]); + blk_get_if_type_name(type)); return NULL; } -- 2.37.1.559.g78731f0fdb-goog