diff mbox series

[1/4] qmi: Create a method to find a service by type

Message ID 20240228215319.153068-1-steve.schrock@getcruise.com (mailing list archive)
State Superseded
Headers show
Series [1/4] qmi: Create a method to find a service by type | expand

Commit Message

Steve Schrock Feb. 28, 2024, 9:53 p.m. UTC
---
 drivers/qmimodem/qmi.c | 43 +++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index ffb26326..aca4df0d 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -953,39 +953,44 @@  static const void *tlv_get(const void *data, uint16_t size,
 	return NULL;
 }
 
-bool qmi_device_get_service_version(struct qmi_device *device, uint16_t type,
-					uint16_t *major, uint16_t *minor)
+static const struct qmi_service_info *__find_service_info_by_type(
+				struct qmi_device *device, uint16_t type)
 {
+	const struct qmi_service_info *info = NULL;
 	const struct l_queue_entry *entry;
 
 	for (entry = l_queue_get_entries(device->service_infos);
 						entry; entry = entry->next) {
-		const struct qmi_service_info *info = entry->data;
-
-		if (info->service_type != type)
-			continue;
+		info = entry->data;
 
-		*major = info->major;
-		*minor = info->minor;
-		return true;
+		if (info->service_type == type)
+			break;
 	}
 
-	return false;
+	return info;
 }
 
-bool qmi_device_has_service(struct qmi_device *device, uint16_t type)
+bool qmi_device_get_service_version(struct qmi_device *device, uint16_t type,
+					uint16_t *major, uint16_t *minor)
 {
-	const struct l_queue_entry *entry;
+	const struct qmi_service_info *info;
 
-	for (entry = l_queue_get_entries(device->service_infos);
-						entry; entry = entry->next) {
-		const struct qmi_service_info *info = entry->data;
+	info = __find_service_info_by_type(device, type);
+	if (!info)
+		return false;
 
-		if (info->service_type == type)
-			return true;
-	}
+	*major = info->major;
+	*minor = info->minor;
+	return true;
+}
 
-	return false;
+bool qmi_device_has_service(struct qmi_device *device, uint16_t type)
+{
+	const struct qmi_service_info *info;
+
+	info = __find_service_info_by_type(device, type);
+
+	return info != NULL;
 }
 
 struct discover_data {