Open Source Telephony
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ofono@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH v2 02/23] qmi: lookup shared family directly by type
Date: Thu, 13 Jun 2024 16:41:11 -0500	[thread overview]
Message-ID: <20240613214134.1056517-2-denkenz@gmail.com> (raw)
In-Reply-To: <20240613214134.1056517-1-denkenz@gmail.com>

Since it is currently no longer possible to create dedicated clients for
a given service type, use the service type as the key to the family_list
hashtable.  For QMUX, this allows the service family to be looked up
directly instead of iterating over the entire hash table.  The hash
table entry at key=service_type will always point to the shared service
family.
---
 drivers/qmimodem/qmi.c | 61 +++++++++---------------------------------
 1 file changed, 13 insertions(+), 48 deletions(-)

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index dfcf46a6e35e..1b3fa34f685c 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -330,21 +330,6 @@ static bool __notify_compare(const void *data, const void *user_data)
 			notify->service_handle == details->service_handle;
 }
 
-struct service_find_by_type_data {
-	unsigned int type;
-	struct service_family *found_family;
-};
-
-static void __family_find_by_type(const void *key, void *value,
-					void *user_data)
-{
-	struct service_family *family = value;
-	struct service_find_by_type_data *data = user_data;
-
-	if (family->info.service_type == data->type)
-		data->found_family = family;
-}
-
 static const char *__service_type_to_string(uint8_t type)
 {
 	switch (type) {
@@ -1403,7 +1388,6 @@ static struct service_family *service_family_ref(struct service_family *family)
 static void service_family_unref(struct service_family *family)
 {
 	struct qmi_device *device;
-	unsigned int hash_id;
 
 	if (--family->ref_count)
 		return;
@@ -1412,9 +1396,15 @@ static void service_family_unref(struct service_family *family)
 	if (!device)
 		goto done;
 
-	hash_id = family_list_create_hash(family->info.service_type,
+	if (family->client_id) {
+		unsigned int hash_id =
+			family_list_create_hash(family->info.service_type,
 							family->client_id);
-	l_hashmap_remove(device->family_list, L_UINT_TO_PTR(hash_id));
+		l_hashmap_remove(device->family_list, L_UINT_TO_PTR(hash_id));
+	}
+
+	l_hashmap_remove(device->family_list,
+				L_UINT_TO_PTR(family->info.service_type));
 
 	if (device->ops->client_release)
 		device->ops->client_release(device, family->info.service_type,
@@ -1799,7 +1789,6 @@ static void qmux_client_create_callback(uint16_t message, uint16_t length,
 	struct qmi_device_qmux *qmux =
 		l_container_of(device, struct qmi_device_qmux, super);
 	struct service_family *family = NULL;
-	struct service_family *old_family = NULL;
 	struct qmi_service_info info;
 	const struct qmi_result_code *result_code;
 	const struct qmi_client_id *client_id;
@@ -1829,16 +1818,13 @@ static void qmux_client_create_callback(uint16_t message, uint16_t length,
 	info.minor = data->minor;
 
 	family = service_family_create(device, &info, client_id->client);
-
+	family = service_family_ref(family);
 	hash_id = family_list_create_hash(family->info.service_type,
 							family->client_id);
-	l_hashmap_replace(device->family_list, L_UINT_TO_PTR(hash_id),
-				family, (void **) &old_family);
-
-	if (old_family)
-		family_destroy(old_family);
-
-	family = service_family_ref(family);
+	l_hashmap_insert(device->family_list, L_UINT_TO_PTR(hash_id), family);
+	l_hashmap_insert(device->family_list,
+				L_UINT_TO_PTR(family->info.service_type),
+				family);
 done:
 	service_create_shared_pending_reply(qmux, data->type, family);
 	if (family)
@@ -2636,28 +2622,7 @@ bool qmi_service_create_shared(struct qmi_device *device, uint16_t type,
 	if (type == QMI_SERVICE_CONTROL)
 		return false;
 
-	/*
-	 * First check to see if the bare type is in the hashmap. If it is not
-	 * the family might exist already, but have the client id included in
-	 * the hash id.
-	 */
 	family = l_hashmap_lookup(device->family_list, L_UINT_TO_PTR(type));
-
-	if (!family) {
-		struct service_find_by_type_data find_data;
-
-		/*
-		 * There is no way to find in an l_hashmap using a custom
-		 * function. Instead we use a temporary struct to store the
-		 * found service family.
-		 */
-		find_data.type = type;
-		find_data.found_family = NULL;
-		l_hashmap_foreach(device->family_list,	__family_find_by_type,
-						&find_data);
-		family = find_data.found_family;
-	}
-
 	if (!family) {
 		const struct qmi_service_info *info;
 
-- 
2.45.0


  reply	other threads:[~2024-06-13 21:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 21:41 [PATCH v2 01/23] gobi: Remove phonebook and stk atom creation Denis Kenzior
2024-06-13 21:41 ` Denis Kenzior [this message]
2024-06-13 21:41 ` [PATCH v2 03/23] core: allow multiple args in atom constructors Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 04/23] unit: Update unit tests to the new API Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 05/23] core: Support register on probe flag Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 06/23] qmi: introduce qmi_service_clone Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 07/23] gobi: request needed services at .enable() Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 08/23] qmi: devinfo: Drop use of qmi_service_create_shared Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 09/23] qmi: sim-legacy: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 10/23] qmi: voicecall: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 11/23] qmi: call-barring: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 12/23] qmi: call-forwarding: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 13/23] qmi: call-settings: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 14/23] qmi: ussd: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 15/23] qmi: location-reporting: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 16/23] qmi: sms: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 17/23] qmi: netreg: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 18/23] qmi: netmon: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 19/23] qmi: lte: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 20/23] qmi: gprs-context: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 21/23] qmi: sim: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 22/23] qmi: gprs: " Denis Kenzior
2024-06-13 21:41 ` [PATCH v2 23/23] qmi: radio-settings: " Denis Kenzior
2024-06-14 15:10 ` [PATCH v2 01/23] gobi: Remove phonebook and stk atom creation patchwork-bot+ofono

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240613214134.1056517-2-denkenz@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ofono@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox