summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill XIE <persmule@hardenedlinux.org>2022-07-08 16:53:21 +0800
committerFelix Held <felix-coreboot@felixheld.de>2022-07-14 23:08:09 +0000
commitac136250b26ddcb54d61ed8428f110b607cb3c88 (patch)
tree40be3a5d3f1674bd18b44e3c45cc3ac1ef9af017
parentf7ba881f98db6561e8c4964663f8774e1a82f41b (diff)
downloadcoreboot-ac136250b26ddcb54d61ed8428f110b607cb3c88.tar.gz
coreboot-ac136250b26ddcb54d61ed8428f110b607cb3c88.tar.bz2
coreboot-ac136250b26ddcb54d61ed8428f110b607cb3c88.zip
commonlib: Substitude macro "__unused" in compiler.h
Since there are many identifiers whose name contain "__unused" in headers of musl libc, introducing a macro which expands "__unused" to the source of a util may have disastrous effect during its compiling under a musl-based platform. However, it is hard to detect musl at build time as musl is notorious for having explicitly been refusing to add a macro like "__MUSL__" to announce its own presence. Using __always_unused and __maybe_unused for everything may be a good idea. This is how it works in the Linux kernel, so that would at least make us match some other standard rather than doing our own thing (especially since the other compiler.h shorthand macros are also inspired by Linux). Signed-off-by: Bill XIE <persmule@hardenedlinux.org> Change-Id: I547ae3371d7568f5aed732ceefe0130a339716a9 Reviewed-on: https://review.coreboot.org/c/coreboot/+/65717 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r--src/arch/riscv/sbi.c2
-rw-r--r--src/commonlib/bsd/include/commonlib/bsd/compiler.h17
-rw-r--r--src/commonlib/region.c9
-rw-r--r--src/drivers/crb/tis.c2
-rw-r--r--src/drivers/spi/spi_sdcard.c2
-rw-r--r--src/ec/google/chromeec/ec.c2
-rw-r--r--src/soc/amd/common/block/lpc/spi_dma.c6
-rw-r--r--src/soc/amd/common/psp_verstage/boot_dev.c6
-rw-r--r--src/southbridge/intel/ibexpeak/me.c2
-rw-r--r--util/cbfstool/cbfstool.c2
-rw-r--r--util/sconfig/main.c2
11 files changed, 35 insertions, 17 deletions
diff --git a/src/arch/riscv/sbi.c b/src/arch/riscv/sbi.c
index 654bef03d6c3..415ea9499dc2 100644
--- a/src/arch/riscv/sbi.c
+++ b/src/arch/riscv/sbi.c
@@ -59,7 +59,7 @@ void handle_sbi(trapframe *tf)
{
uintptr_t ret = 0;
uintptr_t arg0 = tf->gpr[10];
- __unused uintptr_t arg1 = tf->gpr[11];
+ __maybe_unused uintptr_t arg1 = tf->gpr[11];
uintptr_t which = tf->gpr[17];
switch (which) {
diff --git a/src/commonlib/bsd/include/commonlib/bsd/compiler.h b/src/commonlib/bsd/include/commonlib/bsd/compiler.h
index 42f9235e8ea2..aada97374970 100644
--- a/src/commonlib/bsd/include/commonlib/bsd/compiler.h
+++ b/src/commonlib/bsd/include/commonlib/bsd/compiler.h
@@ -15,8 +15,21 @@
#define __aligned(x) __attribute__((__aligned__(x)))
#endif
-#ifndef __unused
-#define __unused __attribute__((__unused__))
+/* Because there may be variables/parameters whose name contains "__unused" in
+ header files of libc, namely musl, these names consistent with ones in the
+ Linux kernel may be a better choice. */
+
+/* This is used to mark identifiers unused in all conditions, e.g. a parameter
+ completely unused in all code branch, only present to fit an API. */
+#ifndef __always_unused
+#define __always_unused __attribute__((__unused__))
+#endif
+
+/* This is used to mark identifiers unused in some conditions, e.g. a parameter
+ only unused in some code branches, a global variable only accessed with code
+ being conditionally preprocessed, etc. */
+#ifndef __maybe_unused
+#define __maybe_unused __attribute__((__unused__))
#endif
#ifndef __must_check
diff --git a/src/commonlib/region.c b/src/commonlib/region.c
index 04c3180754ff..252f6faf12a0 100644
--- a/src/commonlib/region.c
+++ b/src/commonlib/region.c
@@ -222,7 +222,7 @@ void xlate_window_init(struct xlate_window *window, const struct region_device *
}
static void *mdev_mmap(const struct region_device *rd, size_t offset,
- size_t size __unused)
+ size_t size __always_unused)
{
const struct mem_region_device *mdev;
@@ -231,8 +231,8 @@ static void *mdev_mmap(const struct region_device *rd, size_t offset,
return &mdev->base[offset];
}
-static int mdev_munmap(const struct region_device *rd __unused,
- void *mapping __unused)
+static int mdev_munmap(const struct region_device *rd __always_unused,
+ void *mapping __always_unused)
{
return 0;
}
@@ -368,7 +368,8 @@ static void *xlate_mmap(const struct region_device *rd, size_t offset,
return rdev_mmap(xlwindow->access_dev, offset, size);
}
-static int xlate_munmap(const struct region_device *rd __unused, void *mapping __unused)
+static int xlate_munmap(const struct region_device *rd __always_unused,
+ void *mapping __always_unused)
{
/*
* xlate_region_device does not keep track of the access device that was used to service
diff --git a/src/drivers/crb/tis.c b/src/drivers/crb/tis.c
index 95b0656d962e..c3cc3e790d0d 100644
--- a/src/drivers/crb/tis.c
+++ b/src/drivers/crb/tis.c
@@ -127,7 +127,7 @@ static const char *crb_tpm_acpi_name(const struct device *dev)
return "TPM";
}
-static struct device_operations __unused crb_ops = {
+static struct device_operations __maybe_unused crb_ops = {
.read_resources = noop_read_resources,
.set_resources = noop_set_resources,
#if CONFIG(HAVE_ACPI_TABLES)
diff --git a/src/drivers/spi/spi_sdcard.c b/src/drivers/spi/spi_sdcard.c
index 0a18953395ed..e930b50b1349 100644
--- a/src/drivers/spi/spi_sdcard.c
+++ b/src/drivers/spi/spi_sdcard.c
@@ -210,7 +210,7 @@ static int lookup_response_length(int response_type)
static int response_resolve(int response_type, uint8_t *response,
uint32_t *out_register)
{
- __unused static const char * const sd_err[] = {
+ __maybe_unused static const char * const sd_err[] = {
"Card is locked",
"wp erase skip | lock/unlok cmd failed",
"error",
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index b0b4de7d45ae..6604abd49e05 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -219,7 +219,7 @@ static int google_chromeec_clear_mask(uint8_t type, uint64_t mask)
EC_HOST_EVENT_CLEAR, &mask);
}
-static int __unused google_chromeec_set_mask(uint8_t type, uint64_t mask)
+static int google_chromeec_set_mask(uint8_t type, uint64_t mask)
{
if (google_chromeec_is_uhepi_supported())
return google_chromeec_uhepi_cmd(type,
diff --git a/src/soc/amd/common/block/lpc/spi_dma.c b/src/soc/amd/common/block/lpc/spi_dma.c
index 97ba2be24435..8fbd9bd71027 100644
--- a/src/soc/amd/common/block/lpc/spi_dma.c
+++ b/src/soc/amd/common/block/lpc/spi_dma.c
@@ -26,7 +26,8 @@ struct spi_dma_transaction {
size_t remaining;
};
-static void *spi_dma_mmap(const struct region_device *rd, size_t offset, size_t size __unused)
+static void *spi_dma_mmap(const struct region_device *rd, size_t offset,
+ size_t size __always_unused)
{
const struct mem_region_device *mdev;
@@ -35,7 +36,8 @@ static void *spi_dma_mmap(const struct region_device *rd, size_t offset, size_t
return &mdev->base[offset];
}
-static int spi_dma_munmap(const struct region_device *rd __unused, void *mapping __unused)
+static int spi_dma_munmap(const struct region_device *rd __always_unused,
+ void *mapping __always_unused)
{
return 0;
}
diff --git a/src/soc/amd/common/psp_verstage/boot_dev.c b/src/soc/amd/common/psp_verstage/boot_dev.c
index 5b25d5962485..4ee78b834912 100644
--- a/src/soc/amd/common/psp_verstage/boot_dev.c
+++ b/src/soc/amd/common/psp_verstage/boot_dev.c
@@ -11,7 +11,8 @@
#define DEST_BUF_ALIGNMENT 16
-static void *boot_dev_mmap(const struct region_device *rd, size_t offset, size_t size __unused)
+static void *boot_dev_mmap(const struct region_device *rd, size_t offset,
+ size_t size __always_unused)
{
const struct mem_region_device *mdev;
@@ -20,7 +21,8 @@ static void *boot_dev_mmap(const struct region_device *rd, size_t offset, size_t
return &(mdev->base[offset]);
}
-static int boot_dev_munmap(const struct region_device *rd __unused, void *mapping __unused)
+static int boot_dev_munmap(const struct region_device *rd __always_unused,
+ void *mapping __always_unused)
{
return 0;
}
diff --git a/src/southbridge/intel/ibexpeak/me.c b/src/southbridge/intel/ibexpeak/me.c
index 15d8402d8b28..30d73a6f7870 100644
--- a/src/southbridge/intel/ibexpeak/me.c
+++ b/src/southbridge/intel/ibexpeak/me.c
@@ -24,7 +24,7 @@
#include "pch.h"
/* Path that the BIOS should take based on ME state */
-static const char *me_bios_path_values[] __unused = {
+static const char *me_bios_path_values[] = {
[ME_NORMAL_BIOS_PATH] = "Normal",
[ME_S3WAKE_BIOS_PATH] = "S3 Wake",
[ME_ERROR_BIOS_PATH] = "Error",
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index ff10131e4744..87b5d00f19a4 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -1499,7 +1499,7 @@ static int cbfs_layout(void)
return 0;
}
-static enum cb_err verify_walker(__unused cbfs_dev_t dev, size_t offset,
+static enum cb_err verify_walker(__always_unused cbfs_dev_t dev, size_t offset,
const union cbfs_mdata *mdata, size_t already_read, void *arg)
{
uint32_t type = be32toh(mdata->h.type);
diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index 1de98d481ad8..6648254d0aab 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -1970,7 +1970,7 @@ static void generate_outputc(FILE *f, const char *static_header)
fprintf(f, "#include <fw_config.h>\n");
fprintf(f, "#include <%s>\n", static_header);
emit_chip_headers(f, chip_header.next);
- fprintf(f, "\n#define STORAGE static __unused DEVTREE_CONST\n\n");
+ fprintf(f, "\n#define STORAGE static __maybe_unused DEVTREE_CONST\n\n");
walk_device_tree(NULL, NULL, &base_root_dev, inherit_subsystem_ids);
fprintf(f, "\n/* pass 0 */\n");