modem: ppp: fix crash when attaching to a pipe
modem_pipe_attach() can send events before returning, which could provoke a crash as ppp->pipe, still NULL at that time, could be used either in receiving (if the pipe had some data pending) or in sending (if the PPP module had already been attached and had some data to send in its transmit buffer). ppp->pipe is now set before modem_pipe_attach(). Also, the ATTACHED_BIT is now set only after having actually attached. And finally, the send_work is now scheduled on PIPE_EVENT_OPENED so that data is flushed when the (closed) attached pipe is opened. Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
This commit is contained in:
parent
5fc02e3501
commit
6aef9d4d9a
1 changed files with 5 additions and 2 deletions
|
|
@ -319,6 +319,7 @@ static void modem_ppp_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_eve
|
|||
k_work_submit(&ppp->process_work);
|
||||
break;
|
||||
|
||||
case MODEM_PIPE_EVENT_OPENED:
|
||||
case MODEM_PIPE_EVENT_TRANSMIT_IDLE:
|
||||
k_work_submit(&ppp->send_work);
|
||||
break;
|
||||
|
|
@ -467,12 +468,14 @@ const struct ppp_api modem_ppp_ppp_api = {
|
|||
|
||||
int modem_ppp_attach(struct modem_ppp *ppp, struct modem_pipe *pipe)
|
||||
{
|
||||
if (atomic_test_and_set_bit(&ppp->state, MODEM_PPP_STATE_ATTACHED_BIT) == true) {
|
||||
if (atomic_test_bit(&ppp->state, MODEM_PPP_STATE_ATTACHED_BIT) == true) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
modem_pipe_attach(pipe, modem_ppp_pipe_callback, ppp);
|
||||
ppp->pipe = pipe;
|
||||
modem_pipe_attach(pipe, modem_ppp_pipe_callback, ppp);
|
||||
|
||||
atomic_set_bit(&ppp->state, MODEM_PPP_STATE_ATTACHED_BIT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue