Skip to content

Commit a5cfef0

Browse files
committed
[nrf fromlist] modem: pipe: Don't return EPERM on closed pipe
When working on CMUX power saving, it is typical that we end up closing the pipe before the last RX_READY event is handled from workqueue, so we end up receiving -EPERM which is not really a fatal error. Pipes recover when they are re-opened. So drop this error and return zero instead, like modem_pipe_open() and close() does. Upstream PR #: 97362 Signed-off-by: Seppo Takalo <[email protected]>
1 parent 877a754 commit a5cfef0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

subsys/modem/modem_pipe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void modem_pipe_attach(struct modem_pipe *pipe, modem_pipe_api_callback callback
136136
int modem_pipe_transmit(struct modem_pipe *pipe, const uint8_t *buf, size_t size)
137137
{
138138
if (!pipe_test_events(pipe, PIPE_EVENT_OPENED_BIT)) {
139-
return -EPERM;
139+
return 0;
140140
}
141141

142142
pipe_clear_events(pipe, PIPE_EVENT_TRANSMIT_IDLE_BIT);
@@ -146,7 +146,7 @@ int modem_pipe_transmit(struct modem_pipe *pipe, const uint8_t *buf, size_t size
146146
int modem_pipe_receive(struct modem_pipe *pipe, uint8_t *buf, size_t size)
147147
{
148148
if (!pipe_test_events(pipe, PIPE_EVENT_OPENED_BIT)) {
149-
return -EPERM;
149+
return 0;
150150
}
151151

152152
pipe_clear_events(pipe, PIPE_EVENT_RECEIVE_READY_BIT);

tests/subsys/modem/modem_pipe/src/main.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ static void test_pipe_notify_receive_ready(void)
327327
"Unexpected state %u", (uint32_t)atomic_get(&test_state));
328328
}
329329

330+
static void test_pipe_receive_closed(void)
331+
{
332+
/* Try to receive from a closed pipe - should return 0 */
333+
zassert_equal(modem_pipe_receive(test_pipe, test_buffer, test_buffer_size), 0,
334+
"Reading from closed pipe should return 0");
335+
zassert_false(test_backend.receive_called, "receive should not be called on closed pipe");
336+
}
337+
330338
ZTEST(modem_pipe, test_async_open_close)
331339
{
332340
test_pipe_open();
@@ -397,5 +405,16 @@ ZTEST(modem_pipe, test_attach)
397405
test_pipe_attach_receive_not_ready_transmit_idle();
398406
}
399407

408+
ZTEST(modem_pipe, test_receive_closed)
409+
{
410+
test_pipe_open();
411+
test_reset();
412+
test_pipe_async_transmit();
413+
test_reset();
414+
test_pipe_close();
415+
/* Test reading from a closed pipe should return 0 */
416+
test_pipe_receive_closed();
417+
}
418+
400419
ZTEST_SUITE(modem_pipe, NULL, modem_backend_fake_setup, modem_backend_fake_before,
401420
modem_backend_fake_after, NULL);

0 commit comments

Comments
 (0)