Message ID | 20230719163446.1398961-3-samuel.holland@sifive.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | gpio: sifive: Module support | expand |
Context | Check | Description |
---|---|---|
conchuod/cover_letter | success | Series has a cover letter |
conchuod/tree_selection | success | Guessed tree name to be for-next at HEAD 471aba2e4760 |
conchuod/fixes_present | success | Fixes tag not required for -next series |
conchuod/maintainers_pattern | success | MAINTAINERS pattern errors before the patch: 4 and now 4 |
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: 9 this patch: 9 |
conchuod/module_param | success | Was 0 now: 0 |
conchuod/build_rv64_gcc_allmodconfig | success | Errors and warnings before: 9 this patch: 9 |
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, 36 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 |
On Wed, Jul 19, 2023 at 09:34:43AM -0700, Samuel Holland wrote: > of_irq_count(), or eqivalently platform_irq_count(), simply looks up > successively-numbered IRQs until that fails. Since this driver needs to > look up each IRQ anyway to get its virq number, use that existing loop > to count the IRQs at the same time. ... > - ngpio = of_irq_count(node); > - if (ngpio > SIFIVE_GPIO_MAX) { > - dev_err(dev, "Too many GPIO interrupts (max=%d)\n", > - SIFIVE_GPIO_MAX); > - return -ENXIO; Do we still need this check? > - } ... > + for (ngpio = 0; ngpio < SIFIVE_GPIO_MAX; ngpio++) { > + ret = platform_get_irq_optional(pdev, ngpio); > if (ret < 0) > - return ret; > - chip->irq_number[i] = ret; > + break; > + chip->irq_number[ngpio] = ret; > } If so, here we need something like ret = platform_get_irq_optional(pdev, ngpio); if (ret > 0) { dev_err(dev, "Too many GPIO interrupts (max=%d)\n", SIFIVE_GPIO_MAX); return -ENXIO; } Otherwise you need to mention this relaxation in the commit message.
On 2023-07-19 11:48 AM, Andy Shevchenko wrote: > On Wed, Jul 19, 2023 at 09:34:43AM -0700, Samuel Holland wrote: >> of_irq_count(), or eqivalently platform_irq_count(), simply looks up >> successively-numbered IRQs until that fails. Since this driver needs to >> look up each IRQ anyway to get its virq number, use that existing loop >> to count the IRQs at the same time. > > ... > >> - ngpio = of_irq_count(node); >> - if (ngpio > SIFIVE_GPIO_MAX) { >> - dev_err(dev, "Too many GPIO interrupts (max=%d)\n", >> - SIFIVE_GPIO_MAX); >> - return -ENXIO; > > Do we still need this check? I don't think so. I think this check was only intended to prevent overflowing the irq_number array, and that is now handled by the loop condition. >> - } > > ... > >> + for (ngpio = 0; ngpio < SIFIVE_GPIO_MAX; ngpio++) { >> + ret = platform_get_irq_optional(pdev, ngpio); >> if (ret < 0) >> - return ret; >> - chip->irq_number[i] = ret; >> + break; >> + chip->irq_number[ngpio] = ret; >> } > > If so, here we need something like > > ret = platform_get_irq_optional(pdev, ngpio); > if (ret > 0) { > dev_err(dev, "Too many GPIO interrupts (max=%d)\n", > SIFIVE_GPIO_MAX); > return -ENXIO; > } > > Otherwise you need to mention this relaxation in the commit message. OK, I will add something to the commit message in v3.
diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c index ab32c952c61b..6606c919d957 100644 --- a/drivers/gpio/gpio-sifive.c +++ b/drivers/gpio/gpio-sifive.c @@ -185,7 +185,7 @@ static int sifive_gpio_probe(struct platform_device *pdev) struct irq_domain *parent; struct gpio_irq_chip *girq; struct sifive_gpio *chip; - int ret, ngpio, i; + int ret, ngpio; chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) @@ -202,13 +202,6 @@ static int sifive_gpio_probe(struct platform_device *pdev) if (IS_ERR(chip->regs)) return PTR_ERR(chip->regs); - ngpio = of_irq_count(node); - if (ngpio > SIFIVE_GPIO_MAX) { - dev_err(dev, "Too many GPIO interrupts (max=%d)\n", - SIFIVE_GPIO_MAX); - return -ENXIO; - } - irq_parent = of_irq_find_parent(node); if (!irq_parent) { dev_err(dev, "no IRQ parent node\n"); @@ -221,11 +214,11 @@ static int sifive_gpio_probe(struct platform_device *pdev) return -ENODEV; } - for (i = 0; i < ngpio; i++) { - ret = platform_get_irq(pdev, i); + for (ngpio = 0; ngpio < SIFIVE_GPIO_MAX; ngpio++) { + ret = platform_get_irq_optional(pdev, ngpio); if (ret < 0) - return ret; - chip->irq_number[i] = ret; + break; + chip->irq_number[ngpio] = ret; } ret = bgpio_init(&chip->gc, dev, 4,
of_irq_count(), or eqivalently platform_irq_count(), simply looks up successively-numbered IRQs until that fails. Since this driver needs to look up each IRQ anyway to get its virq number, use that existing loop to count the IRQs at the same time. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> --- Changes in v2: - New patch for v2 drivers/gpio/gpio-sifive.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)