power: supply: Added check for negative values

Message ID 20221206091723.28656-1-arefev@swemel.ru
State New
Headers
Series power: supply: Added check for negative values |

Commit Message

Denis Arefev Dec. 6, 2022, 9:17 a.m. UTC
  Variable 'pirq', which may receive negative value
in platform_get_irq().
Used as an index in a function regmap_irq_get_virq().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 drivers/power/supply/axp288_fuel_gauge.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Hans de Goede Dec. 6, 2022, 5:11 p.m. UTC | #1
Hi,

On 12/6/22 10:17, Denis Arefev wrote:
> Variable 'pirq', which may receive negative value
> in platform_get_irq().
> Used as an index in a function regmap_irq_get_virq().
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Denis Arefev <arefev@swemel.ru>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>  drivers/power/supply/axp288_fuel_gauge.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/power/supply/axp288_fuel_gauge.c b/drivers/power/supply/axp288_fuel_gauge.c
> index 148eb8105803..36c7039c99c2 100644
> --- a/drivers/power/supply/axp288_fuel_gauge.c
> +++ b/drivers/power/supply/axp288_fuel_gauge.c
> @@ -640,6 +640,8 @@ static void fuel_gauge_init_irq(struct axp288_fg_info *info)
>  
>  	for (i = 0; i < AXP288_FG_INTR_NUM; i++) {
>  		pirq = platform_get_irq(info->pdev, i);
> +		if (pirq < 0)
> +			continue;
>  		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
>  		if (info->irq[i] < 0) {
>  			dev_warn(&info->pdev->dev,
  
Sebastian Reichel Jan. 2, 2023, 10:19 p.m. UTC | #2
Hi,

On Tue, Dec 06, 2022 at 06:11:23PM +0100, Hans de Goede wrote:
> Hi,
> 
> On 12/6/22 10:17, Denis Arefev wrote:
> > Variable 'pirq', which may receive negative value
> > in platform_get_irq().
> > Used as an index in a function regmap_irq_get_virq().
> > 
> > Found by Linux Verification Center (linuxtesting.org) with SVACE.
> > 
> > Signed-off-by: Denis Arefev <arefev@swemel.ru>
> 
> Thanks, patch looks good to me:
> 
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> 
> Regards,
> 
> Hans

Thanks, queued to power-supply's fixes branch.

-- Sebastian

> 
> > ---
> >  drivers/power/supply/axp288_fuel_gauge.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/power/supply/axp288_fuel_gauge.c b/drivers/power/supply/axp288_fuel_gauge.c
> > index 148eb8105803..36c7039c99c2 100644
> > --- a/drivers/power/supply/axp288_fuel_gauge.c
> > +++ b/drivers/power/supply/axp288_fuel_gauge.c
> > @@ -640,6 +640,8 @@ static void fuel_gauge_init_irq(struct axp288_fg_info *info)
> >  
> >  	for (i = 0; i < AXP288_FG_INTR_NUM; i++) {
> >  		pirq = platform_get_irq(info->pdev, i);
> > +		if (pirq < 0)
> > +			continue;
> >  		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
> >  		if (info->irq[i] < 0) {
> >  			dev_warn(&info->pdev->dev,
>
  

Patch

diff --git a/drivers/power/supply/axp288_fuel_gauge.c b/drivers/power/supply/axp288_fuel_gauge.c
index 148eb8105803..36c7039c99c2 100644
--- a/drivers/power/supply/axp288_fuel_gauge.c
+++ b/drivers/power/supply/axp288_fuel_gauge.c
@@ -640,6 +640,8 @@  static void fuel_gauge_init_irq(struct axp288_fg_info *info)
 
 	for (i = 0; i < AXP288_FG_INTR_NUM; i++) {
 		pirq = platform_get_irq(info->pdev, i);
+		if (pirq < 0)
+			continue;
 		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
 		if (info->irq[i] < 0) {
 			dev_warn(&info->pdev->dev,