diff mbox series

usb: typec: Fix unchecked return value

Message ID 20190318211830.GA29785@embeddedor (mailing list archive)
State Mainlined
Commit e82adc1074a7356f1158233551df9e86b7ebfb82
Headers show
Series usb: typec: Fix unchecked return value | expand

Commit Message

Gustavo A. R. Silva March 18, 2019, 9:18 p.m. UTC
Currently there is no check on platform_get_irq() return value
in case it fails, hence never actually reporting any errors and
causing unexpected behavior when using such value as argument
for function regmap_irq_get_virq().

Fix this by adding a proper check, a message error and return
*irq* in case platform_get_irq() fails.

Addresses-Coverity-ID: 1443899 ("Improper use of negative value")
Fixes: d2061f9cc32d ("usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/usb/typec/tcpm/wcove.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Guenter Roeck March 18, 2019, 10:37 p.m. UTC | #1
On Mon, Mar 18, 2019 at 04:18:30PM -0500, Gustavo A. R. Silva wrote:
> Currently there is no check on platform_get_irq() return value
> in case it fails, hence never actually reporting any errors and
> causing unexpected behavior when using such value as argument
> for function regmap_irq_get_virq().
> 
> Fix this by adding a proper check, a message error and return
> *irq* in case platform_get_irq() fails.
> 
> Addresses-Coverity-ID: 1443899 ("Improper use of negative value")
> Fixes: d2061f9cc32d ("usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/usb/typec/tcpm/wcove.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/wcove.c b/drivers/usb/typec/tcpm/wcove.c
> index 423208e19383..6770afd40765 100644
> --- a/drivers/usb/typec/tcpm/wcove.c
> +++ b/drivers/usb/typec/tcpm/wcove.c
> @@ -615,8 +615,13 @@ static int wcove_typec_probe(struct platform_device *pdev)
>  	wcove->dev = &pdev->dev;
>  	wcove->regmap = pmic->regmap;
>  
> -	irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr,
> -				  platform_get_irq(pdev, 0));
> +	irq = platform_get_irq(pdev, 0);
> +	if (irq < 0) {
> +		dev_err(&pdev->dev, "Failed to get IRQ: %d\n", irq);
> +		return irq;
> +	}
> +
> +	irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr, irq);
>  	if (irq < 0)
>  		return irq;
>  
> -- 
> 2.21.0
>
Heikki Krogerus March 19, 2019, 11:13 a.m. UTC | #2
On Mon, Mar 18, 2019 at 04:18:30PM -0500, Gustavo A. R. Silva wrote:
> Currently there is no check on platform_get_irq() return value
> in case it fails, hence never actually reporting any errors and
> causing unexpected behavior when using such value as argument
> for function regmap_irq_get_virq().
> 
> Fix this by adding a proper check, a message error and return
> *irq* in case platform_get_irq() fails.
> 
> Addresses-Coverity-ID: 1443899 ("Improper use of negative value")
> Fixes: d2061f9cc32d ("usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/tcpm/wcove.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/wcove.c b/drivers/usb/typec/tcpm/wcove.c
> index 423208e19383..6770afd40765 100644
> --- a/drivers/usb/typec/tcpm/wcove.c
> +++ b/drivers/usb/typec/tcpm/wcove.c
> @@ -615,8 +615,13 @@ static int wcove_typec_probe(struct platform_device *pdev)
>  	wcove->dev = &pdev->dev;
>  	wcove->regmap = pmic->regmap;
>  
> -	irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr,
> -				  platform_get_irq(pdev, 0));
> +	irq = platform_get_irq(pdev, 0);
> +	if (irq < 0) {
> +		dev_err(&pdev->dev, "Failed to get IRQ: %d\n", irq);
> +		return irq;
> +	}
> +
> +	irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr, irq);
>  	if (irq < 0)
>  		return irq;
>  
> -- 
> 2.21.0

thanks,
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm/wcove.c b/drivers/usb/typec/tcpm/wcove.c
index 423208e19383..6770afd40765 100644
--- a/drivers/usb/typec/tcpm/wcove.c
+++ b/drivers/usb/typec/tcpm/wcove.c
@@ -615,8 +615,13 @@  static int wcove_typec_probe(struct platform_device *pdev)
 	wcove->dev = &pdev->dev;
 	wcove->regmap = pmic->regmap;
 
-	irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr,
-				  platform_get_irq(pdev, 0));
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "Failed to get IRQ: %d\n", irq);
+		return irq;
+	}
+
+	irq = regmap_irq_get_virq(pmic->irq_chip_data_chgr, irq);
 	if (irq < 0)
 		return irq;