diff mbox series

usb: dwc3: xilinx: fix uninitialized return value

Message ID 20220127221500.177021-1-robert.hancock@calian.com
State Superseded
Headers show
Series usb: dwc3: xilinx: fix uninitialized return value | expand

Commit Message

Robert Hancock Jan. 27, 2022, 10:15 p.m. UTC
A previous patch to skip part of the initialization when a USB3 PHY was
not present could result in the return value being uninitialized in that
case, causing spurious probe failures. Initialize ret to 0 to avoid this.

Fixes: 9678f3361afc ("usb: dwc3: xilinx: Skip resets and USB3 register settings for USB2.0 mode")
Cc: <stable@vger.kernel.org>
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
---
 drivers/usb/dwc3/dwc3-xilinx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nathan Chancellor Jan. 29, 2022, 8:55 p.m. UTC | #1
On Thu, Jan 27, 2022 at 04:15:00PM -0600, Robert Hancock wrote:
> A previous patch to skip part of the initialization when a USB3 PHY was
> not present could result in the return value being uninitialized in that
> case, causing spurious probe failures. Initialize ret to 0 to avoid this.
> 
> Fixes: 9678f3361afc ("usb: dwc3: xilinx: Skip resets and USB3 register settings for USB2.0 mode")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Robert Hancock <robert.hancock@calian.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

This resolves a clang warning that is now in mainline:

$ make -sj"$(nproc)" ARCH=arm64 LLVM=1 allmodconfig drivers/usb/dwc3/dwc3-xilinx.o
drivers/usb/dwc3/dwc3-xilinx.c:122:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
        if (!usb3_phy)
            ^~~~~~~~~
drivers/usb/dwc3/dwc3-xilinx.c:216:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/usb/dwc3/dwc3-xilinx.c:122:2: note: remove the 'if' if its condition is always false
        if (!usb3_phy)
        ^~~~~~~~~~~~~~
drivers/usb/dwc3/dwc3-xilinx.c:102:11: note: initialize the variable 'ret' to silence this warning
        int                     ret;
                                   ^
                                    = 0
1 error generated.

It might be worth moving the initialization into the if statement

    if (!usb3_phy) {
        ret = 0;
        goto skip_usb3_phy;
    }

as that will avoid hiding warnings of this nature if someone forgets to
set ret on an error path but that is ultimately up to the maintainer.

> ---
>  drivers/usb/dwc3/dwc3-xilinx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c
> index e14ac15e24c3..a6f3a9b38789 100644
> --- a/drivers/usb/dwc3/dwc3-xilinx.c
> +++ b/drivers/usb/dwc3/dwc3-xilinx.c
> @@ -99,7 +99,7 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
>  	struct device		*dev = priv_data->dev;
>  	struct reset_control	*crst, *hibrst, *apbrst;
>  	struct phy		*usb3_phy;
> -	int			ret;
> +	int			ret = 0;
>  	u32			reg;
>  
>  	usb3_phy = devm_phy_optional_get(dev, "usb3-phy");
> -- 
> 2.31.1
> 
>
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c
index e14ac15e24c3..a6f3a9b38789 100644
--- a/drivers/usb/dwc3/dwc3-xilinx.c
+++ b/drivers/usb/dwc3/dwc3-xilinx.c
@@ -99,7 +99,7 @@  static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data)
 	struct device		*dev = priv_data->dev;
 	struct reset_control	*crst, *hibrst, *apbrst;
 	struct phy		*usb3_phy;
-	int			ret;
+	int			ret = 0;
 	u32			reg;
 
 	usb3_phy = devm_phy_optional_get(dev, "usb3-phy");