diff mbox series

[2/7] qmi: gprs-context: Do not free/alloc unnecessarily

Message ID 20240416151448.3359644-2-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 844b488b2919d5af4bf9d8c8278344ab354abeb7
Headers show
Series [1/7] qmimodem: wds: Introduce qmi_wds_ip_family enum | expand

Commit Message

Denis Kenzior April 16, 2024, 3:14 p.m. UTC
In start_net_cb, a new cb_data object is allocated which contains the
exact same information as the cb_data object being passed in as
userdata.  Use cb_data_ref/unref instead.

While here, also fix an erroneous invocation of CALLBACK_WITH_SUCCESS if
the GET_CURRENT_SETTINGS request was not queued successfully.  An error
should be generated instead.
---
 drivers/qmimodem/gprs-context.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/gprs-context.c b/drivers/qmimodem/gprs-context.c
index cbe33861968b..1d7449e68ccc 100644
--- a/drivers/qmimodem/gprs-context.c
+++ b/drivers/qmimodem/gprs-context.c
@@ -166,17 +166,12 @@  static void start_net_cb(struct qmi_result *result, void *user_data)
 
 	data->pkt_handle = handle;
 
-	/* Duplicate cbd, the old one will be freed when this method returns */
-	cbd = cb_data_new(cb, cbd->data);
-	cbd->user = gc;
 
 	if (qmi_service_send(data->wds, QMI_WDS_GET_CURRENT_SETTINGS, NULL,
-					get_settings_cb, cbd, l_free) > 0)
+				get_settings_cb, cbd, cb_data_unref) > 0) {
+		cb_data_ref(cbd);
 		return;
-
-	CALLBACK_WITH_SUCCESS(cb, cbd->data);
-
-	return;
+	}
 
 error:
 	data->active_context = 0;
@@ -205,7 +200,7 @@  static void qmi_gprs_read_settings(struct ofono_gprs_context* gc,
 	cbd->user = gc;
 
 	if (qmi_service_send(data->wds, QMI_WDS_START_NETWORK, NULL,
-					start_net_cb, cbd, l_free) > 0)
+					start_net_cb, cbd, cb_data_unref) > 0)
 		return;
 
 	data->active_context = 0;
@@ -277,7 +272,7 @@  static void qmi_activate_primary(struct ofono_gprs_context *gc,
 					strlen(ctx->password), ctx->password);
 
 	if (qmi_service_send(data->wds, QMI_WDS_START_NETWORK, param,
-					start_net_cb, cbd, l_free) > 0)
+					start_net_cb, cbd, cb_data_unref) > 0)
 		return;
 
 	qmi_param_free(param);