All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: connman@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH 3/4] ofono: combine create_device and ready_to_create_device
Date: Wed, 27 Mar 2024 14:43:34 -0500	[thread overview]
Message-ID: <20240327194337.2735677-3-denkenz@gmail.com> (raw)
In-Reply-To: <20240327194337.2735677-1-denkenz@gmail.com>

These two functions are called one after the other, repeating the same
comment in multiple places.  Combine them into a single function that
takes care of checking whether the device can be created, and if so,
creating it.  Move the repeated comment to the new function.

While here, refactor handling of 'ident' which removes the need for the
'out' label.  Also, simplify some logic left over from CDMA support that
was checking whether modem->imsi exists.
---
 plugins/ofono.c | 75 ++++++++++++++++++-------------------------------
 1 file changed, 28 insertions(+), 47 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index fd8b442a674c..ad85c55d3df3 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -957,57 +957,56 @@ out:
 
 /*
  * This functions tests if we have the necessary information gathered
- * before we are able to create a device.
+ * in order to create the device.
  */
-static bool ready_to_create_device(struct modem_data *modem)
+static bool try_create_device(struct modem_data *modem)
 {
+	struct connman_device *device;
+	char *ident;
+
+	DBG("%s", modem->path);
+
 	if (modem->device)
 		return false;
 
 	if (!modem->imsi)
 		return false;
 
-	return true;
-}
-
-static void create_device(struct modem_data *modem)
-{
-	struct connman_device *device;
-	char *ident = NULL;
 
-	DBG("%s", modem->path);
+	/*
+	 * Create the device and register it at the core. Enabling (setting
+	 * it online is done through the modem_enable() callback.
+	 */
+	device = connman_device_create("ofono", CONNMAN_DEVICE_TYPE_CELLULAR);
+	if (!device) {
+		connman_error("Failed to create device for modem on path: %s",
+				modem->path);
+		return false;
+	}
 
-	if (modem->imsi)
-		ident = modem->imsi;
+	DBG("created device %p", device);
 
-	if (!connman_dbus_validate_ident(ident))
-		ident = connman_dbus_encode_string(ident);
+	if (!connman_dbus_validate_ident(modem->imsi))
+		ident = connman_dbus_encode_string(modem->imsi);
 	else
-		ident = g_strdup(ident);
-
-	device = connman_device_create("ofono", CONNMAN_DEVICE_TYPE_CELLULAR);
-	if (!device)
-		goto out;
-
-	DBG("device %p", device);
+		ident = g_strdup(modem->imsi);
 
 	connman_device_set_ident(device, ident);
+	g_free(ident);
 
 	connman_device_set_string(device, "Path", modem->path);
-
 	connman_device_set_data(device, modem);
 
 	if (connman_device_register(device) < 0) {
-		connman_error("Failed to register cellular device");
+		connman_error("Failed to register cellular device %p", device);
 		connman_device_unref(device);
-		goto out;
+		return false;
 	}
 
 	modem->device = device;
-
 	connman_device_set_powered(modem->device, modem->online);
-out:
-	g_free(ident);
+
+	return true;
 }
 
 static void destroy_device(struct modem_data *modem)
@@ -1835,17 +1834,7 @@ static gboolean sim_changed(DBusConnection *conn, DBusMessage *message,
 
 	if (g_str_equal(key, "SubscriberIdentity")) {
 		sim_update_imsi(modem, &value);
-
-		if (!ready_to_create_device(modem))
-			return TRUE;
-
-		/*
-		 * This is a GSM modem. Create the device and
-		 * register it at the core. Enabling (setting
-		 * it online is done through the
-		 * modem_enable() callback.
-		 */
-		create_device(modem);
+		try_create_device(modem);
 	}
 
 	return TRUE;
@@ -1869,17 +1858,9 @@ static void sim_properties_reply(struct modem_data *modem,
 		if (g_str_equal(key, "SubscriberIdentity")) {
 			sim_update_imsi(modem, &value);
 
-			if (!ready_to_create_device(modem))
+			if (!try_create_device(modem))
 				return;
 
-			/*
-			 * This is a GSM modem. Create the device and
-			 * register it at the core. Enabling (setting
-			 * it online is done through the
-			 * modem_enable() callback.
-			 */
-			create_device(modem);
-
 			if (!modem->online)
 				return;
 
-- 
2.43.0


  parent reply	other threads:[~2024-03-27 19:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 19:43 [PATCH 1/4] ofono: Add generic method to convert a list of strings to flags Denis Kenzior
2024-03-27 19:43 ` [PATCH 2/4] ofono: Set modem->interfaces earlier Denis Kenzior
2024-03-27 19:43 ` Denis Kenzior [this message]
2024-03-27 19:43 ` [PATCH 4/4] ofono: delay device creation until lte settings are provisioned Denis Kenzior
2024-04-17 17:00 ` [PATCH 1/4] ofono: Add generic method to convert a list of strings to flags patchwork-bot+connman

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=20240327194337.2735677-3-denkenz@gmail.com \
    --to=denkenz@gmail.com \
    --cc=connman@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.