diff mbox series

pinctrl: madera: Fix uninitialized variable issue in madera_mux_set_mux

Message ID 20181010141353.GA14382@embeddedor.com (mailing list archive)
State New, archived
Headers show
Series pinctrl: madera: Fix uninitialized variable issue in madera_mux_set_mux | expand

Commit Message

Gustavo A. R. Silva Oct. 10, 2018, 2:13 p.m. UTC
There is a potential execution path in which variable *ret* is checked
in an IF statement, and then its value is used to report an error at
line 659 without being properly initialized previously:

659 if (ret)
660	dev_err(priv->dev, "Failed to write to 0x%x (%d)\n", reg, ret);

Fix this by initializing variable *ret* to -1.

Addresses-Coverity-ID: 1471969 ("Uninitialized scalar variable")
Fixes: 218d72a77b0b ("pinctrl: madera: Add driver for Cirrus Logic Madera codecs")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/pinctrl/cirrus/pinctrl-madera-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Charles Keepax Oct. 10, 2018, 2:33 p.m. UTC | #1
On Wed, Oct 10, 2018 at 04:13:53PM +0200, Gustavo A. R. Silva wrote:
> There is a potential execution path in which variable *ret* is checked
> in an IF statement, and then its value is used to report an error at
> line 659 without being properly initialized previously:
> 
> 659 if (ret)
> 660	dev_err(priv->dev, "Failed to write to 0x%x (%d)\n", reg, ret);
> 
> Fix this by initializing variable *ret* to -1.
> 
> Addresses-Coverity-ID: 1471969 ("Uninitialized scalar variable")
> Fixes: 218d72a77b0b ("pinctrl: madera: Add driver for Cirrus Logic Madera codecs")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/pinctrl/cirrus/pinctrl-madera-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/cirrus/pinctrl-madera-core.c b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
> index 0266302..a99ace8 100644
> --- a/drivers/pinctrl/cirrus/pinctrl-madera-core.c
> +++ b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
> @@ -608,7 +608,7 @@ static int madera_mux_set_mux(struct pinctrl_dev *pctldev,
>  	unsigned int n_chip_groups = priv->chip->n_pin_groups;
>  	const char *func_name = madera_mux_funcs[selector].name;
>  	unsigned int reg;
> -	int i, ret;
> +	int i, ret = -1;
>  

I don't believe this would fully address the issue since if you
initialise ret to -1 you will still drop into the if statement
and you will use the reg variable which should also be
uninitialised on that code path.

Feels like initialising to 0 would probably be better anyway
since the code path looks like the case were you have n_pins == 0
and nothing really failed in that case just nothing needed to be
done.

Thanks,
Charles

>  	dev_dbg(priv->dev, "%s selecting %u (%s) for group %u (%s)\n",
>  		__func__, selector, func_name, group,
> -- 
> 2.7.4
Gustavo A. R. Silva Oct. 10, 2018, 2:58 p.m. UTC | #2
Hi Charles,

> I don't believe this would fully address the issue since if you
> initialise ret to -1 you will still drop into the if statement
> and you will use the reg variable which should also be
> uninitialised on that code path.
> 
> Feels like initialising to 0 would probably be better anyway
> since the code path looks like the case were you have n_pins == 0
> and nothing really failed in that case just nothing needed to be
> done.
> 

You're right. I got confused with another similar issue I fixed, recently.

I'll send v2 shortly.

Thanks for the feedback.
--
Gustavo
diff mbox series

Patch

diff --git a/drivers/pinctrl/cirrus/pinctrl-madera-core.c b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
index 0266302..a99ace8 100644
--- a/drivers/pinctrl/cirrus/pinctrl-madera-core.c
+++ b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
@@ -608,7 +608,7 @@  static int madera_mux_set_mux(struct pinctrl_dev *pctldev,
 	unsigned int n_chip_groups = priv->chip->n_pin_groups;
 	const char *func_name = madera_mux_funcs[selector].name;
 	unsigned int reg;
-	int i, ret;
+	int i, ret = -1;
 
 	dev_dbg(priv->dev, "%s selecting %u (%s) for group %u (%s)\n",
 		__func__, selector, func_name, group,