[PATCH 11/11] wifi: ath12k: fix endianness handling in QMI response

Alexander Wilhelm alexander.wilhelm at westermo.com
Wed Jul 16 00:51:00 PDT 2025


Ensure proper endianness support for big-endian platforms by correcting
data types in the QMI response. Add missing byte swaps wherever this
structure is accessed or modified.

Fixes: 9b8a11e82615 ("soc: qcom: Introduce QMI encoder/decoder")
Signed-off-by: Alexander Wilhelm <alexander.wilhelm at westermo.com>
---
 drivers/net/wireless/ath/ath12k/qmi.c | 49 ++++++++++++++++-----------
 include/linux/soc/qcom/qmi.h          |  4 +--
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c
index 71cf6408c6fb..d421e7b3fc87 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.c
+++ b/drivers/net/wireless/ath/ath12k/qmi.c
@@ -2227,9 +2227,10 @@ int ath12k_qmi_host_cap_send(struct ath12k_base *ab)
 	if (ret < 0)
 		goto out;
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ath12k_warn(ab, "Host capability request failed, result: %d, err: %d\n",
-			    resp.resp.result, resp.resp.error);
+			    le16_to_cpu(resp.resp.result),
+			    le16_to_cpu(resp.resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
@@ -2264,7 +2265,7 @@ static void ath12k_qmi_phy_cap_send(struct ath12k_base *ab)
 	if (ret < 0)
 		goto out;
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ret = -EOPNOTSUPP;
 		goto out;
 	}
@@ -2352,9 +2353,10 @@ static int ath12k_qmi_fw_ind_register_send(struct ath12k_base *ab)
 		goto out;
 	}
 
-	if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp->resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ath12k_warn(ab, "FW Ind register request failed, result: %d, err: %d\n",
-			    resp->resp.result, resp->resp.error);
+			    le16_to_cpu(resp->resp.result),
+			    le16_to_cpu(resp->resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
@@ -2427,15 +2429,16 @@ int ath12k_qmi_respond_fw_mem_request(struct ath12k_base *ab)
 		goto out;
 	}
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		/* the error response is expected when
 		 * target_mem_delayed is true.
 		 */
-		if (delayed && resp.resp.error == 0)
+		if (delayed && le16_to_cpu(resp.resp.error) == 0)
 			goto out;
 
 		ath12k_warn(ab, "Respond mem req failed, result: %d, err: %d\n",
-			    resp.resp.result, resp.resp.error);
+			    le16_to_cpu(resp.resp.result),
+			    le16_to_cpu(resp.resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
@@ -2842,9 +2845,10 @@ int ath12k_qmi_request_target_cap(struct ath12k_base *ab)
 		goto out;
 	}
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ath12k_warn(ab, "qmi targetcap req failed, result: %d, err: %d\n",
-			    resp.resp.result, resp.resp.error);
+			    le16_to_cpu(resp.resp.result),
+			    le16_to_cpu(resp.resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
@@ -2981,9 +2985,10 @@ static int ath12k_qmi_load_file_target_mem(struct ath12k_base *ab,
 		if (ret < 0)
 			goto out;
 
-		if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+		if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 			ath12k_warn(ab, "qmi BDF download failed, result: %d, err: %d\n",
-				    resp.resp.result, resp.resp.error);
+				    le16_to_cpu(resp.resp.result),
+				    le16_to_cpu(resp.resp.error));
 			ret = -EINVAL;
 			goto out;
 		}
@@ -3224,9 +3229,10 @@ int ath12k_qmi_wlanfw_m3_info_send(struct ath12k_base *ab)
 		goto out;
 	}
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ath12k_warn(ab, "qmi M3 info request failed, result: %d, err: %d\n",
-			    resp.resp.result, resp.resp.error);
+			    le16_to_cpu(resp.resp.result),
+			    le16_to_cpu(resp.resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
@@ -3273,9 +3279,10 @@ static int ath12k_qmi_wlanfw_mode_send(struct ath12k_base *ab,
 		goto out;
 	}
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ath12k_warn(ab, "Mode request failed, mode: %d, result: %d err: %d\n",
-			    mode, resp.resp.result, resp.resp.error);
+			    mode, le16_to_cpu(resp.resp.result),
+			    le16_to_cpu(resp.resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
@@ -3360,9 +3367,10 @@ static int ath12k_qmi_wlanfw_wlan_cfg_send(struct ath12k_base *ab)
 		goto out;
 	}
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ath12k_warn(ab, "qmi wlan config request failed, result: %d, err: %d\n",
-			    resp.resp.result, resp.resp.error);
+			    le16_to_cpu(resp.resp.result),
+			    le16_to_cpu(resp.resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
@@ -3404,9 +3412,10 @@ static int ath12k_qmi_wlanfw_wlan_ini_send(struct ath12k_base *ab)
 		goto out;
 	}
 
-	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
+	if (le16_to_cpu(resp.resp.result) != QMI_RESULT_SUCCESS_V01) {
 		ath12k_warn(ab, "QMI wlan ini response failure: %d %d\n",
-			    resp.resp.result, resp.resp.error);
+			    le16_to_cpu(resp.resp.result),
+			    le16_to_cpu(resp.resp.error));
 		ret = -EINVAL;
 		goto out;
 	}
diff --git a/include/linux/soc/qcom/qmi.h b/include/linux/soc/qcom/qmi.h
index 469e02d2aa0d..a487b724abd2 100644
--- a/include/linux/soc/qcom/qmi.h
+++ b/include/linux/soc/qcom/qmi.h
@@ -98,8 +98,8 @@ struct qmi_elem_info {
  * @error:	error value, when @result is QMI_RESULT_FAILURE_V01
  */
 struct qmi_response_type_v01 {
-	u16 result;
-	u16 error;
+	__le16 result;
+	__le16 error;
 };
 
 extern const struct qmi_elem_info qmi_response_type_v01_ei[];
-- 
2.34.1




More information about the ath12k mailing list