Skip to contentSkip to conversation

usb: typec: qcom-pmic-typec: avoid uninit values in dev_dbg() error paths

PATCH Superseded Vasiliy Kovalev 3 participants 3 messages Jun 30 – Jul 3

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: typec: qcom-pmic-typec: avoid uninit values in dev_dbg() error paths

Several functions take a 'goto done' shortcut on regmap_read() (or switch default) failure before assigning locals that the trailing dev_dbg() then formats.

Initialize the affected locals at declaration.

Found by Linux Verification Center (linuxtesting.org) with Svace static analysis tool.

Fixes a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +5 -4
index bf985efe1cd6..c8379cdcb6da 100644
@@ -366,7 +366,7 @@ static int qcom_pmic_typec_port_get_cc(struct tcpc_dev *tcpc,
 	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
 	struct device *dev = pmic_typec_port->dev;
 	unsigned int misc, val;
-	bool attached;
+	bool attached = false;
 	int ret = 0;
 
 	ret = regmap_read(pmic_typec_port->regmap,
@@ -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 mode = 0, currsrc = 0;
+	unsigned int misc = 0;
 	unsigned long flags;
 	int ret;
 
@@ -535,7 +535,8 @@ static int qcom_pmic_typec_port_set_vconn(struct tcpc_dev *tcpc, bool on)
 	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 orientation, misc, mask, value;
+	unsigned int orientation = 0, misc = 0, value = 0;
+	unsigned int mask;
 	unsigned long flags;
 	int ret;
 
Signature · 1 line
2.50.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 41 lines · Vasiliy Kovalev

Several functions take a 'goto done' shortcut on regmap_read() (or switch default) failure before assigning locals that the trailing dev_dbg() then formats.

Initialize the affected locals at declaration.

Found by Linux Verification Center (linuxtesting.org) with Svace static analysis tool.

Fixes a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
---
  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +3 -3
index bf985efe1cd6..c8379cdcb6da 100644
@@ -366,7 +366,7 @@ static int qcom_pmic_typec_port_get_cc(struct tcpc_dev *tcpc,
  	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
  	struct device *dev = pmic_typec_port->dev;
  	unsigned int misc, val;
-	bool attached;
+	bool attached = false;
  	int ret = 0;
 
  	ret = regmap_read(pmic_typec_port->regmap,
@@ -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 mode = 0, currsrc = 0;
+	unsigned int misc = 0;
  	unsigned long flags;
  	int ret;
 

drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c static int qcom_pmic_typec_port_set_vconn(struct tcpc_dev *tcpc, bool on) · line 542

Quoted 9 lines
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +2 -1
@@ -535,7 +535,8 @@ static int qcom_pmic_typec_port_set_vconn(struct tcpc_dev *tcpc, bool on)
  	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 orientation, misc, mask, value;
+	unsigned int orientation = 0, misc = 0, value = 0;
+	unsigned int mask;
  	unsigned long flags;
  	int ret;
 

---
bod

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Vasiliy Kovalev
Quoted 4 lines · Vasiliy Kovalev

Several functions take a 'goto done' shortcut on regmap_read() (or switch default) failure before assigning locals that the trailing dev_dbg() then formats.

Quoted 8 lines

Initialize the affected locals at declaration.

Found by Linux Verification Center (linuxtesting.org) with Svace static analysis tool.

Fixes a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Quoted 40 lines
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +5 -4
index bf985efe1cd6..c8379cdcb6da 100644
@@ -366,7 +366,7 @@ static int qcom_pmic_typec_port_get_cc(struct tcpc_dev *tcpc,
 	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
 	struct device *dev = pmic_typec_port->dev;
 	unsigned int misc, val;
-	bool attached;
+	bool attached = false;
 	int ret = 0;
 
 	ret = regmap_read(pmic_typec_port->regmap,
@@ -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 mode = 0, currsrc = 0;
+	unsigned int misc = 0;
 	unsigned long flags;
 	int ret;
 
@@ -535,7 +535,8 @@ static int qcom_pmic_typec_port_set_vconn(struct tcpc_dev *tcpc, bool on)
 	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 orientation, misc, mask, value;
+	unsigned int orientation = 0, misc = 0, value = 0;
+	unsigned int mask;
 	unsigned long flags;
 	int ret;
 
Signature · 1 line
2.50.1
Signature · 1 line
heikki