From patchwork Mon Nov 11 22:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009937 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=iEDuoV+s; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=cQxXreQf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XnNpc17HLz1xwF for ; Tue, 12 Nov 2024 09:03:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/UxwUZqgCb5tp+a1kEDqWmxzmlZUQuIG++XpDZP7Czk=; b=iEDuoV+sFh7y9o FOW8sP/H7FX66JwkwAm6KMBGDVONPd5jyWLesOGUqKLea+pBtut87M3orKG5hw8ASzfUF4lLYF4Pn QSpqCp5MHOy/R8EBcgnWCghzm7QV40YpbPG1QvAcltZhNfMvyp8Vj7E9G+0ZuU+fNZThBPb5cbjpJ giSWw05r04q2wYxQMlzsTuZ8YX94dyQ/KhA6Jg2WAN5LLiurVk2vXbdGZFqZ01OEZKZQvJGBXga7t NzjmHeHUTOO5kYCQga1YtAAwG+DZNm02iu1LXspvy333ueX3YncLmPefyfUfiJM5ShtuRWz0BGtsh IGlrYfE+yD02SoRNpDgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV5-00000001RM8-0tuN; Mon, 11 Nov 2024 22:03:11 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV2-00000001RKs-0scv for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:09 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-20ca388d242so50470035ad.2 for ; Mon, 11 Nov 2024 14:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362587; x=1731967387; darn=lists.infradead.org; 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=/eTQ+51Ayqlm4hws28hLYsecciVj5QxzxcaytKE4UNE=; b=cQxXreQfwpVyoa1UftpVMRAl3qrmmzLbIkpJqJKiY1HHqIgSUDKKzrWFiy5rqO0Wen 4WVnDdsfriHpzQmrUAr4IAfyHbp7C6OY+p01IE/gZGE1tu141FOehhjEHXXjSrIzc/Pl HbtTag8Y+nOThprAgscA1p865ycvau4/++bssSCrQS659pz8CGtC9AdpQZVMNRCFDin9 O8FgRfjdkkTN7pONFDU47e4+YuSJwMld8WV6+82PeIZg3Z15dIg79kinBX0dFuVUAk/v zpjywXEA8jgvm7BgGCaNAodLsI9aUOMZDSVAiifHp107iLLqwX8m7uqHQjc6w02cwXx2 qbVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362587; x=1731967387; 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=/eTQ+51Ayqlm4hws28hLYsecciVj5QxzxcaytKE4UNE=; b=HQdiCR2H5ePTyYE11zSIcEMcvTmIxZDqPhICiN/PvT9/F/3ZT5eTC65jI4GtDL9Oq7 rZFHNx5olR+Gc7c3BE3gZASlFr+iYT3VCI0WvmvW+coKncpqg2SJ2yENGXLX5Mh8qt6c 3fDgI0tjV14DFN4NDxIDm9AY2D2aT6KoiqPsl50/KaA41hd2uEeUTZE6AkLhNebIuEKc BnOAc3v6j3ewBSrNYr6Bz7Uh+4cu8betmotSYsPeC4StX+5UouL3AphU9FxoB+/ThkLd 6wkt3m7Qa8IOpOIR82zcnjt4PrO8bx7dXzBmX8fqtESFnZiIgc1JleL1VH0qCzPPFZSx /X/A== X-Gm-Message-State: AOJu0YwVbGt/l5Dt7K3izkKjw0xC+Y7Ge9RLjcRq/9u9G1Cfhafcq+VN lIJ1Q6XBc7sUEzf2umtZA9MksXd+OjTMffGNSV9rq8mGdYeMXw/QvKaUBfc73ABtgDnUtXiCmX6 DH9wusJ/f0oMF4p6UnR8v594rzB9FIZS6WK9GLHOdDremHh8auOj3JIiKb4DsR5WCcaziD612hI SLdEkVOKQgeYfW6NwYwn2NLmRfbaeXW9FbFFEvBbNl8xhOc90wxRo= X-Google-Smtp-Source: AGHT+IHQZIk7KOhe4VoWYvO/QSpJVOqEj861BqU0QNHaeI/G8/iNIKoxKoSeb3jmThd2yaFUjHVT9w== X-Received: by 2002:a17:902:cf12:b0:20c:528d:7063 with SMTP id d9443c01a7336-21183d4baa1mr206780755ad.19.1731362587367; Mon, 11 Nov 2024 14:03:07 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:06 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 01/11] treewide: Make carray arrays const and NULL-terminated Date: Mon, 11 Nov 2024 14:02:45 -0800 Message-ID: <20241111220304.1228821-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_140308_412785_82C4C99E X-CRM114-Status: GOOD ( 14.32 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also s [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:630 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- (no changes since v1) lib/sbi/sbi_ecall.c | 5 ++--- lib/sbi/tests/sbi_unit_test.c | 5 ++--- lib/utils/gpio/fdt_gpio.c | 5 ++--- lib/utils/i2c/fdt_i2c.c | 5 ++--- lib/utils/ipi/fdt_ipi.c | 5 ++--- lib/utils/irqchip/fdt_irqchip.c | 5 ++--- lib/utils/regmap/fdt_regmap.c | 5 ++--- lib/utils/reset/fdt_reset.c | 5 ++--- lib/utils/serial/fdt_serial.c | 7 +++---- lib/utils/timer/fdt_timer.c | 5 ++--- platform/generic/platform.c | 5 ++--- scripts/carray.sh | 7 +++---- 12 files changed, 26 insertions(+), 38 deletions(-) diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index d4fc58c5..be0b67e1 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -13,8 +13,7 @@ #include #include -extern struct sbi_ecall_extension *sbi_ecall_exts[]; -extern unsigned long sbi_ecall_exts_size; +extern struct sbi_ecall_extension *const sbi_ecall_exts[]; u16 sbi_ecall_version_major(void) { @@ -148,7 +147,7 @@ int sbi_ecall_init(void) struct sbi_ecall_extension *ext; unsigned long i; - for (i = 0; i < sbi_ecall_exts_size; i++) { + for (i = 0; sbi_ecall_exts[i]; i++) { ext = sbi_ecall_exts[i]; ret = SBI_ENODEV; diff --git a/lib/sbi/tests/sbi_unit_test.c b/lib/sbi/tests/sbi_unit_test.c index cd091663..d5e81568 100644 --- a/lib/sbi/tests/sbi_unit_test.c +++ b/lib/sbi/tests/sbi_unit_test.c @@ -11,8 +11,7 @@ #define ANSI_COLOR_RED "\x1b[31m" #define ANSI_COLOR_RESET "\x1b[0m" -extern struct sbiunit_test_suite *sbi_unit_tests[]; -extern unsigned long sbi_unit_tests_size; +extern struct sbiunit_test_suite *const sbi_unit_tests[]; static void run_test_suite(struct sbiunit_test_suite *suite) { @@ -48,6 +47,6 @@ void run_all_tests(void) sbi_printf("\n# Running SBIUNIT tests #\n"); - for (i = 0; i < sbi_unit_tests_size; i++) + for (i = 0; sbi_unit_tests[i]; i++) run_test_suite(sbi_unit_tests[i]); } diff --git a/lib/utils/gpio/fdt_gpio.c b/lib/utils/gpio/fdt_gpio.c index 953fa13a..eac2b863 100644 --- a/lib/utils/gpio/fdt_gpio.c +++ b/lib/utils/gpio/fdt_gpio.c @@ -13,8 +13,7 @@ #include /* List of FDT gpio drivers generated at compile time */ -extern struct fdt_gpio *fdt_gpio_drivers[]; -extern unsigned long fdt_gpio_drivers_size; +extern struct fdt_gpio *const fdt_gpio_drivers[]; static int fdt_gpio_init(const void *fdt, int nodeoff) { @@ -27,7 +26,7 @@ static int fdt_gpio_init(const void *fdt, int nodeoff) return SBI_EINVAL; /* Try all GPIO drivers one-by-one */ - for (pos = 0; pos < fdt_gpio_drivers_size; pos++) { + for (pos = 0; fdt_gpio_drivers[pos]; pos++) { drv = fdt_gpio_drivers[pos]; match = fdt_match_node(fdt, nodeoff, drv->match_table); diff --git a/lib/utils/i2c/fdt_i2c.c b/lib/utils/i2c/fdt_i2c.c index d23b40db..56891a0a 100644 --- a/lib/utils/i2c/fdt_i2c.c +++ b/lib/utils/i2c/fdt_i2c.c @@ -17,8 +17,7 @@ #include /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *fdt_i2c_adapter_drivers[]; -extern unsigned long fdt_i2c_adapter_drivers_size; +extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[]; static int fdt_i2c_adapter_init(const void *fdt, int nodeoff) { @@ -27,7 +26,7 @@ static int fdt_i2c_adapter_init(const void *fdt, int nodeoff) const struct fdt_match *match; /* Try all I2C drivers one-by-one */ - for (pos = 0; pos < fdt_i2c_adapter_drivers_size; pos++) { + for (pos = 0; fdt_i2c_adapter_drivers[pos]; pos++) { drv = fdt_i2c_adapter_drivers[pos]; match = fdt_match_node(fdt, nodeoff, drv->match_table); if (match && drv->init) { diff --git a/lib/utils/ipi/fdt_ipi.c b/lib/utils/ipi/fdt_ipi.c index c2ff9cfa..6c2feafb 100644 --- a/lib/utils/ipi/fdt_ipi.c +++ b/lib/utils/ipi/fdt_ipi.c @@ -13,8 +13,7 @@ #include /* List of FDT ipi drivers generated at compile time */ -extern struct fdt_ipi *fdt_ipi_drivers[]; -extern unsigned long fdt_ipi_drivers_size; +extern struct fdt_ipi *const fdt_ipi_drivers[]; int fdt_ipi_init(void) { @@ -23,7 +22,7 @@ int fdt_ipi_init(void) const struct fdt_match *match; const void *fdt = fdt_get_address(); - for (pos = 0; pos < fdt_ipi_drivers_size; pos++) { + for (pos = 0; fdt_ipi_drivers[pos]; pos++) { drv = fdt_ipi_drivers[pos]; noff = -1; diff --git a/lib/utils/irqchip/fdt_irqchip.c b/lib/utils/irqchip/fdt_irqchip.c index b4f054ae..0c8c76b2 100644 --- a/lib/utils/irqchip/fdt_irqchip.c +++ b/lib/utils/irqchip/fdt_irqchip.c @@ -13,8 +13,7 @@ #include /* List of FDT irqchip drivers generated at compile time */ -extern struct fdt_irqchip *fdt_irqchip_drivers[]; -extern unsigned long fdt_irqchip_drivers_size; +extern struct fdt_irqchip *const fdt_irqchip_drivers[]; #define FDT_IRQCHIP_MAX_DRIVERS 8 @@ -55,7 +54,7 @@ static int fdt_irqchip_cold_init(void) const struct fdt_match *match; const void *fdt = fdt_get_address(); - for (pos = 0; pos < fdt_irqchip_drivers_size; pos++) { + for (pos = 0; fdt_irqchip_drivers[pos]; pos++) { drv = fdt_irqchip_drivers[pos]; noff = -1; diff --git a/lib/utils/regmap/fdt_regmap.c b/lib/utils/regmap/fdt_regmap.c index 933938fb..ab991c45 100644 --- a/lib/utils/regmap/fdt_regmap.c +++ b/lib/utils/regmap/fdt_regmap.c @@ -13,8 +13,7 @@ #include /* List of FDT regmap drivers generated at compile time */ -extern struct fdt_regmap *fdt_regmap_drivers[]; -extern unsigned long fdt_regmap_drivers_size; +extern struct fdt_regmap *const fdt_regmap_drivers[]; static int fdt_regmap_init(const void *fdt, int nodeoff) { @@ -23,7 +22,7 @@ static int fdt_regmap_init(const void *fdt, int nodeoff) const struct fdt_match *match; /* Try all I2C drivers one-by-one */ - for (pos = 0; pos < fdt_regmap_drivers_size; pos++) { + for (pos = 0; fdt_regmap_drivers[pos]; pos++) { drv = fdt_regmap_drivers[pos]; match = fdt_match_node(fdt, nodeoff, drv->match_table); if (match && drv->init) { diff --git a/lib/utils/reset/fdt_reset.c b/lib/utils/reset/fdt_reset.c index 05deb75e..4b20c3e3 100644 --- a/lib/utils/reset/fdt_reset.c +++ b/lib/utils/reset/fdt_reset.c @@ -14,8 +14,7 @@ #include /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *fdt_reset_drivers[]; -extern unsigned long fdt_reset_drivers_size; +extern struct fdt_reset *const fdt_reset_drivers[]; int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv) { @@ -46,6 +45,6 @@ void fdt_reset_init(const void *fdt) { int pos; - for (pos = 0; pos < fdt_reset_drivers_size; pos++) + for (pos = 0; fdt_reset_drivers[pos]; pos++) fdt_reset_driver_init(fdt, fdt_reset_drivers[pos]); } diff --git a/lib/utils/serial/fdt_serial.c b/lib/utils/serial/fdt_serial.c index a2a96cb2..a7129bdd 100644 --- a/lib/utils/serial/fdt_serial.c +++ b/lib/utils/serial/fdt_serial.c @@ -14,8 +14,7 @@ #include /* List of FDT serial drivers generated at compile time */ -extern struct fdt_serial *fdt_serial_drivers[]; -extern unsigned long fdt_serial_drivers_size; +extern struct fdt_serial *const fdt_serial_drivers[]; int fdt_serial_init(const void *fdt) { @@ -46,7 +45,7 @@ int fdt_serial_init(const void *fdt) } /* First check DT node pointed by stdout-path */ - for (pos = 0; pos < fdt_serial_drivers_size && -1 < noff; pos++) { + for (pos = 0; fdt_serial_drivers[pos] && -1 < noff; pos++) { drv = fdt_serial_drivers[pos]; match = fdt_match_node(fdt, noff, drv->match_table); @@ -64,7 +63,7 @@ int fdt_serial_init(const void *fdt) } /* Lastly check all DT nodes */ - for (pos = 0; pos < fdt_serial_drivers_size; pos++) { + for (pos = 0; fdt_serial_drivers[pos]; pos++) { drv = fdt_serial_drivers[pos]; noff = -1; diff --git a/lib/utils/timer/fdt_timer.c b/lib/utils/timer/fdt_timer.c index 37965f5e..a2412409 100644 --- a/lib/utils/timer/fdt_timer.c +++ b/lib/utils/timer/fdt_timer.c @@ -13,8 +13,7 @@ #include /* List of FDT timer drivers generated at compile time */ -extern struct fdt_timer *fdt_timer_drivers[]; -extern unsigned long fdt_timer_drivers_size; +extern struct fdt_timer *const fdt_timer_drivers[]; int fdt_timer_init(void) { @@ -23,7 +22,7 @@ int fdt_timer_init(void) const struct fdt_match *match; const void *fdt = fdt_get_address(); - for (pos = 0; pos < fdt_timer_drivers_size; pos++) { + for (pos = 0; fdt_timer_drivers[pos]; pos++) { drv = fdt_timer_drivers[pos]; noff = -1; diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 3b20ffbe..2ffb41e2 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -30,8 +30,7 @@ #include /* List of platform override modules generated at compile time */ -extern const struct platform_override *platform_override_modules[]; -extern unsigned long platform_override_modules_size; +extern const struct platform_override *const platform_override_modules[]; static const struct platform_override *generic_plat = NULL; static const struct fdt_match *generic_plat_match = NULL; @@ -42,7 +41,7 @@ static void fw_platform_lookup_special(const void *fdt, int root_offset) const struct fdt_match *match; int pos; - for (pos = 0; pos < platform_override_modules_size; pos++) { + for (pos = 0; platform_override_modules[pos]; pos++) { plat = platform_override_modules[pos]; if (!plat->match_table) continue; diff --git a/scripts/carray.sh b/scripts/carray.sh index 1fa2366a..72808697 100755 --- a/scripts/carray.sh +++ b/scripts/carray.sh @@ -69,10 +69,9 @@ for VAR in ${VAR_LIST}; do done printf "\n" -printf "%s *%s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" +printf "%s *const %s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" for VAR in ${VAR_LIST}; do printf "\t&%s,\n" "${VAR}" done -printf "};\n\n" - -printf "unsigned long %s_size = sizeof(%s) / sizeof(%s *);\n" "${ARRAY_NAME}" "${ARRAY_NAME}" "${TYPE_NAME}" + printf "\tNULL\n" +printf "};\n"