[v2] pinctrl: madera: Fix uninitialized variable bug in madera_mux_set_mux
diff mbox series

Message ID 20181010151313.GA16854@embeddedor.com
State New
Headers show
Series
  • [v2] pinctrl: madera: Fix uninitialized variable bug in madera_mux_set_mux
Related show

Commit Message

Gustavo A. R. Silva Oct. 10, 2018, 3: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 0 in order to
avoid unpredictable or unintended results.

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>
---
Changes in v2:
 - Initialize variable ret to 0 instead of -1. Thanks to Charles Keepax
   for pointing this out.
 - Update subject and commit log.

 drivers/pinctrl/cirrus/pinctrl-madera-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Linus Walleij Oct. 11, 2018, 8:40 a.m. UTC | #1
On Wed, Oct 10, 2018 at 5:13 PM Gustavo A. R. Silva
<gustavo@embeddedor.com> 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 0 in order to
> avoid unpredictable or unintended results.
>
> 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>
> ---
> Changes in v2:
>  - Initialize variable ret to 0 instead of -1. Thanks to Charles Keepax
>    for pointing this out.
>  - Update subject and commit log.

Patch applied with Charles' ACK.

Yours,
Linus Walleij
Gustavo A. R. Silva Oct. 12, 2018, 9:04 a.m. UTC | #2
On 10/11/18 10:40 AM, Linus Walleij wrote:

>> Changes in v2:
>>  - Initialize variable ret to 0 instead of -1. Thanks to Charles Keepax
>>    for pointing this out.
>>  - Update subject and commit log.
> 
> Patch applied with Charles' ACK.
> 

Thanks, Linus.
--
Gustavo

Patch
diff mbox series

diff --git a/drivers/pinctrl/cirrus/pinctrl-madera-core.c b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
index 0266302..a5dda83 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 = 0;
 
 	dev_dbg(priv->dev, "%s selecting %u (%s) for group %u (%s)\n",
 		__func__, selector, func_name, group,