Browse Source

include: Make statements evaluate boolean expressions

MISRA-C requires that the if statement has essentially Boolean type.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
pull/14549/head
Flavio Ceolin 6 years ago committed by Anas Nashif
parent
commit
063a9ce8c3
  1. 2
      include/arch/bits_portable.h
  2. 2
      include/arch/x86/arch.h
  3. 4
      include/atomic.h
  4. 10
      include/gpio.h
  5. 4
      include/i2c.h
  6. 4
      include/logging/log_core.h
  7. 6
      include/misc/list_gen.h
  8. 2
      include/misc/util.h
  9. 2
      include/rtc.h
  10. 4
      include/sensor.h
  11. 6
      include/uart.h

2
include/arch/bits_portable.h

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
static ALWAYS_INLINE unsigned int find_msb_set(u32_t op)
{
if (!op) {
if (op == 0) {
return 0;
}

2
include/arch/x86/arch.h

@ -444,7 +444,7 @@ static ALWAYS_INLINE unsigned int z_arch_irq_lock(void) @@ -444,7 +444,7 @@ static ALWAYS_INLINE unsigned int z_arch_irq_lock(void)
static ALWAYS_INLINE void z_arch_irq_unlock(unsigned int key)
{
if (!(key & 0x200)) {
if ((key & 0x200) == 0) {
return;
}

4
include/atomic.h

@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
#include <stdbool.h>
#include <toolchain.h>
#include <zephyr/types.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -312,7 +314,7 @@ extern atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value); @@ -312,7 +314,7 @@ extern atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value);
*/
#define ATOMIC_BITS (sizeof(atomic_val_t) * 8)
#define ATOMIC_MASK(bit) (1 << ((bit) & (ATOMIC_BITS - 1)))
#define ATOMIC_MASK(bit) (1 << ((u32_t)(bit) & (ATOMIC_BITS - 1)))
#define ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / ATOMIC_BITS))
/**

10
include/gpio.h

@ -165,7 +165,7 @@ static inline int z_impl_gpio_enable_callback(struct device *port, @@ -165,7 +165,7 @@ static inline int z_impl_gpio_enable_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
if (!api->enable_callback) {
if (api->enable_callback == NULL) {
return -ENOTSUP;
}
@ -181,7 +181,7 @@ static inline int z_impl_gpio_disable_callback(struct device *port, @@ -181,7 +181,7 @@ static inline int z_impl_gpio_disable_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
if (!api->disable_callback) {
if (api->disable_callback == NULL) {
return -ENOTSUP;
}
@ -268,7 +268,7 @@ static inline int gpio_add_callback(struct device *port, @@ -268,7 +268,7 @@ static inline int gpio_add_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
if (!api->manage_callback) {
if (api->manage_callback == NULL) {
return -ENOTSUP;
}
@ -297,7 +297,7 @@ static inline int gpio_remove_callback(struct device *port, @@ -297,7 +297,7 @@ static inline int gpio_remove_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
if (!api->manage_callback) {
if (api->manage_callback == NULL) {
return -ENOTSUP;
}
@ -428,7 +428,7 @@ static inline int z_impl_gpio_get_pending_int(struct device *dev) @@ -428,7 +428,7 @@ static inline int z_impl_gpio_get_pending_int(struct device *dev)
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)dev->driver_api;
if (!api->get_pending_int) {
if (api->get_pending_int == NULL) {
return -ENOTSUP;
}

4
include/i2c.h

@ -284,7 +284,7 @@ static inline int z_impl_i2c_slave_register(struct device *dev, @@ -284,7 +284,7 @@ static inline int z_impl_i2c_slave_register(struct device *dev,
const struct i2c_driver_api *api =
(const struct i2c_driver_api *)dev->driver_api;
if (!api->slave_register) {
if (api->slave_register == NULL) {
return -ENOTSUP;
}
@ -315,7 +315,7 @@ static inline int z_impl_i2c_slave_unregister(struct device *dev, @@ -315,7 +315,7 @@ static inline int z_impl_i2c_slave_unregister(struct device *dev,
const struct i2c_driver_api *api =
(const struct i2c_driver_api *)dev->driver_api;
if (!api->slave_unregister) {
if (api->slave_unregister == NULL) {
return -ENOTSUP;
}

4
include/logging/log_core.h

@ -219,13 +219,13 @@ extern "C" { @@ -219,13 +219,13 @@ extern "C" {
.source_id = _id \
}; \
\
if (BIT(_level) & LOG_FUNCTION_PREFIX_MASK) { \
if ((BIT(_level) & LOG_FUNCTION_PREFIX_MASK) != 0) {\
__LOG_INTERNAL(src_level, \
Z_LOG_STR(__VA_ARGS__)); \
} else { \
__LOG_INTERNAL(src_level, __VA_ARGS__); \
} \
} else if (0) { \
} else if (false) { \
/* Arguments checker present but never evaluated.*/ \
/* Placed here to ensure that __VA_ARGS__ are*/ \
/* evaluated once when log is enabled.*/ \

6
include/misc/list_gen.h

@ -58,7 +58,7 @@ @@ -58,7 +58,7 @@
static inline bool \
sys_ ## __lname ## _is_empty(sys_ ## __lname ## _t *list) \
{ \
return (!sys_ ## __lname ## _peek_head(list)); \
return (sys_ ## __lname ## _peek_head(list) == NULL); \
}
#define Z_GENLIST_PEEK_NEXT_NO_CHECK(__lname, __nname) \
@ -145,7 +145,7 @@ @@ -145,7 +145,7 @@
sys_ ## __nname ## _t *prev, \
sys_ ## __nname ## _t *node) \
{ \
if (!prev) { \
if (prev == NULL) { \
sys_ ## __lname ## _prepend(list, node); \
} else if (!z_ ## __nname ## _next_peek(prev)) { \
sys_ ## __lname ## _append(list, node); \
@ -187,7 +187,7 @@ @@ -187,7 +187,7 @@
sys_ ## __nname ## _t *prev_node, \
sys_ ## __nname ## _t *node) \
{ \
if (!prev_node) { \
if (prev_node == NULL) { \
z_ ## __lname ## _head_set(list, \
z_ ## __nname ## _next_peek(node)); \
\

2
include/misc/util.h

@ -94,7 +94,7 @@ constexpr size_t ARRAY_SIZE(T(&)[N]) { return N; } @@ -94,7 +94,7 @@ constexpr size_t ARRAY_SIZE(T(&)[N]) { return N; }
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
static inline int is_power_of_two(unsigned int x)
static inline bool is_power_of_two(unsigned int x)
{
return (x != 0) && !(x & (x - 1));
}

2
include/rtc.h

@ -101,7 +101,7 @@ __deprecated static inline int rtc_set_config(struct device *dev, @@ -101,7 +101,7 @@ __deprecated static inline int rtc_set_config(struct device *dev,
err = counter_set_top_value(dev, cfg->alarm_val,
rtc_counter_top_callback, cfg->cb_fn);
if (!err && cfg->alarm_enable) {
if (err == 0 && cfg->alarm_enable != 0) {
err = counter_start(dev);
}

4
include/sensor.h

@ -288,7 +288,7 @@ static inline int z_impl_sensor_attr_set(struct device *dev, @@ -288,7 +288,7 @@ static inline int z_impl_sensor_attr_set(struct device *dev,
{
const struct sensor_driver_api *api = dev->driver_api;
if (!api->attr_set) {
if (api->attr_set == NULL) {
return -ENOTSUP;
}
@ -318,7 +318,7 @@ static inline int sensor_trigger_set(struct device *dev, @@ -318,7 +318,7 @@ static inline int sensor_trigger_set(struct device *dev,
{
const struct sensor_driver_api *api = dev->driver_api;
if (!api->trigger_set) {
if (api->trigger_set == NULL) {
return -ENOTSUP;
}

6
include/uart.h

@ -582,7 +582,7 @@ static inline int z_impl_uart_err_check(struct device *dev) @@ -582,7 +582,7 @@ static inline int z_impl_uart_err_check(struct device *dev)
const struct uart_driver_api *api =
(const struct uart_driver_api *)dev->driver_api;
if (api->err_check) {
if (api->err_check != NULL) {
return api->err_check(dev);
}
return 0;
@ -657,7 +657,7 @@ static inline int z_impl_uart_configure(struct device *dev, @@ -657,7 +657,7 @@ static inline int z_impl_uart_configure(struct device *dev,
const struct uart_driver_api *api =
(const struct uart_driver_api *)dev->driver_api;
if (api->configure) {
if (api->configure != NULL) {
return api->configure(dev, cfg);
}
@ -684,7 +684,7 @@ static inline int z_impl_uart_config_get(struct device *dev, @@ -684,7 +684,7 @@ static inline int z_impl_uart_config_get(struct device *dev,
const struct uart_driver_api *api =
(const struct uart_driver_api *)dev->driver_api;
if (api->config_get) {
if (api->config_get != NULL) {
return api->config_get(dev, cfg);
}

Loading…
Cancel
Save