Skip to content

Commit 6a69387

Browse files
committed
drivers: modem: replace K_SPINLOCK macro with explicit locking where needed
This PR is related to the following Zephyr PR: zephyrproject-rtos#81431 Some compilers (e.g. arm-zephyr-eabi-gcc) don't understand the K_SPINLOCK() macro and therefore do warn about uninitialized variables in the modem related modules. Fix: Replaced the K_SPINLOCK macro with explicit k_spin_lock/k_spin_unlock calls only at relevant locations in the modem subsystem. Signed-off-by: Fabian Kainka <[email protected]>
1 parent 042bf2c commit 6a69387

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

subsys/modem/modem_cmux.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,25 +1108,26 @@ static int modem_cmux_dlci_pipe_api_transmit(void *data, const uint8_t *buf, siz
11081108
{
11091109
struct modem_cmux_dlci *dlci = (struct modem_cmux_dlci *)data;
11101110
struct modem_cmux *cmux = dlci->cmux;
1111-
int ret = 0;
1111+
int ret;
11121112

1113-
K_SPINLOCK(&cmux->work_lock) {
1114-
if (!cmux->attached) {
1115-
ret = -EPERM;
1116-
K_SPINLOCK_BREAK;
1117-
}
1113+
k_spinlock_key_t key = k_spin_lock(&cmux->work_lock);
1114+
if (!cmux->attached) {
1115+
ret = -EPERM;
1116+
k_spin_unlock(&cmux->work_lock, key);
1117+
return ret;
1118+
}
11181119

1119-
struct modem_cmux_frame frame = {
1120-
.dlci_address = dlci->dlci_address,
1121-
.cr = true,
1122-
.pf = false,
1123-
.type = MODEM_CMUX_FRAME_TYPE_UIH,
1124-
.data = buf,
1125-
.data_len = size,
1126-
};
1120+
struct modem_cmux_frame frame = {
1121+
.dlci_address = dlci->dlci_address,
1122+
.cr = true,
1123+
.pf = false,
1124+
.type = MODEM_CMUX_FRAME_TYPE_UIH,
1125+
.data = buf,
1126+
.data_len = size,
1127+
};
11271128

1128-
ret = modem_cmux_transmit_data_frame(cmux, &frame);
1129-
}
1129+
ret = modem_cmux_transmit_data_frame(cmux, &frame);
1130+
k_spin_unlock(&cmux->work_lock, key);
11301131

11311132
return ret;
11321133
}

subsys/modem/modem_pipelink.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ bool modem_pipelink_is_connected(struct modem_pipelink *link)
2929
{
3030
bool connected;
3131

32-
K_SPINLOCK(&link->spinlock) {
33-
connected = link->connected;
34-
}
32+
k_spinlock_key_t key = k_spin_lock(&link->spinlock);
33+
connected = link->connected;
34+
k_spin_unlock(&link->spinlock, key);
3535

3636
return connected;
3737
}

subsys/modem/modem_stats.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ static void stats_buffer_list_append(struct modem_stats_buffer *buffer)
3232

3333
static struct modem_stats_buffer *stats_buffer_list_first(void)
3434
{
35-
struct modem_stats_buffer *first = NULL;
35+
struct modem_stats_buffer *first;
3636

37-
K_SPINLOCK(&stats_buffer_lock) {
38-
first = stats_buffer_from_node(sys_slist_peek_head(&stats_buffer_list));
39-
}
37+
k_spinlock_key_t key = k_spin_lock(&stats_buffer_lock);
38+
first = stats_buffer_from_node(sys_slist_peek_head(&stats_buffer_list));
39+
k_spin_unlock(&stats_buffer_lock, key);
4040

4141
return first;
4242
}
4343

4444
static struct modem_stats_buffer *stats_buffer_list_next(struct modem_stats_buffer *buffer)
4545
{
46-
struct modem_stats_buffer *next = NULL;
46+
struct modem_stats_buffer *next;
4747

48-
K_SPINLOCK(&stats_buffer_lock) {
49-
next = stats_buffer_from_node(sys_slist_peek_next(&buffer->node));
50-
}
48+
k_spinlock_key_t key = k_spin_lock(&stats_buffer_lock);
49+
next = stats_buffer_from_node(sys_slist_peek_next(&buffer->node));
50+
k_spin_unlock(&stats_buffer_lock, key);
5151

5252
return next;
5353
}

0 commit comments

Comments
 (0)