Skip to content

Commit d8837c6

Browse files
Flavio Ceolinnashif
authored andcommitted
kernel: Using boolean expression on ASSERT macros
ASSERT macro expects a boolean expression, making it explicit. MISRA-C rule 14.4 Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 6fdc56d commit d8837c6

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

include/clock_control.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static inline int clock_control_get_rate(struct device *dev,
8383
{
8484
const struct clock_control_driver_api *api = dev->driver_api;
8585

86-
__ASSERT(api->get_rate, "%s not implemented for device %s",
86+
__ASSERT(api->get_rate != NULL, "%s not implemented for device %s",
8787
__func__, dev->config->name);
8888

8989
return api->get_rate(dev, sys, rate);

include/entropy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static inline int _impl_entropy_get_entropy(struct device *dev,
7171
{
7272
const struct entropy_driver_api *api = dev->driver_api;
7373

74-
__ASSERT(api->get_entropy, "Callback pointer should not be NULL");
74+
__ASSERT(api->get_entropy != NULL,
75+
"Callback pointer should not be NULL");
7576
return api->get_entropy(dev, buffer, length);
7677
}
7778

include/misc/sflist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static inline u8_t sys_sfnode_flags_get(sys_sfnode_t *node)
281281
*/
282282
static inline void sys_sfnode_init(sys_sfnode_t *node, u8_t flags)
283283
{
284-
__ASSERT(!(flags & ~SYS_SFLIST_FLAGS_MASK), "flags too large");
284+
__ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0, "flags too large");
285285
node->next_and_flags = flags;
286286
}
287287

@@ -297,7 +297,7 @@ static inline void sys_sfnode_init(sys_sfnode_t *node, u8_t flags)
297297
*/
298298
static inline void sys_sfnode_flags_set(sys_sfnode_t *node, u8_t flags)
299299
{
300-
__ASSERT(!(flags & ~SYS_SFLIST_FLAGS_MASK), "flags too large");
300+
__ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0, "flags too large");
301301
node->next_and_flags = (unative_t)(z_sfnode_next_peek(node)) | flags;
302302
}
303303

kernel/mem_domain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts,
8888
u32_t i;
8989

9090
for (i = 0; i < num_parts; i++) {
91-
__ASSERT(parts[i], "");
91+
__ASSERT(parts[i] != NULL, "");
9292
__ASSERT((parts[i]->start + parts[i]->size) >
9393
parts[i]->start, "");
9494

kernel/poll.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void k_poll_event_init(struct k_poll_event *event, u32_t type,
3131
__ASSERT(mode == K_POLL_MODE_NOTIFY_ONLY,
3232
"only NOTIFY_ONLY mode is supported\n");
3333
__ASSERT(type < (BIT(_POLL_NUM_TYPES)), "invalid type\n");
34-
__ASSERT(obj, "must provide an object\n");
34+
__ASSERT(obj != NULL, "must provide an object\n");
3535

3636
event->poller = NULL;
3737
/* event->tag is left uninitialized: the user will set it if needed */
@@ -105,15 +105,15 @@ static inline int register_event(struct k_poll_event *event,
105105
{
106106
switch (event->type) {
107107
case K_POLL_TYPE_SEM_AVAILABLE:
108-
__ASSERT(event->sem, "invalid semaphore\n");
108+
__ASSERT(event->sem != NULL, "invalid semaphore\n");
109109
add_event(&event->sem->poll_events, event, poller);
110110
break;
111111
case K_POLL_TYPE_DATA_AVAILABLE:
112-
__ASSERT(event->queue, "invalid queue\n");
112+
__ASSERT(event->queue != NULL, "invalid queue\n");
113113
add_event(&event->queue->poll_events, event, poller);
114114
break;
115115
case K_POLL_TYPE_SIGNAL:
116-
__ASSERT(event->signal, "invalid poll signal\n");
116+
__ASSERT(event->signal != NULL, "invalid poll signal\n");
117117
add_event(&event->signal->poll_events, event, poller);
118118
break;
119119
case K_POLL_TYPE_IGNORE:
@@ -136,15 +136,15 @@ static inline void clear_event_registration(struct k_poll_event *event)
136136

137137
switch (event->type) {
138138
case K_POLL_TYPE_SEM_AVAILABLE:
139-
__ASSERT(event->sem, "invalid semaphore\n");
139+
__ASSERT(event->sem != NULL, "invalid semaphore\n");
140140
sys_dlist_remove(&event->_node);
141141
break;
142142
case K_POLL_TYPE_DATA_AVAILABLE:
143-
__ASSERT(event->queue, "invalid queue\n");
143+
__ASSERT(event->queue != NULL, "invalid queue\n");
144144
sys_dlist_remove(&event->_node);
145145
break;
146146
case K_POLL_TYPE_SIGNAL:
147-
__ASSERT(event->signal, "invalid poll signal\n");
147+
__ASSERT(event->signal != NULL, "invalid poll signal\n");
148148
sys_dlist_remove(&event->_node);
149149
break;
150150
case K_POLL_TYPE_IGNORE:
@@ -177,7 +177,7 @@ static inline void set_event_ready(struct k_poll_event *event, u32_t state)
177177
int _impl_k_poll(struct k_poll_event *events, int num_events, s32_t timeout)
178178
{
179179
__ASSERT(!_is_in_isr(), "");
180-
__ASSERT(events, "NULL events\n");
180+
__ASSERT(events != NULL, "NULL events\n");
181181
__ASSERT(num_events > 0, "zero events\n");
182182

183183
int last_registered = -1, rc;
@@ -327,7 +327,8 @@ static int signal_poll_event(struct k_poll_event *event, u32_t state)
327327

328328
struct k_thread *thread = event->poller->thread;
329329

330-
__ASSERT(event->poller->thread, "poller should have a thread\n");
330+
__ASSERT(event->poller->thread != NULL,
331+
"poller should have a thread\n");
331332

332333
event->poller->is_polling = 0;
333334

kernel/thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data)
4444
struct k_thread *thread;
4545
unsigned int key;
4646

47-
__ASSERT(user_cb, "user_cb can not be NULL");
47+
__ASSERT(user_cb != NULL, "user_cb can not be NULL");
4848

4949
/*
5050
* Lock is needed to make sure that the _kernel.threads is not being

kernel/thread_abort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void _impl_k_thread_abort(k_tid_t thread)
3131

3232
key = irq_lock();
3333

34-
__ASSERT(!(thread->base.user_options & K_ESSENTIAL),
34+
__ASSERT((thread->base.user_options & K_ESSENTIAL) == 0,
3535
"essential thread aborted");
3636

3737
_k_thread_single_abort(thread);

0 commit comments

Comments
 (0)