Skip to content

Commit dc3dcfd

Browse files
committed
Bluetooth: Mesh: Fixed reported coverity issues
Fixed High/Medium/Low covertiy reported issues: - Out-of-bounds access - Unchecked return values - Logically dead code - Defererence null return value - Unnecessary header file - Recursion in included headers - Uninitialized scalar variable Signed-off-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
1 parent 5e55cf8 commit dc3dcfd

35 files changed

+49
-115
lines changed

samples/bluetooth/mesh/dfu/distributor/src/main.c

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <zephyr/storage/flash_map.h>
1212
#include <zephyr/bluetooth/bluetooth.h>
1313
#include <zephyr/bluetooth/mesh.h>
14-
#include <zephyr/bluetooth/mesh/shell.h>
1514
#include <bluetooth/mesh/vnd/le_pair_resp.h>
1615
#include <bluetooth/mesh/dk_prov.h>
1716
#include <dk_buttons_and_leds.h>

samples/bluetooth/mesh/light_ctrl/src/lc_pwm_led.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ void lc_pwm_led_set(uint16_t desired_lvl)
3131
(PWM_PERIOD * desired_lvl) /
3232
BT_MESH_LIGHTNESS_MAX;
3333

34-
pwm_set_dt(&led0, PWM_USEC(PWM_PERIOD), PWM_USEC(scaled_lvl));
34+
(void)pwm_set_dt(&led0, PWM_USEC(PWM_PERIOD), PWM_USEC(scaled_lvl));
3535
}

samples/bluetooth/mesh/light_ctrl/src/model_handler.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ static int energy_use_get(struct bt_mesh_sensor_srv *srv,
200200
struct bt_mesh_sensor_value *rsp)
201201
{
202202
/* Report energy usage as dummy value, and increase it by one every time
203-
* a get callback is triggered. The logic and hardware for mesuring
203+
* a get callback is triggered. The logic and hardware for measuring
204204
* the actual energy usage of the device should be implemented here.
205205
*/
206-
bt_mesh_sensor_value_from_micro(sensor->type->channels[0].format,
207-
dummy_energy_use * 1000000LL, rsp);
206+
(void)bt_mesh_sensor_value_from_micro(sensor->type->channels[0].format,
207+
dummy_energy_use * 1000000LL, rsp);
208208
dummy_energy_use++;
209209

210210
return 0;

samples/bluetooth/mesh/sensor_server/src/model_handler.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,9 @@ const struct bt_mesh_comp *model_handler_init(void)
11031103
dk_button_handler_add(&button_handler);
11041104

11051105
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
1106-
settings_subsys_init();
1106+
if (!settings_subsys_init()) {
1107+
printf("Failed to initialize setting subsystem");
1108+
}
11071109
settings_register(&temp_range_conf);
11081110
settings_register(&presence_motion_threshold_conf);
11091111
settings_register(&amb_light_level_gain_conf);

samples/bluetooth/mesh/silvair_enocean/src/model_handler.c

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
#include <zephyr/bluetooth/bluetooth.h>
1616
#include <bluetooth/mesh/models.h>
17-
#include <bluetooth/enocean.h>
1817
#include <bluetooth/mesh/vnd/silvair_enocean_srv.h>
1918
#include <dk_buttons_and_leds.h>
2019
#include "model_handler.h"

subsys/bluetooth/enocean.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static void adv_recv(const struct bt_le_scan_recv_info *info,
458458

459459
static void store_dirty(struct k_work *work)
460460
{
461-
int err;
461+
int err = 0;
462462

463463
for (int i = 0; i < ARRAY_SIZE(devices); ++i) {
464464
if (!(devices[i].flags & FLAG_DIRTY)) {
@@ -617,12 +617,12 @@ void bt_enocean_decommission(struct bt_enocean_device *dev)
617617

618618
if (IS_ENABLED(CONFIG_BT_ENOCEAN_STORE)) {
619619
encode_tag(name, dev - &devices[0], ENTRY_TAG_DEVICE);
620-
settings_delete(name);
620+
(void)settings_delete(name);
621621
}
622622

623623
if (IS_ENABLED(CONFIG_BT_ENOCEAN_STORE_SEQ)) {
624624
encode_tag(name, dev - &devices[0], ENTRY_TAG_SEQ);
625-
settings_delete(name);
625+
(void)settings_delete(name);
626626
}
627627

628628
dev->flags = 0;

subsys/bluetooth/mesh/gen_prop_srv.c

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "gen_prop_internal.h"
1010
#include "model_utils.h"
1111
#include "mesh/net.h"
12-
#include "mesh/transport.h"
1312

1413
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
1514
#include "zephyr/logging/log.h"

subsys/bluetooth/mesh/model_utils.c

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include <bluetooth/mesh/models.h>
77
#include "model_utils.h"
8-
#include "mesh/mesh.h"
98

109
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
1110
#include "zephyr/logging/log.h"

subsys/bluetooth/mesh/scheduler_srv.c

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <stdio.h>
88
#include <bluetooth/mesh/models.h>
9-
#include <zephyr/sys/byteorder.h>
109
#include <zephyr/sys/util.h>
1110
#include <zephyr/sys/math_extras.h>
1211
#include <zephyr/random/random.h>

subsys/bluetooth/mesh/sensor_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
#include <stdlib.h>
88
#include <bluetooth/mesh/sensor_cli.h>
9-
#include <bluetooth/mesh/properties.h>
109
#include "model_utils.h"
1110
#include "sensor.h"
1211
#include "mesh/net.h"
13-
#include "mesh/transport.h"
1412

1513
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
1614
#include "zephyr/logging/log.h"

subsys/bluetooth/mesh/sensor_srv.c

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <bluetooth/mesh/properties.h>
1111
#include "mesh/net.h"
1212
#include "mesh/access.h"
13-
#include "mesh/transport.h"
1413
#include "model_utils.h"
1514
#include "sensor.h"
1615

subsys/bluetooth/mesh/shell/shell_bat_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_ctl_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_ctrl_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_dm_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <zephyr/shell/shell.h>
1010
#include <bluetooth/mesh/vnd/dm_cli.h>
1111

12-
#include "mesh/net.h"
13-
#include "mesh/access.h"
1412
#include "shell_utils.h"
1513

1614
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_dtt_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_hsl_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_lightness_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_loc_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_lvl_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_onoff_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_plvl_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_ponoff_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_prop_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL

subsys/bluetooth/mesh/shell/shell_scene_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
#define SHELL_SENSOR_CLI_REG_CNT_MAX 32

subsys/bluetooth/mesh/shell/shell_scheduler_cli.c

-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
#include <stdlib.h>
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
10-
#include <zephyr/sys/math_extras.h>
1110

12-
#include "mesh/net.h"
13-
#include "mesh/access.h"
1411
#include "../model_utils.h"
1512

1613
#include "shell_utils.h"

subsys/bluetooth/mesh/shell/shell_sensor_cli.c

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <bluetooth/mesh/models.h>
88
#include <zephyr/shell/shell.h>
9-
#include <ctype.h>
109

1110
#include "shell_utils.h"
1211

subsys/bluetooth/mesh/shell/shell_time_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/shell/shell_utils.c

-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
#include <bluetooth/mesh/models.h>
88
#include <zephyr/shell/shell.h>
9-
#include <ctype.h>
109
#include <string.h>
1110
#include <errno.h>
1211

13-
#include "mesh/net.h"
1412
#include "mesh/access.h"
1513
#include "shell_utils.h"
1614

subsys/bluetooth/mesh/shell/shell_xyl_cli.c

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <bluetooth/mesh/models.h>
99
#include <zephyr/shell/shell.h>
1010

11-
#include "mesh/net.h"
12-
#include "mesh/access.h"
1311
#include "shell_utils.h"
1412

1513
static const struct bt_mesh_model *mod;

subsys/bluetooth/mesh/vnd/le_pair_resp.c

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <bluetooth/mesh/vnd/le_pair_resp.h>
1111
#include "../model_utils.h"
1212
#include "mesh/net.h"
13-
#include "mesh/access.h"
1413

1514
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
1615
#include "zephyr/logging/log.h"

0 commit comments

Comments
 (0)