diff mbox series

[v2] gpio: sifive: Add missing check for platform_get_irq

Message ID 20230602072755.7314-1-jiasheng@iscas.ac.cn (mailing list archive)
State Superseded
Headers show
Series [v2] gpio: sifive: Add missing check for platform_get_irq | expand

Checks

Context Check Description
conchuod/cover_letter success Single patches do not need cover letters
conchuod/tree_selection success Guessed tree name to be for-next at HEAD ac9a78681b92
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 6 and now 6
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 14 this patch: 14
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 28 this patch: 28
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Jiasheng Jiang June 2, 2023, 7:27 a.m. UTC
Add the missing check for platform_get_irq and return error code
if it fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:

v1 -> v2:

1. Return "chip->irq_number[i]" instead of "-ENODEV".
---
 drivers/gpio/gpio-sifive.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko June 2, 2023, 1:03 p.m. UTC | #1
On Fri, Jun 2, 2023 at 10:28 AM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> Add the missing check for platform_get_irq and return error code
> if it fails.

The template for function references is func().
Otherwise looks fine to me
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> Changelog:
>
> v1 -> v2:
>
> 1. Return "chip->irq_number[i]" instead of "-ENODEV".
> ---
>  drivers/gpio/gpio-sifive.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
> index 98939cd4a71e..7245000fb049 100644
> --- a/drivers/gpio/gpio-sifive.c
> +++ b/drivers/gpio/gpio-sifive.c
> @@ -221,8 +221,11 @@ static int sifive_gpio_probe(struct platform_device *pdev)
>                 return -ENODEV;
>         }
>
> -       for (i = 0; i < ngpio; i++)
> +       for (i = 0; i < ngpio; i++) {
>                 chip->irq_number[i] = platform_get_irq(pdev, i);
> +               if (chip->irq_number[i] < 0)
> +                       return chip->irq_number[i];
> +       }
>
>         ret = bgpio_init(&chip->gc, dev, 4,
>                          chip->base + SIFIVE_GPIO_INPUT_VAL,
> --
> 2.25.1
>


--
With Best Regards,
Andy Shevchenko
kernel test robot June 3, 2023, 5:47 p.m. UTC | #2
Hi Jiasheng,

kernel test robot noticed the following build warnings:

[auto build test WARNING on brgl/gpio/for-next]
[also build test WARNING on linus/master v6.4-rc4 next-20230602]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jiasheng-Jiang/gpio-sifive-Add-missing-check-for-platform_get_irq/20230602-152856
base:   https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next
patch link:    https://lore.kernel.org/r/20230602072755.7314-1-jiasheng%40iscas.ac.cn
patch subject: [PATCH v2] gpio: sifive: Add missing check for platform_get_irq
config: openrisc-randconfig-m041-20230531 (https://download.01.org/0day-ci/archive/20230604/202306040153.RPAlkz3U-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 12.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306040153.RPAlkz3U-lkp@intel.com/

smatch warnings:
drivers/gpio/gpio-sifive.c:226 sifive_gpio_probe() warn: unsigned 'chip->irq_number[i]' is never less than zero.

vim +226 drivers/gpio/gpio-sifive.c

   179	
   180	static int sifive_gpio_probe(struct platform_device *pdev)
   181	{
   182		struct device *dev = &pdev->dev;
   183		struct device_node *node = pdev->dev.of_node;
   184		struct device_node *irq_parent;
   185		struct irq_domain *parent;
   186		struct gpio_irq_chip *girq;
   187		struct sifive_gpio *chip;
   188		int ret, ngpio, i;
   189	
   190		chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
   191		if (!chip)
   192			return -ENOMEM;
   193	
   194		chip->base = devm_platform_ioremap_resource(pdev, 0);
   195		if (IS_ERR(chip->base)) {
   196			dev_err(dev, "failed to allocate device memory\n");
   197			return PTR_ERR(chip->base);
   198		}
   199	
   200		chip->regs = devm_regmap_init_mmio(dev, chip->base,
   201						   &sifive_gpio_regmap_config);
   202		if (IS_ERR(chip->regs))
   203			return PTR_ERR(chip->regs);
   204	
   205		ngpio = of_irq_count(node);
   206		if (ngpio > SIFIVE_GPIO_MAX) {
   207			dev_err(dev, "Too many GPIO interrupts (max=%d)\n",
   208				SIFIVE_GPIO_MAX);
   209			return -ENXIO;
   210		}
   211	
   212		irq_parent = of_irq_find_parent(node);
   213		if (!irq_parent) {
   214			dev_err(dev, "no IRQ parent node\n");
   215			return -ENODEV;
   216		}
   217		parent = irq_find_host(irq_parent);
   218		of_node_put(irq_parent);
   219		if (!parent) {
   220			dev_err(dev, "no IRQ parent domain\n");
   221			return -ENODEV;
   222		}
   223	
   224		for (i = 0; i < ngpio; i++) {
   225			chip->irq_number[i] = platform_get_irq(pdev, i);
 > 226			if (chip->irq_number[i] < 0)
   227				return chip->irq_number[i];
   228		}
   229	
   230		ret = bgpio_init(&chip->gc, dev, 4,
   231				 chip->base + SIFIVE_GPIO_INPUT_VAL,
   232				 chip->base + SIFIVE_GPIO_OUTPUT_VAL,
   233				 NULL,
   234				 chip->base + SIFIVE_GPIO_OUTPUT_EN,
   235				 chip->base + SIFIVE_GPIO_INPUT_EN,
   236				 BGPIOF_READ_OUTPUT_REG_SET);
   237		if (ret) {
   238			dev_err(dev, "unable to init generic GPIO\n");
   239			return ret;
   240		}
   241	
   242		/* Disable all GPIO interrupts before enabling parent interrupts */
   243		regmap_write(chip->regs, SIFIVE_GPIO_RISE_IE, 0);
   244		regmap_write(chip->regs, SIFIVE_GPIO_FALL_IE, 0);
   245		regmap_write(chip->regs, SIFIVE_GPIO_HIGH_IE, 0);
   246		regmap_write(chip->regs, SIFIVE_GPIO_LOW_IE, 0);
   247		chip->irq_state = 0;
   248	
   249		chip->gc.base = -1;
   250		chip->gc.ngpio = ngpio;
   251		chip->gc.label = dev_name(dev);
   252		chip->gc.parent = dev;
   253		chip->gc.owner = THIS_MODULE;
   254		girq = &chip->gc.irq;
   255		gpio_irq_chip_set_chip(girq, &sifive_gpio_irqchip);
   256		girq->fwnode = of_node_to_fwnode(node);
   257		girq->parent_domain = parent;
   258		girq->child_to_parent_hwirq = sifive_gpio_child_to_parent_hwirq;
   259		girq->handler = handle_bad_irq;
   260		girq->default_type = IRQ_TYPE_NONE;
   261	
   262		platform_set_drvdata(pdev, chip);
   263		return gpiochip_add_data(&chip->gc, chip);
   264	}
   265
Andy Shevchenko June 3, 2023, 8:59 p.m. UTC | #3
On Sat, Jun 3, 2023 at 8:48 PM kernel test robot <lkp@intel.com> wrote:
>
> Hi Jiasheng,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on brgl/gpio/for-next]
> [also build test WARNING on linus/master v6.4-rc4 next-20230602]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Jiasheng-Jiang/gpio-sifive-Add-missing-check-for-platform_get_irq/20230602-152856
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next
> patch link:    https://lore.kernel.org/r/20230602072755.7314-1-jiasheng%40iscas.ac.cn
> patch subject: [PATCH v2] gpio: sifive: Add missing check for platform_get_irq
> config: openrisc-randconfig-m041-20230531 (https://download.01.org/0day-ci/archive/20230604/202306040153.RPAlkz3U-lkp@intel.com/config)
> compiler: or1k-linux-gcc (GCC) 12.3.0
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202306040153.RPAlkz3U-lkp@intel.com/
>
> smatch warnings:
> drivers/gpio/gpio-sifive.c:226 sifive_gpio_probe() warn: unsigned 'chip->irq_number[i]' is never less than zero.

Nice!

...

>    224          for (i = 0; i < ngpio; i++) {
>    225                  chip->irq_number[i] = platform_get_irq(pdev, i);
>  > 226                  if (chip->irq_number[i] < 0)
>    227                          return chip->irq_number[i];

So, this should be

  ret = ...
  if (ret < 0)
    return ret;
  irq_number = ret;

>    228          }
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
index 98939cd4a71e..7245000fb049 100644
--- a/drivers/gpio/gpio-sifive.c
+++ b/drivers/gpio/gpio-sifive.c
@@ -221,8 +221,11 @@  static int sifive_gpio_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	for (i = 0; i < ngpio; i++)
+	for (i = 0; i < ngpio; i++) {
 		chip->irq_number[i] = platform_get_irq(pdev, i);
+		if (chip->irq_number[i] < 0)
+			return chip->irq_number[i];
+	}
 
 	ret = bgpio_init(&chip->gc, dev, 4,
 			 chip->base + SIFIVE_GPIO_INPUT_VAL,