Skip to contentSkip to conversation

soc: qcom: qmi_interface: Limit txn ids to U16_MAX

PATCH In review Arun Kumar Neelakantam 3 participants 3 messages Oct 3, 2018 – Nov 14, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: qcom: qmi_interface: Limit txn ids to U16_MAX

Txn IDs created up to INT_MAX cause overflow while storing the IDs in u16 type supported by QMI header.

Limit the txn IDs max value to U16_MAX to avoid overflow.

---
 drivers/soc/qcom/qmi_interface.c | 2 +-
 include/linux/soc/qcom/qmi.h     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/soc/qcom/qmi_interface.c +1 -1
index 938ca41c..c239a28 100644
@@ -318,7 +318,7 @@ int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn,
 	txn->dest = c_struct;
 
 	mutex_lock(&qmi->txn_lock);
-	ret = idr_alloc_cyclic(&qmi->txns, txn, 0, INT_MAX, GFP_KERNEL);
+	ret = idr_alloc_cyclic(&qmi->txns, txn, 0, U16_MAX, GFP_KERNEL);
 	if (ret < 0)
 		pr_err("failed to allocate transaction id\n");
 
include/linux/soc/qcom/qmi.h +1 -1
index f4de336..5efa2b6 100644
@@ -166,7 +166,7 @@ struct qmi_ops {
 struct qmi_txn {
 	struct qmi_handle *qmi;
 
-	int id;
+	u16 id;
 
 	struct mutex lock;
 	struct completion completion;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Arun Kumar Neelakantam

Txn IDs created up to INT_MAX cause overflow while storing the IDs in u16 type supported by QMI header.

Limit the txn IDs max value to U16_MAX to avoid overflow.

Regards,
Bjorn

Quoted 35 lines
---
 drivers/soc/qcom/qmi_interface.c | 2 +-
 include/linux/soc/qcom/qmi.h     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/soc/qcom/qmi_interface.c +1 -1
index 938ca41c..c239a28 100644
@@ -318,7 +318,7 @@ int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn,
 	txn->dest = c_struct;
 
 	mutex_lock(&qmi->txn_lock);
-	ret = idr_alloc_cyclic(&qmi->txns, txn, 0, INT_MAX, GFP_KERNEL);
+	ret = idr_alloc_cyclic(&qmi->txns, txn, 0, U16_MAX, GFP_KERNEL);
 	if (ret < 0)
 		pr_err("failed to allocate transaction id\n");
 
include/linux/soc/qcom/qmi.h +1 -1
index f4de336..5efa2b6 100644
@@ -166,7 +166,7 @@ struct qmi_ops {
 struct qmi_txn {
 	struct qmi_handle *qmi;
 
-	int id;
+	u16 id;
 
 	struct mutex lock;
 	struct completion completion;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project