From patchwork Mon May 2 14:18:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josua Mayer X-Patchwork-Id: 1625123 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 (2048-bit key; unprotected) header.d=solid-run-com.20210112.gappssmtp.com header.i=@solid-run-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=CBu6BbOC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4KsQHw4srTz9sFr for ; Tue, 3 May 2022 00:21:16 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5301983F4C; Mon, 2 May 2022 16:19:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=solid-run.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=solid-run-com.20210112.gappssmtp.com header.i=@solid-run-com.20210112.gappssmtp.com header.b="CBu6BbOC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 16B2D83E2B; Mon, 2 May 2022 16:19:15 +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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) (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 D1C2F83E57 for ; Mon, 2 May 2022 16:18:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=solid-run.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=josua@solid-run.com Received: by mail-wm1-x334.google.com with SMTP id a14-20020a7bc1ce000000b00393fb52a386so10271522wmj.1 for ; Mon, 02 May 2022 07:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=solid-run-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9+JoX+a5/XHvP+SPO9QZQSty5KA5/c2sKXAMSgLwCO8=; b=CBu6BbOCo/eFr8YVYkpukjCRloKDOhNdkRVTCZHL1GrZ1D2OuVAyQYOkVyDyCg8rrn IPILg7DvmtFCbLgrWor1as7itYDv9fSwRPrvneqBtFZH8yBpCXslcmSDcBSRA3tD0Tp7 KZB+YJdW26MxGh+e8Lq2L3hQRIqKc3bzmen75qZbapceDcHoAW7SIBchf5aeRIlfjucU 3wRMWgM0svPcDvv+R0MPfWbeVDrXwcyN+51q0DDjr5KH2Z5NZEEc6NNqcFORhNIVFJYF Le29Y+VfDEAly4a0s4+n/fN4ZOnj3vZTtdCAoRzB47w15zRhnX0/IMFUT2zThzKawc9Q MtHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9+JoX+a5/XHvP+SPO9QZQSty5KA5/c2sKXAMSgLwCO8=; b=ONj5YtWcRgQUCNmiZ/Amx+ymOTw5OjmC0X2gXF0/HfbYnzk/m0cb/hyiiI60Rx2Idu Lcc4sQplWlMNgy1DVfxbEGnwQo6TgqLpCjG06RK9+0Czwg+4NPElFvA+QAV+VIgE/Oi8 XCfHYyqBdvoNye0XOA/CtRgciy3UgmgJEVnaXQzvxtYVya2yF2cNhowGY8tl9CkjJwam iZOGHPQUbLloHMH3UD3utsPDsc6D8ehoPo5uN53i+E1tF2LZ7hEic9c+NmrL7STu1iMt 8WYgiuWmyDIrAAom/61YbQkPg4j5JBTi4cfU0b58FcR25s/ffIoGGtgSKSYmvaacSZG7 MDKQ== X-Gm-Message-State: AOAM530KNT+4gzSk2Ad/8vLTdADp07rYjOaV9zq1ysqOcv+NBngv7HG3 Re/kAxeto1O/YqJOGpP8nixJRW8rqjjACA== X-Google-Smtp-Source: ABdhPJyluSCIoePr6nDWiBCg/b+AzTqACMAuNriscNcXcgBEdYh0qB2YLa/IqQKu7qJ02x5tF+ArfQ== X-Received: by 2002:a05:600c:48b:b0:394:2ee9:5847 with SMTP id d11-20020a05600c048b00b003942ee95847mr10106777wme.117.1651501136156; Mon, 02 May 2022 07:18:56 -0700 (PDT) Received: from josua-work.lan (bzq-82-81-222-124.cablep.bezeqint.net. [82.81.222.124]) by smtp.gmail.com with ESMTPSA id t1-20020adfba41000000b0020c6fa5a797sm940035wrg.91.2022.05.02.07.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 07:18:55 -0700 (PDT) From: Josua Mayer To: u-boot@lists.denx.de Cc: Josua Mayer , Sven Auhagen , Simon Glass , Stefan Roese Subject: [PATCH 07/12] cmd: tlv_eeprom: hide access to static tlv_devices array behind accessor Date: Mon, 2 May 2022 17:18:33 +0300 Message-Id: <20220502141838.15912-8-josua@solid-run.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220502141838.15912-1-josua@solid-run.com> References: <20220502141838.15912-1-josua@solid-run.com> 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.5 at phobos.denx.de X-Virus-Status: Clean The tlv_eeprom command logic checks the static tlv_devices array to validate the eeprom number. This array will be move to a separate tlv library. Hide this access behind a new function exists_tlv_eeprom. Signed-off-by: Josua Mayer --- cmd/tlv_eeprom.c | 12 ++++++++++-- include/tlv_eeprom.h | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/tlv_eeprom.c b/cmd/tlv_eeprom.c index 57468edb1c..f51a9666bf 100644 --- a/cmd/tlv_eeprom.c +++ b/cmd/tlv_eeprom.c @@ -44,6 +44,14 @@ static struct udevice *tlv_devices[MAX_TLV_DEVICES]; #define to_header(p) ((struct tlvinfo_header *)p) #define to_entry(p) ((struct tlvinfo_tlv *)p) +/** + * Check whether eeprom device exists. + */ +bool exists_tlv_eeprom(int dev) +{ + return dev < TLV_MAX_DEVICES && tlv_devices[dev] != 0; +} + static inline bool is_digit(char c) { return (c >= '0' && c <= '9'); @@ -481,7 +489,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) unsigned int devnum; devnum = simple_strtoul(argv[2], NULL, 0); - if (devnum > MAX_TLV_DEVICES || !tlv_devices[devnum]) { + if (!exists_tlv_eeprom(devnum)) { printf("Invalid device number\n"); return 0; } @@ -866,7 +874,7 @@ static void show_tlv_devices(int current_dev) unsigned int dev; for (dev = 0; dev < MAX_TLV_DEVICES; dev++) - if (tlv_devices[dev]) + if (exists_tlv_eeprom(dev)) printf("TLV: %u%s\n", dev, (dev == current_dev) ? " (*)" : ""); } diff --git a/include/tlv_eeprom.h b/include/tlv_eeprom.h index dc7952da6b..c81c58837d 100644 --- a/include/tlv_eeprom.h +++ b/include/tlv_eeprom.h @@ -69,6 +69,13 @@ struct __attribute__ ((__packed__)) tlvinfo_tlv { /* how many EEPROMs can be used */ #define TLV_MAX_DEVICES 2 +/** + * Check whether eeprom device exists. + * + * @dev: EEPROM device to check. + */ +bool exists_tlv_eeprom(int dev); + /** * read_tlv_eeprom - Read the EEPROM binary data from the hardware * @eeprom: Pointer to buffer to hold the binary data