diff mbox series

[2/2] qmimodem: sms: Silence valgrind warning

Message ID 20240319164309.2676887-2-denkenz@gmail.com (mailing list archive)
State Accepted
Commit b0f808ccd6e1f81b19da247bc0a69e3015b3168b
Headers show
Series [1/2] qmimodem: Rework GET_CARD_STATUS retry logic | expand

Commit Message

Denis Kenzior March 19, 2024, 4:42 p.m. UTC
ofonod[2670789]: drivers/qmimodem/sms.c:get_msg_protocol_cb()
==2670789== Conditional jump or move depends on uninitialised value(s)
==2670789==    at 0x46552A: get_msg_protocol_cb (sms.c:565)
==2670789==    by 0x45D5C1: service_send_callback (qmi.c:2762)
==2670789==    by 0x4594F5: __rx_message (qmi.c:846)
==2670789==    by 0x45A6A4: received_qmux_data (qmi.c:1393)
==2670789==    by 0x58D71C: io_callback (io.c:105)
==2670789==    by 0x58C073: l_main_iterate (main.c:461)
==2670789==    by 0x500EC0: event_check (main.c:190)
==2670789==    by 0x48FC09D: ??? (in /usr/lib/libglib-2.0.so.0.7800.3)
==2670789==    by 0x49591CF: ??? (in /usr/lib/libglib-2.0.so.0.7800.3)
==2670789==    by 0x48FBB96: g_main_loop_run (in /usr/lib/libglib-2.0.so.0.7800.3)
==2670789==    by 0x5011F5: main (main.c:284)
==2670789==
ofonod[2670789]: drivers/qmimodem/sms.c:get_msg_list()

The warning is triggered because GET_MSG_PROTOCOL command succeeds and
qmi_result_set_error() returns false.  It seems the intent in this case
is to use the msg_mode reported by the device by obtaining it using
qmi_result_get_uint8.  In case GET_MSG_PROTOCOL command fails, both CDMA
and WCDMA messages should be queried.
---
 drivers/qmimodem/sms.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/sms.c b/drivers/qmimodem/sms.c
index 498a6d778303..b9fe963520d6 100644
--- a/drivers/qmimodem/sms.c
+++ b/drivers/qmimodem/sms.c
@@ -556,21 +556,23 @@  static void get_msg_protocol_cb(struct qmi_result *result, void *user_data)
 
 	DBG("");
 
-	if (qmi_result_set_error(result, &err) &&
-			(err != QMI_ERR_OP_DEVICE_UNSUPPORTED)) {
-		DBG("Err: protocol %d - %s", err, qmi_result_get_error(result));
-		return;
-	}
+	if (qmi_result_set_error(result, &err)) {
+		if (err != QMI_ERR_OP_DEVICE_UNSUPPORTED) {
+			DBG("Err: protocol %d - %s",
+					err, qmi_result_get_error(result));
+			return;
+		}
 
-	if (err != QMI_ERR_OP_DEVICE_UNSUPPORTED) {
-		/* modem supports only 1 protocol */
-		qmi_result_get_uint8(result, QMI_WMS_PARAM_PROTOCOL,
-					&data->msg_mode);
-	} else {
-		/* check both, start with 1 then switch to other */
-		DBG("device supports CDMA and WCDMA msg protocol");
+		/* Get Message Protocol operation is not supported */
+		DBG("query both CDMA and WCDMA");
 		data->msg_mode_all = true;
 		data->msg_mode = QMI_WMS_MESSAGE_MODE_CDMA;
+	} else {
+		/* Query of current protocol succeeded, use that */
+		qmi_result_get_uint8(result, QMI_WMS_PARAM_PROTOCOL,
+					&data->msg_mode);
+
+		DBG("msg_mode: %s", data->msg_mode ? "WCDMA" : "CDMA");
 	}
 
 	/* check for messages */