[1/2] pinctrl: mediatek: mt7622: fix potential uninitialized value being returned

Message ID a26c40a8ad2af3cf81b31ae34bc82c1ef80d9279.1515514758.git.sean.wang@mediatek.com
State New
Headers show
Series
  • [1/2] pinctrl: mediatek: mt7622: fix potential uninitialized value being returned
Related show

Commit Message

Sean Wang Jan. 9, 2018, 4:28 p.m.
From: Sean Wang <sean.wang@mediatek.com>

commit d6ed93551320 ("pinctrl: mediatek: add pinctrl driver for MT7622
SoC") leads to the following static checker warning:

drivers/pinctrl/mediatek/pinctrl-mt7622.c:1419 mtk_gpio_get()
error: uninitialized symbol 'value'.
1412  static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
1413  {
1414          struct mtk_pinctrl *hw = dev_get_drvdata(chip->parent);
1415          int value;
1416
1417          mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
^^^^^^^^^^^^^^^^
1418
1419          return !!value;
1420  }

The appropriate error handling must be added to avoid the potential error
caused by uninitialized value being returned.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/pinctrl/mediatek/pinctrl-mt7622.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Matthias Brugger Jan. 10, 2018, 9 a.m. | #1
On 01/09/2018 05:28 PM, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> commit d6ed93551320 ("pinctrl: mediatek: add pinctrl driver for MT7622
> SoC") leads to the following static checker warning:
> 
> drivers/pinctrl/mediatek/pinctrl-mt7622.c:1419 mtk_gpio_get()
> error: uninitialized symbol 'value'.
> 1412  static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
> 1413  {
> 1414          struct mtk_pinctrl *hw = dev_get_drvdata(chip->parent);
> 1415          int value;
> 1416
> 1417          mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
> ^^^^^^^^^^^^^^^^
> 1418
> 1419          return !!value;
> 1420  }
> 
> The appropriate error handling must be added to avoid the potential error
> caused by uninitialized value being returned.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/pinctrl/mediatek/pinctrl-mt7622.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> diff --git a/drivers/pinctrl/mediatek/pinctrl-mt7622.c b/drivers/pinctrl/mediatek/pinctrl-mt7622.c
> index 3824d82..dc32e3c 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mt7622.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mt7622.c
> @@ -1412,9 +1412,11 @@ static struct pinctrl_desc mtk_desc = {
>  static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
>  {
>  	struct mtk_pinctrl *hw = dev_get_drvdata(chip->parent);
> -	int value;
> +	int value, err;
>  
> -	mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
> +	err = mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
> +	if (err)
> +		return err;
>  
>  	return !!value;
>  }
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Jan. 11, 2018, 9:42 a.m. | #2
On Tue, Jan 9, 2018 at 5:28 PM,  <sean.wang@mediatek.com> wrote:

> From: Sean Wang <sean.wang@mediatek.com>
>
> commit d6ed93551320 ("pinctrl: mediatek: add pinctrl driver for MT7622
> SoC") leads to the following static checker warning:

Patch applied.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/pinctrl/mediatek/pinctrl-mt7622.c b/drivers/pinctrl/mediatek/pinctrl-mt7622.c
index 3824d82..dc32e3c 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mt7622.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mt7622.c
@@ -1412,9 +1412,11 @@  static struct pinctrl_desc mtk_desc = {
 static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 {
 	struct mtk_pinctrl *hw = dev_get_drvdata(chip->parent);
-	int value;
+	int value, err;
 
-	mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
+	err = mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
+	if (err)
+		return err;
 
 	return !!value;
 }