diff mbox series

[v2,03/11] modem: commonize interface string list generation

Message ID 20240322154234.2720542-3-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 864466ac2d9ea8a7100ee2d192f5f68ecff5e057
Headers show
Series [v2,01/11] phonesim: Allow phonesim to work with Multiplexer=internal | expand

Commit Message

Denis Kenzior March 22, 2024, 3:42 p.m. UTC
This code was repeated in multiple places, factor it out into a common
function.
---
 src/modem.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/src/modem.c b/src/modem.c
index 37d9bd57fdd9..24ab61761325 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -149,6 +149,19 @@  static char **get_features(struct ofono_modem *modem)
 	return features;
 }
 
+static char **get_interfaces(struct ofono_modem *modem)
+{
+	char **interfaces = l_new(char *,
+				g_slist_length(modem->interface_list) + 1);
+	unsigned int i;
+	GSList *l;
+
+	for (i = 0, l = modem->interface_list; l; l = l->next, i++)
+		interfaces[i] = l->data;
+
+	return interfaces;
+}
+
 unsigned int __ofono_modem_callid_next(struct ofono_modem *modem)
 {
 	unsigned int i;
@@ -832,8 +845,6 @@  void __ofono_modem_append_properties(struct ofono_modem *modem,
 {
 	char **interfaces;
 	char **features;
-	int i;
-	GSList *l;
 	struct ofono_devinfo *info;
 	dbus_bool_t emergency = ofono_modem_get_emergency_mode(modem);
 	const char *strtype;
@@ -883,12 +894,10 @@  void __ofono_modem_append_properties(struct ofono_modem *modem,
 		ofono_dbus_dict_append(dict, "SystemPath", DBUS_TYPE_STRING,
 					&system_path);
 
-	interfaces = g_new0(char *, g_slist_length(modem->interface_list) + 1);
-	for (i = 0, l = modem->interface_list; l; l = l->next, i++)
-		interfaces[i] = l->data;
+	interfaces = get_interfaces(modem);
 	ofono_dbus_dict_append_array(dict, "Interfaces", DBUS_TYPE_STRING,
 					&interfaces);
-	g_free(interfaces);
+	l_free(interfaces);
 
 	features = get_features(modem);
 	ofono_dbus_dict_append_array(dict, "Features", DBUS_TYPE_STRING,
@@ -1301,17 +1310,13 @@  static gboolean trigger_interface_update(void *data)
 	DBusConnection *conn = ofono_dbus_get_connection();
 	char **interfaces;
 	char **features;
-	GSList *l;
-	int i;
 
-	interfaces = g_new0(char *, g_slist_length(modem->interface_list) + 1);
-	for (i = 0, l = modem->interface_list; l; l = l->next, i++)
-		interfaces[i] = l->data;
+	interfaces = get_interfaces(modem);
 	ofono_dbus_signal_array_property_changed(conn, modem->path,
 						OFONO_MODEM_INTERFACE,
 						"Interfaces", DBUS_TYPE_STRING,
 						&interfaces);
-	g_free(interfaces);
+	l_free(interfaces);
 
 	features = get_features(modem);
 	ofono_dbus_signal_array_property_changed(conn, modem->path,