diff mbox series

[4/4] qmi: voicecall: Remove redundant initialization to NULL

Message ID 20240422214058.3411417-4-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 789f68a5fba332fe6d16102c63578eac46a1f0b3
Headers show
Series [1/4] qmi: Remove redundant NULL check in qmi_param_new | expand

Commit Message

Denis Kenzior April 22, 2024, 9:40 p.m. UTC
param was needlelly initialized to NULL in answer() and
release_specific().  Since all error paths free both cbd and param,
declare & initialize these variables at the start of the function.

Handle dial() similarly for consistency.
---
 drivers/qmimodem/voicecall.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/voicecall.c b/drivers/qmimodem/voicecall.c
index dcb91c642c0c..b66f1ae7d56d 100644
--- a/drivers/qmimodem/voicecall.c
+++ b/drivers/qmimodem/voicecall.c
@@ -434,7 +434,8 @@  static void dial(struct ofono_voicecall *vc,
 {
 	struct voicecall_data *vd = ofono_voicecall_get_data(vc);
 	struct cb_data *cbd = cb_data_new(cb, data);
-	struct qmi_param *param;
+	struct qmi_param *param = qmi_param_new();
+
 	const char *calling_number = phone_number_to_string(ph);
 
 	static const uint8_t PARAM_CALL_NUMBER = 0x01;
@@ -446,8 +447,6 @@  static void dial(struct ofono_voicecall *vc,
 	cbd->user = vc;
 	memcpy(&vd->dialed, ph, sizeof(*ph));
 
-	param = qmi_param_new();
-
 	if (!qmi_param_append(param, PARAM_CALL_NUMBER,
 			strlen(calling_number), calling_number))
 		goto error;
@@ -492,27 +491,22 @@  static void answer(struct ofono_voicecall *vc,
 					ofono_voicecall_cb_t cb, void *data)
 {
 	struct voicecall_data *vd = ofono_voicecall_get_data(vc);
-	struct cb_data *cbd;
+	struct cb_data *cbd = cb_data_new(cb, data);
+	struct qmi_param *param = qmi_param_new();
 	struct ofono_call *call;
-	struct qmi_param *param = NULL;
-
 	static const uint8_t PARAM_CALL_ID = 0x01;
 
 	DBG("");
 
-	call = l_queue_find(vd->call_list,
-					ofono_call_match_by_status,
-					L_UINT_TO_PTR(CALL_STATUS_INCOMING));
-
-	param = qmi_param_new();
-	cbd = cb_data_new(cb, data);
-	cbd->user = vc;
-
-	if (call == NULL) {
+	call = l_queue_find(vd->call_list, ofono_call_match_by_status,
+				L_UINT_TO_PTR(CALL_STATUS_INCOMING));
+	if (!call) {
 		ofono_error("Can not find a call to pick up");
 		goto error;
 	}
 
+	cbd->user = vc;
+
 	if (!qmi_param_append_uint8(param, PARAM_CALL_ID,
 			call->id))
 		goto error;
@@ -552,22 +546,20 @@  static void release_specific(struct ofono_voicecall *vc, int id,
 			ofono_voicecall_cb_t cb, void *data)
 {
 	struct voicecall_data *vd = ofono_voicecall_get_data(vc);
-	struct cb_data *cbd;
-	struct qmi_param *param = NULL;
+	struct cb_data *cbd = cb_data_new(cb, data);
+	struct qmi_param *param = qmi_param_new();
 
 	static const uint8_t PARAM_CALL_ID = 0x01;
 
 	DBG("");
 
-	param = qmi_param_new();
-	cbd = cb_data_new(cb, data);
 	cbd->user = vc;
 
 	if (!qmi_param_append_uint8(param, PARAM_CALL_ID, id))
 		goto error;
 
 	if (qmi_service_send(vd->voice, QMI_VOICE_END_CALL, param, end_call_cb,
-			cbd, l_free) > 0)
+				cbd, l_free) > 0)
 		return;
 
 error: