From 7ade471a47d22336fb88d3592dd30cbd32bc2e6e Mon Sep 17 00:00:00 2001 From: Marek Metelski Date: Tue, 7 Jun 2022 11:42:54 +0200 Subject: [PATCH] drivers: gsm_ppp: Wait for NET_IF_DOWN in gsm_ppp_stop only if iface was up Check if ppp iface was actually up before taking it down and waiting for NET_EVENT_IF_DOWN. This allows to call gsm_ppp_stop() even if the PPP was never started, which previously caused the call to lock forever. This case is useful, for example, if the modem didn't attach to network in desirable time and user wants to abort PPP setup. Signed-off-by: Marek Metelski --- drivers/modem/gsm_ppp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/modem/gsm_ppp.c b/drivers/modem/gsm_ppp.c index 6f48f4bea49..f1b5c1cdde1 100644 --- a/drivers/modem/gsm_ppp.c +++ b/drivers/modem/gsm_ppp.c @@ -1154,11 +1154,11 @@ void gsm_ppp_stop(const struct device *dev) gsm_ppp_lock(gsm); - net_if_l2(iface)->enable(iface, false); - /* wait for the interface to be properly down */ - (void)k_sem_take(&gsm->sem_if_down, K_FOREVER); - + if (net_if_is_up(iface)) { + net_if_l2(iface)->enable(iface, false); + (void)k_sem_take(&gsm->sem_if_down, K_FOREVER); + } if (IS_ENABLED(CONFIG_GSM_MUX)) { if (gsm->ppp_dev) {