Skip to content

Commit 7aaba4e

Browse files
doki-nordiclstnl
authored andcommitted
Asserts and removed unused code
1 parent 2d58de1 commit 7aaba4e

File tree

3 files changed

+54
-44
lines changed

3 files changed

+54
-44
lines changed

subsys/ipc/ipc_service/backends/ipc_icmsg.c

+44-32
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,50 @@ static int backend_init(const struct device *instance)
5656

5757
#define UNBOUND_MODE(i) CONCAT(ICMSG_UNBOUND_MODE_, DT_INST_STRING_UPPER_TOKEN(i, unbound))
5858

59-
#define DEFINE_BACKEND_DEVICE(i) \
60-
static const struct icmsg_config_t backend_config_##i = { \
61-
.mbox_tx = MBOX_DT_SPEC_INST_GET(i, tx), \
62-
.mbox_rx = MBOX_DT_SPEC_INST_GET(i, rx), \
63-
.unbound_mode = UNBOUND_MODE(i), \
64-
}; \
65-
\
66-
PBUF_DEFINE(tx_pb_##i, \
67-
DT_REG_ADDR(DT_INST_PHANDLE(i, tx_region)), \
68-
DT_REG_SIZE(DT_INST_PHANDLE(i, tx_region)), \
69-
DT_INST_PROP_OR(i, dcache_alignment, 0), \
70-
UNBOUND_MODE(i) != ICMSG_UNBOUND_MODE_DISABLE, \
71-
UNBOUND_MODE(i) == ICMSG_UNBOUND_MODE_DETECT); \
72-
PBUF_DEFINE(rx_pb_##i, \
73-
DT_REG_ADDR(DT_INST_PHANDLE(i, rx_region)), \
74-
DT_REG_SIZE(DT_INST_PHANDLE(i, rx_region)), \
75-
DT_INST_PROP_OR(i, dcache_alignment, 0), \
76-
UNBOUND_MODE(i) != ICMSG_UNBOUND_MODE_DISABLE, \
77-
UNBOUND_MODE(i) == ICMSG_UNBOUND_MODE_DETECT); \
78-
\
79-
static struct icmsg_data_t backend_data_##i = { \
80-
.tx_pb = &tx_pb_##i, \
81-
.rx_pb = &rx_pb_##i, \
82-
}; \
83-
\
84-
DEVICE_DT_INST_DEFINE(i, \
85-
&backend_init, \
86-
NULL, \
87-
&backend_data_##i, \
88-
&backend_config_##i, \
89-
POST_KERNEL, \
90-
CONFIG_IPC_SERVICE_REG_BACKEND_PRIORITY, \
59+
#define DEFINE_BACKEND_DEVICE(i) \
60+
static const struct icmsg_config_t backend_config_##i = { \
61+
.mbox_tx = MBOX_DT_SPEC_INST_GET(i, tx), \
62+
.mbox_rx = MBOX_DT_SPEC_INST_GET(i, rx), \
63+
.unbound_mode = UNBOUND_MODE(i), \
64+
}; \
65+
\
66+
PBUF_DEFINE(tx_pb_##i, \
67+
DT_REG_ADDR(DT_INST_PHANDLE(i, tx_region)), \
68+
DT_REG_SIZE(DT_INST_PHANDLE(i, tx_region)), \
69+
DT_INST_PROP_OR(i, dcache_alignment, 0), \
70+
UNBOUND_MODE(i) != ICMSG_UNBOUND_MODE_DISABLE, \
71+
UNBOUND_MODE(i) == ICMSG_UNBOUND_MODE_DETECT); \
72+
PBUF_DEFINE(rx_pb_##i, \
73+
DT_REG_ADDR(DT_INST_PHANDLE(i, rx_region)), \
74+
DT_REG_SIZE(DT_INST_PHANDLE(i, rx_region)), \
75+
DT_INST_PROP_OR(i, dcache_alignment, 0), \
76+
UNBOUND_MODE(i) != ICMSG_UNBOUND_MODE_DISABLE, \
77+
UNBOUND_MODE(i) == ICMSG_UNBOUND_MODE_DETECT); \
78+
\
79+
BUILD_ASSERT(UNBOUND_MODE(i) != ICMSG_UNBOUND_MODE_DISABLE || \
80+
IS_ENABLED(CONFIG_IPC_SERVICE_ICMSG_UNBOUND_DISABLED_ALLOWED), \
81+
"Unbound mode \"disabled\" is was forbidden in Kconfig."); \
82+
\
83+
BUILD_ASSERT(UNBOUND_MODE(i) != ICMSG_UNBOUND_MODE_ENABLE || \
84+
IS_ENABLED(CONFIG_IPC_SERVICE_ICMSG_UNBOUND_ENABLED_ALLOWED), \
85+
"Unbound mode \"enabled\" is was forbidden in Kconfig."); \
86+
\
87+
BUILD_ASSERT(UNBOUND_MODE(i) != ICMSG_UNBOUND_MODE_DETECT || \
88+
IS_ENABLED(CONFIG_IPC_SERVICE_ICMSG_UNBOUND_DETECT_ALLOWED), \
89+
"Unbound mode \"detect\" is was forbidden in Kconfig."); \
90+
\
91+
static struct icmsg_data_t backend_data_##i = { \
92+
.tx_pb = &tx_pb_##i, \
93+
.rx_pb = &rx_pb_##i, \
94+
}; \
95+
\
96+
DEVICE_DT_INST_DEFINE(i, \
97+
&backend_init, \
98+
NULL, \
99+
&backend_data_##i, \
100+
&backend_config_##i, \
101+
POST_KERNEL, \
102+
CONFIG_IPC_SERVICE_REG_BACKEND_PRIORITY, \
91103
&backend_ops);
92104

93105
DT_INST_FOREACH_STATUS_OKAY(DEFINE_BACKEND_DEVICE)

subsys/ipc/ipc_service/lib/icmsg.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <zephyr/init.h>
1414

1515

16-
#define UNBOUND_ENABLED IS_ENABLED(CONFIG_IPC_SERVICE_ICMSG_UNBOUND_ENABLED_ALLOWED)
1716
#define UNBOUND_DISABLED IS_ENABLED(CONFIG_IPC_SERVICE_ICMSG_UNBOUND_DISABLED_ALLOWED)
17+
#define UNBOUND_ENABLED IS_ENABLED(CONFIG_IPC_SERVICE_ICMSG_UNBOUND_ENABLED_ALLOWED)
1818
#define UNBOUND_DETECT IS_ENABLED(CONFIG_IPC_SERVICE_ICMSG_UNBOUND_DETECT_ALLOWED)
1919

2020
/** Get local session id request from RX handshake word.
@@ -384,6 +384,13 @@ int icmsg_open(const struct icmsg_config_t *conf,
384384
int ret;
385385
enum icmsg_state old_state;
386386

387+
__ASSERT(conf->unbound_mode != ICMSG_UNBOUND_MODE_DISABLE || UNBOUND_DISABLED,
388+
"Unbound mode \"disabled\" is was forbidden in Kconfig.");
389+
__ASSERT(conf->unbound_mode != ICMSG_UNBOUND_MODE_ENABLE || UNBOUND_ENABLED,
390+
"Unbound mode \"enabled\" is was forbidden in Kconfig.");
391+
__ASSERT(conf->unbound_mode != ICMSG_UNBOUND_MODE_DETECT || UNBOUND_DETECT,
392+
"Unbound mode \"detect\" is was forbidden in Kconfig.");
393+
387394
if (conf->unbound_mode == ICMSG_UNBOUND_MODE_DISABLE ||
388395
!(UNBOUND_ENABLED || UNBOUND_DETECT)) {
389396
if (!atomic_cas(&dev_data->state, ICMSG_STATE_OFF,

subsys/ipc/ipc_service/lib/pbuf.c

+2-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ static int validate_cfg(const struct pbuf_cfg *cfg)
3232
{
3333
/* Validate pointers. */
3434
if (!cfg || !cfg->rd_idx_loc || !cfg->wr_idx_loc || !cfg->data_loc) {
35-
printk("Invalid pointers\n");
3635
return -EINVAL;
3736
}
3837

@@ -41,13 +40,11 @@ static int validate_cfg(const struct pbuf_cfg *cfg)
4140
!IS_PTR_ALIGNED_BYTES(cfg->wr_idx_loc, MAX(cfg->dcache_alignment, _PBUF_IDX_SIZE)) ||
4241
!IS_PTR_ALIGNED_BYTES(cfg->handshake_loc, _PBUF_IDX_SIZE) ||
4342
!IS_PTR_ALIGNED_BYTES(cfg->data_loc, _PBUF_IDX_SIZE)) {
44-
printk("Invalid alignment\n");
4543
return -EINVAL;
4644
}
4745

4846
/* Validate len. */
4947
if (cfg->len < _PBUF_MIN_DATA_LEN || !IS_PTR_ALIGNED_BYTES(cfg->len, _PBUF_IDX_SIZE)) {
50-
printk("Invalid length\n");
5148
return -EINVAL;
5249
}
5350

@@ -58,12 +55,6 @@ static int validate_cfg(const struct pbuf_cfg *cfg)
5855
!((uint8_t *)cfg->wr_idx_loc < cfg->data_loc) ||
5956
!(((uint8_t *)cfg->rd_idx_loc + MAX(_PBUF_IDX_SIZE, cfg->dcache_alignment)) ==
6057
(uint8_t *)cfg->wr_idx_loc)) {
61-
printk("Invalid pointer values\n");
62-
printk("rd_idx_loc: 0x%08X\n", (uintptr_t)cfg->rd_idx_loc);
63-
printk("wr_idx_loc: 0x%08X\n", (uintptr_t)cfg->wr_idx_loc);
64-
printk("handshake_loc: 0x%08X\n", (uintptr_t)cfg->handshake_loc);
65-
printk("data_loc: 0x%08X\n", (uintptr_t)cfg->data_loc);
66-
printk("dcache_alignment: 0x%08X\n", (uintptr_t)cfg->dcache_alignment);
6758
return -EINVAL;
6859
}
6960

@@ -203,7 +194,7 @@ int pbuf_get_initial_buf(struct pbuf *pb, volatile char **buf, uint16_t *len)
203194

204195
wr_idx = *(pb->cfg->wr_idx_loc);
205196
if (wr_idx >= pb->cfg->len || wr_idx > 0xFFFF || wr_idx == 0) {
206-
/* Incorrect index - probably pbuf was not initialized or message was not send yet. */
197+
/* Wrong index - probably pbuf was not initialized or message was not send yet. */
207198
return -EINVAL;
208199
}
209200

@@ -213,7 +204,7 @@ int pbuf_get_initial_buf(struct pbuf *pb, volatile char **buf, uint16_t *len)
213204
plen = sys_get_be16(&pb->cfg->data_loc[0]);
214205

215206
if (plen + 4 > wr_idx) {
216-
/* Incorrect length - probably pbuf was not initialized or message was not send yet. */
207+
/* Wrong length - probably pbuf was not initialized or message was not send yet. */
217208
return -EINVAL;
218209
}
219210

0 commit comments

Comments
 (0)