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

Alexander Wilhelm posted 11 patches 2 months, 3 weeks ago
There is a newer version of this series
[PATCH 11/11] wifi: ath12k: fix endianness handling in QMI response
Posted by Alexander Wilhelm 2 months, 3 weeks ago
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@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
Re: [PATCH 11/11] wifi: ath12k: fix endianness handling in QMI response
Posted by kernel test robot 2 months, 3 weeks ago
Hi Alexander,

kernel test robot noticed the following build warnings:

[auto build test WARNING on ath/ath-next]
[also build test WARNING on linus/master v6.16-rc6 next-20250716]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Alexander-Wilhelm/wifi-ath12k-fix-endianness-handling-in-QMI-host-capability-request/20250716-162058
base:   https://git.kernel.org/pub/scm/linux/kernel/git/ath/ath.git ath-next
patch link:    https://lore.kernel.org/r/20250716075100.1447352-12-alexander.wilhelm%40westermo.com
patch subject: [PATCH 11/11] wifi: ath12k: fix endianness handling in QMI response
config: mips-randconfig-r123-20250717 (https://download.01.org/0day-ci/archive/20250717/202507171640.30pUvpPv-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 8.5.0
reproduce: (https://download.01.org/0day-ci/archive/20250717/202507171640.30pUvpPv-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507171640.30pUvpPv-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/soc/qcom/pdr_interface.c:612:22: sparse: sparse: restricted __le16 degrades to integer
   drivers/soc/qcom/pdr_interface.c:613:22: sparse: sparse: restricted __le16 degrades to integer

vim +612 drivers/soc/qcom/pdr_interface.c

fbe639b44a8275 Sibi Sankar           2020-03-12  549  
fbe639b44a8275 Sibi Sankar           2020-03-12  550  /**
fbe639b44a8275 Sibi Sankar           2020-03-12  551   * pdr_restart_pd() - restart PD
fbe639b44a8275 Sibi Sankar           2020-03-12  552   * @pdr:	PDR client handle
fbe639b44a8275 Sibi Sankar           2020-03-12  553   * @pds:	PD service handle
fbe639b44a8275 Sibi Sankar           2020-03-12  554   *
fbe639b44a8275 Sibi Sankar           2020-03-12  555   * Restarts the PD tracked by the PDR client handle for a given service path.
fbe639b44a8275 Sibi Sankar           2020-03-12  556   *
fbe639b44a8275 Sibi Sankar           2020-03-12  557   * Return: 0 on success, negative errno on failure.
fbe639b44a8275 Sibi Sankar           2020-03-12  558   */
fbe639b44a8275 Sibi Sankar           2020-03-12  559  int pdr_restart_pd(struct pdr_handle *pdr, struct pdr_service *pds)
fbe639b44a8275 Sibi Sankar           2020-03-12  560  {
fbe639b44a8275 Sibi Sankar           2020-03-12  561  	struct servreg_restart_pd_resp resp;
a161ffe4b87772 Tom Rix               2020-08-19  562  	struct servreg_restart_pd_req req = { 0 };
fbe639b44a8275 Sibi Sankar           2020-03-12  563  	struct sockaddr_qrtr addr;
fbe639b44a8275 Sibi Sankar           2020-03-12  564  	struct pdr_service *tmp;
fbe639b44a8275 Sibi Sankar           2020-03-12  565  	struct qmi_txn txn;
fbe639b44a8275 Sibi Sankar           2020-03-12  566  	int ret;
fbe639b44a8275 Sibi Sankar           2020-03-12  567  
fbe639b44a8275 Sibi Sankar           2020-03-12  568  	if (IS_ERR_OR_NULL(pdr) || IS_ERR_OR_NULL(pds))
fbe639b44a8275 Sibi Sankar           2020-03-12  569  		return -EINVAL;
fbe639b44a8275 Sibi Sankar           2020-03-12  570  
fbe639b44a8275 Sibi Sankar           2020-03-12  571  	mutex_lock(&pdr->list_lock);
fbe639b44a8275 Sibi Sankar           2020-03-12  572  	list_for_each_entry(tmp, &pdr->lookups, node) {
fbe639b44a8275 Sibi Sankar           2020-03-12  573  		if (tmp != pds)
fbe639b44a8275 Sibi Sankar           2020-03-12  574  			continue;
fbe639b44a8275 Sibi Sankar           2020-03-12  575  
fbe639b44a8275 Sibi Sankar           2020-03-12  576  		if (!pds->service_connected)
fbe639b44a8275 Sibi Sankar           2020-03-12  577  			break;
fbe639b44a8275 Sibi Sankar           2020-03-12  578  
fbe639b44a8275 Sibi Sankar           2020-03-12  579  		/* Prepare req message */
26bc7a6a0beed8 Len Baker             2021-08-08  580  		strscpy(req.service_path, pds->service_path, sizeof(req.service_path));
fbe639b44a8275 Sibi Sankar           2020-03-12  581  		addr = pds->addr;
fbe639b44a8275 Sibi Sankar           2020-03-12  582  		break;
fbe639b44a8275 Sibi Sankar           2020-03-12  583  	}
fbe639b44a8275 Sibi Sankar           2020-03-12  584  	mutex_unlock(&pdr->list_lock);
fbe639b44a8275 Sibi Sankar           2020-03-12  585  
fbe639b44a8275 Sibi Sankar           2020-03-12  586  	if (!req.service_path[0])
fbe639b44a8275 Sibi Sankar           2020-03-12  587  		return -EINVAL;
fbe639b44a8275 Sibi Sankar           2020-03-12  588  
fbe639b44a8275 Sibi Sankar           2020-03-12  589  	ret = qmi_txn_init(&pdr->notifier_hdl, &txn,
fbe639b44a8275 Sibi Sankar           2020-03-12  590  			   servreg_restart_pd_resp_ei,
fbe639b44a8275 Sibi Sankar           2020-03-12  591  			   &resp);
fbe639b44a8275 Sibi Sankar           2020-03-12  592  	if (ret < 0)
fbe639b44a8275 Sibi Sankar           2020-03-12  593  		return ret;
fbe639b44a8275 Sibi Sankar           2020-03-12  594  
fbe639b44a8275 Sibi Sankar           2020-03-12  595  	ret = qmi_send_request(&pdr->notifier_hdl, &addr,
fbe639b44a8275 Sibi Sankar           2020-03-12  596  			       &txn, SERVREG_RESTART_PD_REQ,
fbe639b44a8275 Sibi Sankar           2020-03-12  597  			       SERVREG_RESTART_PD_REQ_MAX_LEN,
fbe639b44a8275 Sibi Sankar           2020-03-12  598  			       servreg_restart_pd_req_ei, &req);
fbe639b44a8275 Sibi Sankar           2020-03-12  599  	if (ret < 0) {
fbe639b44a8275 Sibi Sankar           2020-03-12  600  		qmi_txn_cancel(&txn);
fbe639b44a8275 Sibi Sankar           2020-03-12  601  		return ret;
fbe639b44a8275 Sibi Sankar           2020-03-12  602  	}
fbe639b44a8275 Sibi Sankar           2020-03-12  603  
fbe639b44a8275 Sibi Sankar           2020-03-12  604  	ret = qmi_txn_wait(&txn, 5 * HZ);
fbe639b44a8275 Sibi Sankar           2020-03-12  605  	if (ret < 0) {
fbe639b44a8275 Sibi Sankar           2020-03-12  606  		pr_err("PDR: %s PD restart txn wait failed: %d\n",
fbe639b44a8275 Sibi Sankar           2020-03-12  607  		       req.service_path, ret);
fbe639b44a8275 Sibi Sankar           2020-03-12  608  		return ret;
fbe639b44a8275 Sibi Sankar           2020-03-12  609  	}
fbe639b44a8275 Sibi Sankar           2020-03-12  610  
fbe639b44a8275 Sibi Sankar           2020-03-12  611  	/* Check response if PDR is disabled */
fbe639b44a8275 Sibi Sankar           2020-03-12 @612  	if (resp.resp.result == QMI_RESULT_FAILURE_V01 &&
fbe639b44a8275 Sibi Sankar           2020-03-12  613  	    resp.resp.error == QMI_ERR_DISABLED_V01) {
fbe639b44a8275 Sibi Sankar           2020-03-12  614  		pr_err("PDR: %s PD restart is disabled: 0x%x\n",
fbe639b44a8275 Sibi Sankar           2020-03-12  615  		       req.service_path, resp.resp.error);
fbe639b44a8275 Sibi Sankar           2020-03-12  616  		return -EOPNOTSUPP;
fbe639b44a8275 Sibi Sankar           2020-03-12  617  	}
fbe639b44a8275 Sibi Sankar           2020-03-12  618  
fbe639b44a8275 Sibi Sankar           2020-03-12  619  	/* Check the response for other error case*/
fbe639b44a8275 Sibi Sankar           2020-03-12  620  	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
fbe639b44a8275 Sibi Sankar           2020-03-12  621  		pr_err("PDR: %s request for PD restart failed: 0x%x\n",
fbe639b44a8275 Sibi Sankar           2020-03-12  622  		       req.service_path, resp.resp.error);
fbe639b44a8275 Sibi Sankar           2020-03-12  623  		return -EREMOTEIO;
fbe639b44a8275 Sibi Sankar           2020-03-12  624  	}
fbe639b44a8275 Sibi Sankar           2020-03-12  625  
fbe639b44a8275 Sibi Sankar           2020-03-12  626  	return 0;
fbe639b44a8275 Sibi Sankar           2020-03-12  627  }
9b09c0f289c5a8 Unnathi Chalicheemala 2023-09-22  628  EXPORT_SYMBOL_GPL(pdr_restart_pd);
fbe639b44a8275 Sibi Sankar           2020-03-12  629  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki