[PATCH] qmi: Allow qmi_qmux_device_discover be called from callback

Denis Kenzior <[email protected]>
Newsgroups dev.linux.lists.ofono
Message-ID <[email protected]>
When the gobi modem plugin performs discovery, it checks whether the WMS
service is present in the callback function provided to
qmi_qmux_device_discover().  If the WMS service isn't present (likely
due to a timeout from the modem firmware), device discovery is
re-attempted from within the callback.  This functionality was broken
since the qmux->discover.tid was not set to 0 until after the callback
function returned.  Allow such re-entrant behavior by making a copy of
device discovery func/user_data/destroy members and de-initializing the
discovery structure prior to invoking the callbacks.

Fixes: 217b57328473 ("qmi: Rename and refactor qmi_device_discover")
---
 drivers/qmimodem/qmi.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index b8f46a5b4a0e..0ba2e8b9e352 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -1152,13 +1152,17 @@ static struct qmi_request *find_control_request(struct qmi_qmux_device *qmux,
 
 static void __qmux_discovery_finished(struct qmi_qmux_device *qmux)
 {
+	qmi_qmux_device_discover_func_t func = qmux->discover.func;
+	void *user_data = qmux->discover.user_data;
+	qmi_destroy_func_t destroy = qmux->discover.destroy;
+
 	l_timeout_remove(qmux->discover.timeout);
-	qmux->discover.func(qmux->discover.user_data);
+	memset(&qmux->discover, 0, sizeof(qmux->discover));
 
-	if (qmux->discover.destroy)
-		qmux->discover.destroy(qmux->discover.user_data);
+	func(user_data);
 
-	memset(&qmux->discover, 0, sizeof(qmux->discover));
+	if (destroy)
+		destroy(user_data);
 }
 
 static void qmux_sync_callback(struct qmi_request *req, uint16_t message,
-- 
2.45.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.