Skip to contentSkip to conversation

usb: typec: tcpm: qcom: initialize currsrc explicitly

PATCH In review Alexey V. Vissarionov 5 participants 5 messages Jul 13 – Jul 14

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

PATCH 1/1 usb: typec: tcpm: qcom: initialize currsrc explicitly

When regmap_read() fails, the execution goes to done: label, where currsrc is passed to rp_sel_to_name() and used as an index after a proper check. However, to make this situation easier to notice, an explicit initialization of currsrc with obviously impossible value is suggested. Alas, we can't simply use zero value here because it means TYPEC_SRC_RP_SEL_80UA.

Found by ALT Linux Team (altlinux.org) and Linux Verification Center (linuxtesting.org) using SVACE.

---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +2 -2
index bf985efe1cd6bea4..d7cb69cf6044841b 100644
@@ -461,8 +461,8 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
 	struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc);
 	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
 	struct device *dev = pmic_typec_port->dev;
-	unsigned int mode, currsrc;
-	unsigned int misc;
+	unsigned int currsrc = 0xFF; /* error, easy to notice in the log */
+	unsigned int mode, misc;
 	unsigned long flags;
 	int ret;
 
Signature · 3 lines
Alexey V. Vissarionov
gremlin ПРИ altlinux ТЧК org; +vii-cmiii-ccxxix-lxxix-xlii
GPG: 0D92F19E1C0DC36E27F61A29CD17E2B43D879005 @ hkp://keys.gnupg.net
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Alexey V. Vissarionov

When regmap_read() fails, the execution goes to done: label, where currsrc is passed to rp_sel_to_name() and used as an index after a proper check. However, to make this situation easier to notice, an explicit initialization of currsrc with obviously impossible value is suggested. Alas, we can't simply use zero value here because it means TYPEC_SRC_RP_SEL_80UA.

Found by ALT Linux Team (altlinux.org) and Linux Verification Center (linuxtesting.org) using SVACE.

---
  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +2 -3
index bf985efe1cd6bea4..d7cb69cf6044841b 100644
@@ -461,8 +461,8 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
  	struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc);
  	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
  	struct device *dev = pmic_typec_port->dev;
-	unsigned int mode, currsrc;
-	unsigned int misc;
+	unsigned int currsrc = 0xFF; /* error, easy to notice in the log */
+	unsigned int mode, misc;
  	unsigned long flags;
  	int ret;
 
 
 
--
Quoted 4 lines

Alexey V. Vissarionov
gremlin ПРИ altlinux ТЧК org; +vii-cmiii-ccxxix-lxxix-xlii
GPG: 0D92F19E1C0DC36E27F61A29CD17E2B43D879005 @ hkp://keys.gnupg.net

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Alexey V. Vissarionov
Quoted 11 lines · Alexey V. Vissarionov

When regmap_read() fails, the execution goes to done: label, where currsrc is passed to rp_sel_to_name() and used as an index after a proper check. However, to make this situation easier to notice, an explicit initialization of currsrc with obviously impossible value is suggested. Alas, we can't simply use zero value here because it means TYPEC_SRC_RP_SEL_80UA.

Found by ALT Linux Team (altlinux.org) and Linux Verification Center (linuxtesting.org) using SVACE.

Quoted 25 lines
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +2 -2
index bf985efe1cd6bea4..d7cb69cf6044841b 100644
@@ -461,8 +461,8 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
 	struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc);
 	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
 	struct device *dev = pmic_typec_port->dev;
-	unsigned int mode, currsrc;
-	unsigned int misc;
+	unsigned int currsrc = 0xFF; /* error, easy to notice in the log */
+	unsigned int mode, misc;
 	unsigned long flags;
 	int ret;
 
Signature · 4 lines
-- 
Alexey V. Vissarionov
gremlin ПРИ altlinux ТЧК org; +vii-cmiii-ccxxix-lxxix-xlii
GPG: 0D92F19E1C0DC36E27F61A29CD17E2B43D879005 @ hkp://keys.gnupg.net
Signature · 1 line
heikki
#3 lore raw
In reply to Alexey V. Vissarionov
Quoted 20 lines · Alexey V. Vissarionov

When regmap_read() fails, the execution goes to done: label, where currsrc is passed to rp_sel_to_name() and used as an index after a proper check. However, to make this situation easier to notice, an explicit initialization of currsrc with obviously impossible value is suggested. Alas, we can't simply use zero value here because it means TYPEC_SRC_RP_SEL_80UA.

Found by ALT Linux Team (altlinux.org) and Linux Verification Center (linuxtesting.org) using SVACE.

---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +0 -0
index bf985efe1cd6bea4..d7cb69cf6044841b 100644

drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc, · line 467

Quoted 9 lines
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +2 -2
@@ -461,8 +461,8 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
 	struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc);
 	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
 	struct device *dev = pmic_typec_port->dev;
-	unsigned int mode, currsrc;
-	unsigned int misc;
+	unsigned int currsrc = 0xFF; /* error, easy to notice in the log */
+	unsigned int mode, misc;
 	unsigned long flags;
 	int ret;

'mode' and 'misc' should be initialized as well. Though this all was already covered with the patch [1], which got the review two weeks ago. Note that it did initialize currsrc with zero value instead of 0xFF.

It's confusing a bit. Maybe [1] should be respinned now with currsrc = 0xFF or whatever?

+Cc Vasiliy

[1]: https://lore.kernel.org/all/[email protected]/