diff mbox series

[v2,2/6] qmimodem: Use l_timeout and l_idle for discovery

Message ID 20240221221725.185480-2-steve.schrock@getcruise.com (mailing list archive)
State Accepted
Commit ae0392353d8f15a1d20578ec1a9b60d6d7123770
Headers show
Series [v2,1/6] qmimodem: Use l_queue_remove_if to eliminate double lookup | expand

Commit Message

Steve Schrock Feb. 21, 2024, 10:17 p.m. UTC
---
 drivers/qmimodem/qmi.c | 42 +++++++++++++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index d2d4eefa..6880dc45 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -1101,17 +1101,19 @@  struct discover_data {
 	void *user_data;
 	qmi_destroy_func_t destroy;
 	uint16_t tid;
-	guint timeout;
+	struct l_timeout *timeout;
+	struct l_idle *idle;
 };
 
-static void discover_data_free(gpointer user_data)
+static void discover_data_free(void *user_data)
 {
 	struct discover_data *data = user_data;
 
-	if (data->timeout) {
-		g_source_remove(data->timeout);
-		data->timeout = 0;
-	}
+	if (data->timeout)
+		l_timeout_remove(data->timeout);
+
+	if (data->idle)
+		l_idle_remove(data->idle);
 
 	if (data->destroy)
 		data->destroy(data->user_data);
@@ -1253,17 +1255,33 @@  static struct qmi_request *find_control_request(struct qmi_device *device,
 	return req;
 }
 
-static gboolean discover_reply(gpointer user_data)
+
+static void discover_reply_idle(struct l_idle *idle, void *user_data)
+{
+	struct discover_data *data = user_data;
+	struct qmi_device *device = data->device;
+
+	l_idle_remove(data->idle);
+	data->idle = NULL;
+
+	if (data->func)
+		data->func(data->user_data);
+
+	__qmi_device_discovery_complete(device, &data->super);
+}
+
+static void discover_reply_timeout(struct l_timeout *timeout, void *user_data)
 {
 	struct discover_data *data = user_data;
 	struct qmi_device *device = data->device;
 	struct qmi_request *req;
 
+	l_timeout_remove(data->timeout);
+	data->timeout = NULL;
+
 	/* remove request from queues */
 	req = find_control_request(device, data->tid);
 
-	data->timeout = 0;
-
 	if (data->func)
 		data->func(data->user_data);
 
@@ -1271,8 +1289,6 @@  static gboolean discover_reply(gpointer user_data)
 
 	if (req)
 		__request_free(req);
-
-	return FALSE;
 }
 
 bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func,
@@ -1295,7 +1311,7 @@  bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func,
 	data->destroy = destroy;
 
 	if (device->version_list) {
-		data->timeout = g_timeout_add_seconds(0, discover_reply, data);
+		data->idle = l_idle_create(discover_reply_idle, data, NULL);
 		__qmi_device_discovery_started(device, &data->super);
 		return true;
 	}
@@ -1305,7 +1321,7 @@  bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func,
 			NULL, 0, discover_callback, data);
 
 	data->tid = __request_submit(device, req);
-	data->timeout = g_timeout_add_seconds(5, discover_reply, data);
+	data->timeout = l_timeout_create(5, discover_reply_timeout, data, NULL);
 
 	__qmi_device_discovery_started(device, &data->super);