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>
This commit is contained in:
parent
2ecc7cfa55
commit
063a9ce8c3
11 changed files with 24 additions and 22 deletions
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
static ALWAYS_INLINE unsigned int find_msb_set(u32_t op)
|
static ALWAYS_INLINE unsigned int find_msb_set(u32_t op)
|
||||||
{
|
{
|
||||||
if (!op) {
|
if (op == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
static ALWAYS_INLINE void z_arch_irq_unlock(unsigned int key)
|
||||||
{
|
{
|
||||||
if (!(key & 0x200)) {
|
if ((key & 0x200) == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <toolchain.h>
|
#include <toolchain.h>
|
||||||
|
|
||||||
|
#include <zephyr/types.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -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_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))
|
#define ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / ATOMIC_BITS))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 *api =
|
||||||
(const struct gpio_driver_api *)port->driver_api;
|
(const struct gpio_driver_api *)port->driver_api;
|
||||||
|
|
||||||
if (!api->enable_callback) {
|
if (api->enable_callback == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 *api =
|
||||||
(const struct gpio_driver_api *)port->driver_api;
|
(const struct gpio_driver_api *)port->driver_api;
|
||||||
|
|
||||||
if (!api->disable_callback) {
|
if (api->disable_callback == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ static inline int gpio_add_callback(struct device *port,
|
||||||
const struct gpio_driver_api *api =
|
const struct gpio_driver_api *api =
|
||||||
(const struct gpio_driver_api *)port->driver_api;
|
(const struct gpio_driver_api *)port->driver_api;
|
||||||
|
|
||||||
if (!api->manage_callback) {
|
if (api->manage_callback == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ static inline int gpio_remove_callback(struct device *port,
|
||||||
const struct gpio_driver_api *api =
|
const struct gpio_driver_api *api =
|
||||||
(const struct gpio_driver_api *)port->driver_api;
|
(const struct gpio_driver_api *)port->driver_api;
|
||||||
|
|
||||||
if (!api->manage_callback) {
|
if (api->manage_callback == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 *api =
|
||||||
(const struct gpio_driver_api *)dev->driver_api;
|
(const struct gpio_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
if (!api->get_pending_int) {
|
if (api->get_pending_int == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 *api =
|
||||||
(const struct i2c_driver_api *)dev->driver_api;
|
(const struct i2c_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
if (!api->slave_register) {
|
if (api->slave_register == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 *api =
|
||||||
(const struct i2c_driver_api *)dev->driver_api;
|
(const struct i2c_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
if (!api->slave_unregister) {
|
if (api->slave_unregister == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,13 +219,13 @@ extern "C" {
|
||||||
.source_id = _id \
|
.source_id = _id \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
if (BIT(_level) & LOG_FUNCTION_PREFIX_MASK) { \
|
if ((BIT(_level) & LOG_FUNCTION_PREFIX_MASK) != 0) {\
|
||||||
__LOG_INTERNAL(src_level, \
|
__LOG_INTERNAL(src_level, \
|
||||||
Z_LOG_STR(__VA_ARGS__)); \
|
Z_LOG_STR(__VA_ARGS__)); \
|
||||||
} else { \
|
} else { \
|
||||||
__LOG_INTERNAL(src_level, __VA_ARGS__); \
|
__LOG_INTERNAL(src_level, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} else if (0) { \
|
} else if (false) { \
|
||||||
/* Arguments checker present but never evaluated.*/ \
|
/* Arguments checker present but never evaluated.*/ \
|
||||||
/* Placed here to ensure that __VA_ARGS__ are*/ \
|
/* Placed here to ensure that __VA_ARGS__ are*/ \
|
||||||
/* evaluated once when log is enabled.*/ \
|
/* evaluated once when log is enabled.*/ \
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
static inline bool \
|
static inline bool \
|
||||||
sys_ ## __lname ## _is_empty(sys_ ## __lname ## _t *list) \
|
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) \
|
#define Z_GENLIST_PEEK_NEXT_NO_CHECK(__lname, __nname) \
|
||||||
|
@ -145,7 +145,7 @@
|
||||||
sys_ ## __nname ## _t *prev, \
|
sys_ ## __nname ## _t *prev, \
|
||||||
sys_ ## __nname ## _t *node) \
|
sys_ ## __nname ## _t *node) \
|
||||||
{ \
|
{ \
|
||||||
if (!prev) { \
|
if (prev == NULL) { \
|
||||||
sys_ ## __lname ## _prepend(list, node); \
|
sys_ ## __lname ## _prepend(list, node); \
|
||||||
} else if (!z_ ## __nname ## _next_peek(prev)) { \
|
} else if (!z_ ## __nname ## _next_peek(prev)) { \
|
||||||
sys_ ## __lname ## _append(list, node); \
|
sys_ ## __lname ## _append(list, node); \
|
||||||
|
@ -187,7 +187,7 @@
|
||||||
sys_ ## __nname ## _t *prev_node, \
|
sys_ ## __nname ## _t *prev_node, \
|
||||||
sys_ ## __nname ## _t *node) \
|
sys_ ## __nname ## _t *node) \
|
||||||
{ \
|
{ \
|
||||||
if (!prev_node) { \
|
if (prev_node == NULL) { \
|
||||||
z_ ## __lname ## _head_set(list, \
|
z_ ## __lname ## _head_set(list, \
|
||||||
z_ ## __nname ## _next_peek(node)); \
|
z_ ## __nname ## _next_peek(node)); \
|
||||||
\
|
\
|
||||||
|
|
|
@ -94,7 +94,7 @@ constexpr size_t ARRAY_SIZE(T(&)[N]) { return N; }
|
||||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
#endif
|
#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));
|
return (x != 0) && !(x & (x - 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ __deprecated static inline int rtc_set_config(struct device *dev,
|
||||||
err = counter_set_top_value(dev, cfg->alarm_val,
|
err = counter_set_top_value(dev, cfg->alarm_val,
|
||||||
rtc_counter_top_callback, cfg->cb_fn);
|
rtc_counter_top_callback, cfg->cb_fn);
|
||||||
|
|
||||||
if (!err && cfg->alarm_enable) {
|
if (err == 0 && cfg->alarm_enable != 0) {
|
||||||
err = counter_start(dev);
|
err = counter_start(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;
|
const struct sensor_driver_api *api = dev->driver_api;
|
||||||
|
|
||||||
if (!api->attr_set) {
|
if (api->attr_set == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +318,7 @@ static inline int sensor_trigger_set(struct device *dev,
|
||||||
{
|
{
|
||||||
const struct sensor_driver_api *api = dev->driver_api;
|
const struct sensor_driver_api *api = dev->driver_api;
|
||||||
|
|
||||||
if (!api->trigger_set) {
|
if (api->trigger_set == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 *api =
|
||||||
(const struct uart_driver_api *)dev->driver_api;
|
(const struct uart_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
if (api->err_check) {
|
if (api->err_check != NULL) {
|
||||||
return api->err_check(dev);
|
return api->err_check(dev);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -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 *api =
|
||||||
(const struct uart_driver_api *)dev->driver_api;
|
(const struct uart_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
if (api->configure) {
|
if (api->configure != NULL) {
|
||||||
return api->configure(dev, cfg);
|
return api->configure(dev, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 *api =
|
||||||
(const struct uart_driver_api *)dev->driver_api;
|
(const struct uart_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
if (api->config_get) {
|
if (api->config_get != NULL) {
|
||||||
return api->config_get(dev, cfg);
|
return api->config_get(dev, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue