From patchwork Fri Aug 12 01:34:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1665750 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=KO7uPHZX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M3mbF2Cyvz9sFs for ; Fri, 12 Aug 2022 11:40:41 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C97D84B16; Fri, 12 Aug 2022 03:36:31 +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="KO7uPHZX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD58784ACF; Fri, 12 Aug 2022 03:35:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (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 8618A84AD6 for ; Fri, 12 Aug 2022 03:35:47 +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-x229.google.com with SMTP id bb16so23324735oib.11 for ; Thu, 11 Aug 2022 18:35:47 -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=7lV5KzSYz2naVndVuraaZ8KDPEnBxFhgtVooAXnnDDo=; b=KO7uPHZX5q6diPnxDgv2KfBE23VkUTHhH4eDzYzPFF+9MpTDBJHEm2EThC0whJmx+S caHAXVssHwI8z8egeFqAegim84n73J1Ww2XPJ7qwxthtMBixt1AMDDcF9tormpKVhGne Yqy9zyps7SAHFZfp0nmMVIC6T0jT2WB+f5mxs= 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=7lV5KzSYz2naVndVuraaZ8KDPEnBxFhgtVooAXnnDDo=; b=aOJgfpDUGCTNS+K77CYUv17qRqW/PECGt8TJLCxJz1cmF2Nm13R2aGxmr0zAgeQJJF vRBESVej21YMyEIOC0IIlts7KjtoSx8u5TzFDhCHHKTdo4Ougv+RyOHFZ6lRn3qaqeNL zl15ET/5ONyg8AYn79gimJdTk0ZljHujGsSvN9lM6uu263vEuKt5gqnHaTmbO/QC1oVZ S9lukMxc0VgmJm7KHhv0reAN/yU0G66alE6ySjdibZYQlfN34ve0KoL4s2sNwY7RGFyS TO8a3cFaEuJiEaF1/CU8ZLHGqIWjYfUs9iISomEniB8Y4qNQjQ1Kly5x3k7+/aOkgECc gjSQ== X-Gm-Message-State: ACgBeo1mcQXes65zMlSJUPxRWOfh9KI9140bkn5xAxl8AQa5JWP9aQYH FS8fbgxfsk/cEWK8h6TRMF88JZc7K/C5cw== X-Google-Smtp-Source: AA6agR5xSnRW59ODiCU1vPJmpep32ct/nuYZF58lqLGzRthi9bNdhSOHBxsHf17wzJTOSMjUodMiQQ== X-Received: by 2002:aca:5c44:0:b0:33e:8629:b2f2 with SMTP id q65-20020aca5c44000000b0033e8629b2f2mr768621oib.189.1660268145959; Thu, 11 Aug 2022 18:35:45 -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 x21-20020a056870b41500b0010c5005d427sm158518oap.33.2022.08.11.18.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 18:35:45 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , AKASHI Takahiro Subject: [PATCH v2 18/24] blk: Rewrite if_type to name functions Date: Thu, 11 Aug 2022 19:34:57 -0600 Message-Id: <20220812013503.1724919-19-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220812013503.1724919-1-sjg@chromium.org> References: <20220812013503.1724919-1-sjg@chromium.org> MIME-Version: 1.0 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 --- (no changes since v1) 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; }