Skip to content

Commit 5454543

Browse files
dbalutacfriedt
authored andcommitted
drivers: sai: Fix compile time error with clang
After commit 524b72c ("toolchain: llvm: Provide working BUILD_ASSERT macro") when compiling with clang we have actual checks and a real assert check using _Static_assert. Now, when compiling with clang (used by Xtensa internal toolchain) we get the following error. $ zephyr/drivers/dai/nxp/sai/sai.c:968:29: error: static_assert expression is not an integral constant expression We get this in asserts like this: BUILD_ASSERT(SAI_DLINE_COUNT(inst) != -1, "..."). This expands to (reduced the macro to easier understand the context): _Static_assert(((((((I2S_Type *)(uintptr_t)(1493499904U))) == ((I2S_Type *)(0x59040000u))) ... and clang complains that this is not a constant expression. So, in order to fix the compile time error remove the compile time asserts and replace them with runtime checks. Signed-off-by: Daniel Baluta <[email protected]> Fixes: commit 524b72c ("toolchain: llvm: Provide working BUILD_ASSERT macro")
1 parent abd0919 commit 5454543

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

drivers/dai/nxp/sai/sai.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,21 @@ static int sai_init(const struct device *dev)
886886

887887
device_map(&data->regmap, cfg->regmap_phys, cfg->regmap_size, K_MEM_CACHE_NONE);
888888

889+
if (SAI_DLINE_COUNT(cfg->regmap_phys) == -1) {
890+
LOG_ERR("bad or unsupported SAI instance");
891+
return -EINVAL;
892+
}
893+
894+
if (cfg->tx_dline >= SAI_DLINE_COUNT(cfg->regmap_phys)) {
895+
LOG_ERR("invalid TX data line index");
896+
return -EINVAL;
897+
}
898+
899+
if (cfg->rx_dline >= SAI_DLINE_COUNT(cfg->regmap_phys)) {
900+
LOG_ERR("invalid RX data line index");
901+
return -EINVAL;
902+
}
903+
889904
#ifndef CONFIG_PM_DEVICE_RUNTIME
890905
ret = sai_clks_enable_disable(dev, true);
891906
if (ret < 0) {
@@ -935,17 +950,6 @@ BUILD_ASSERT(SAI_TX_SYNC_MODE(inst) != SAI_RX_SYNC_MODE(inst) || \
935950
SAI_TX_SYNC_MODE(inst) != kSAI_ModeSync, \
936951
"transmitter and receiver can't be both SYNC with each other"); \
937952
\
938-
BUILD_ASSERT(SAI_DLINE_COUNT(inst) != -1, \
939-
"bad or unsupported SAI instance. Is the base address correct?"); \
940-
\
941-
BUILD_ASSERT(SAI_TX_DLINE_INDEX(inst) >= 0 && \
942-
(SAI_TX_DLINE_INDEX(inst) < SAI_DLINE_COUNT(inst)), \
943-
"invalid TX data line index"); \
944-
\
945-
BUILD_ASSERT(SAI_RX_DLINE_INDEX(inst) >= 0 && \
946-
(SAI_RX_DLINE_INDEX(inst) < SAI_DLINE_COUNT(inst)), \
947-
"invalid RX data line index"); \
948-
\
949953
static const struct dai_properties sai_tx_props_##inst = { \
950954
.fifo_address = SAI_TX_FIFO_BASE(inst, SAI_TX_DLINE_INDEX(inst)), \
951955
.fifo_depth = SAI_FIFO_DEPTH(inst) * CONFIG_SAI_FIFO_WORD_SIZE, \

drivers/dai/nxp/sai/sai.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ LOG_MODULE_REGISTER(nxp_dai_sai);
148148
((DT_INST_DMAS_CELL_BY_NAME(inst, dir, mux) << 8) & GENMASK(15, 8)))
149149

150150
/* used to retrieve the number of supported transmission/receive lines */
151-
#define SAI_DLINE_COUNT(inst)\
152-
FSL_FEATURE_SAI_CHANNEL_COUNTn(UINT_TO_I2S(DT_INST_REG_ADDR(inst)))
151+
#define SAI_DLINE_COUNT(base)\
152+
FSL_FEATURE_SAI_CHANNEL_COUNTn(UINT_TO_I2S(base))
153153

154154
/* used to retrieve the index of the transmission line */
155155
#define SAI_TX_DLINE_INDEX(inst) DT_INST_PROP_OR(inst, tx_dataline, 0)

0 commit comments

Comments
 (0)