Skip to contentSkip to conversation

PHY: Variable "val" in function pistachio_usb_phy_power_on() could be uninitialized

PATCH New Yizhuo 1 participant 1 message Feb 5, 2019 Generic PHY framework

lore
Share & tools
lore

Yizhuo

author
#0 lore raw

PATCH 1/1 PHY: Variable "val" in function pistachio_usb_phy_power_on() could be uninitialized

In function pistachio_usb_phy_power_on(), local variable "val" could be uninitialized if function regmap_read() returns -EINVAL. However, it will be used directly in the if statement, which is potentially unsafe.

---
 drivers/phy/phy-pistachio-usb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/phy/phy-pistachio-usb.c +6 -2
index c6db35e6bb63..ae9b6df1667d 100644
@@ -95,9 +95,13 @@ static int pistachio_usb_phy_power_on(struct phy *phy)
 
 	timeout = jiffies + msecs_to_jiffies(200);
 	while (time_before(jiffies, timeout)) {
-		unsigned int val;
+		unsigned int val = 0;
 
-		regmap_read(p_phy->cr_top, USB_PHY_STATUS, &val);
+		ret = regmap_read(p_phy->cr_top, USB_PHY_STATUS, &val);
+		if (ret) {
+			dev_err(p_phy->dev, "Failed to read USB_PHY_STATUS.\n");
+			goto disable_clk;
+		}
 		if (val & USB_PHY_STATUS_VBUS_FAULT) {
 			dev_err(p_phy->dev, "VBUS fault detected\n");
 			ret = -EIO;
Signature · 1 line
2.17.1