With the call to of_irq_count() removed, the SiFive GPIO driver can be
built as a module. This helps to minimize the size of a multiplatform
kernel, and is required by some downstream distributions (Android GKI).
This series removes the rest of the of_* API usage in the process.
Changes in v3:
- Use dev_fwnode() instead of member access
- Mention the SIFIVE_GPIO_MAX check in the commit message
- Keep the variable for the parent IRQ domain
- Add a comment explaining why the IRQ data lookup will succeed
Changes in v2:
- Add 3 new patches removing of_* API usage
- Add MODULE_AUTHOR and MODULE_DESCRIPTION
Samuel Holland (4):
gpio: sifive: Directly use the device's fwnode
gpio: sifive: Look up IRQs only once during probe
gpio: sifive: Get the parent IRQ's domain from its irq_data
gpio: sifive: Allow building the driver as a module
drivers/gpio/Kconfig | 2 +-
drivers/gpio/gpio-sifive.c | 47 ++++++++++++++++----------------------
2 files changed, 21 insertions(+), 28 deletions(-)
--
2.40.1
Do not parse the devicetree again when the data is already available
from the IRQ subsystem. This follows the example of the ThunderX and
X-Gene GPIO drivers. The ngpio check is needed to avoid a possible
out-of-bounds read.
Signed-off-by: Samuel Holland <[email protected]>
---
Changes in v3:
- Keep the variable for the parent IRQ domain
- Add a comment explaining why the IRQ data lookup will succeed
Changes in v2:
- New patch for v2
drivers/gpio/gpio-sifive.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
index e96829ac731d..3545bc0fad13 100644
--- a/drivers/gpio/gpio-sifive.c
+++ b/drivers/gpio/gpio-sifive.c
@@ -6,7 +6,6 @@
#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/errno.h>
-#include <linux/of_irq.h>
#include <linux/gpio/driver.h>
#include <linux/init.h>
#include <linux/platform_device.h>
@@ -181,8 +180,6 @@ static const struct regmap_config sifive_gpio_regmap_config = {
static int sifive_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *node = pdev->dev.of_node;
- struct device_node *irq_parent;
struct irq_domain *parent;
struct gpio_irq_chip *girq;
struct sifive_gpio *chip;
@@ -203,24 +200,22 @@ static int sifive_gpio_probe(struct platform_device *pdev)
if (IS_ERR(chip->regs))
return PTR_ERR(chip->regs);
- irq_parent = of_irq_find_parent(node);
- if (!irq_parent) {
- dev_err(dev, "no IRQ parent node\n");
- return -ENODEV;
- }
- parent = irq_find_host(irq_parent);
- of_node_put(irq_parent);
- if (!parent) {
- dev_err(dev, "no IRQ parent domain\n");
- return -ENODEV;
- }
-
for (ngpio = 0; ngpio < SIFIVE_GPIO_MAX; ngpio++) {
ret = platform_get_irq_optional(pdev, ngpio);
if (ret < 0)
break;
chip->irq_number[ngpio] = ret;
}
+ if (!ngpio) {
+ dev_err(dev, "no IRQ found\n");
+ return -ENODEV;
+ }
+
+ /*
+ * The check above ensures at least one parent IRQ is valid.
+ * Assume all parent IRQs belong to the same domain.
+ */
+ parent = irq_get_irq_data(chip->irq_number[0])->domain;
ret = bgpio_init(&chip->gc, dev, 4,
chip->base + SIFIVE_GPIO_INPUT_VAL,
--
2.40.1
On Tue, Jul 25, 2023 at 3:40 AM Samuel Holland
<[email protected]> wrote:
>
> With the call to of_irq_count() removed, the SiFive GPIO driver can be
> built as a module. This helps to minimize the size of a multiplatform
> kernel, and is required by some downstream distributions (Android GKI).
>
> This series removes the rest of the of_* API usage in the process.
Reviewed-by: Andy Shevchenko <[email protected]>
for unreviewed (by me) patches.
Thank you!
> Changes in v3:
> - Use dev_fwnode() instead of member access
> - Mention the SIFIVE_GPIO_MAX check in the commit message
> - Keep the variable for the parent IRQ domain
> - Add a comment explaining why the IRQ data lookup will succeed
>
> Changes in v2:
> - Add 3 new patches removing of_* API usage
> - Add MODULE_AUTHOR and MODULE_DESCRIPTION
>
> Samuel Holland (4):
> gpio: sifive: Directly use the device's fwnode
> gpio: sifive: Look up IRQs only once during probe
> gpio: sifive: Get the parent IRQ's domain from its irq_data
> gpio: sifive: Allow building the driver as a module
>
> drivers/gpio/Kconfig | 2 +-
> drivers/gpio/gpio-sifive.c | 47 ++++++++++++++++----------------------
> 2 files changed, 21 insertions(+), 28 deletions(-)
>
> --
> 2.40.1
>
--
With Best Regards,
Andy Shevchenko
On Tue, Jul 25, 2023 at 2:40 AM Samuel Holland
<[email protected]> wrote:
>
> With the call to of_irq_count() removed, the SiFive GPIO driver can be
> built as a module. This helps to minimize the size of a multiplatform
> kernel, and is required by some downstream distributions (Android GKI).
>
> This series removes the rest of the of_* API usage in the process.
>
> Changes in v3:
> - Use dev_fwnode() instead of member access
> - Mention the SIFIVE_GPIO_MAX check in the commit message
> - Keep the variable for the parent IRQ domain
> - Add a comment explaining why the IRQ data lookup will succeed
>
> Changes in v2:
> - Add 3 new patches removing of_* API usage
> - Add MODULE_AUTHOR and MODULE_DESCRIPTION
>
> Samuel Holland (4):
> gpio: sifive: Directly use the device's fwnode
> gpio: sifive: Look up IRQs only once during probe
> gpio: sifive: Get the parent IRQ's domain from its irq_data
> gpio: sifive: Allow building the driver as a module
>
> drivers/gpio/Kconfig | 2 +-
> drivers/gpio/gpio-sifive.c | 47 ++++++++++++++++----------------------
> 2 files changed, 21 insertions(+), 28 deletions(-)
>
> --
> 2.40.1
>
Applied, thanks!
Bartosz