gpio: mt7621: address Sashiko complains and other cleanups
Subsystems (3)
v2 cover gpio: mt7621: address Sashiko complains and other cleanups
Hi,
This patchset covers some sashiko complains reported at some point when IRQ mapping was being fixed for this driver [0].
I have included 'Fixes' tag and CC to stable for patches 13 since patch 4 is just a cleanup for naming.
Thanks in advance for your time.
Best regards,
Sergio Paracuellos
[0]: https://sashiko.dev/#/patchset/20260609031118.2275735-1-sergio.paracuellos%40gmail.com
Changes in v2:
- Add Fixes and Cc tags on patches 1-3 as requested by Bartosz
Sergio Paracuellos (4):
gpio: mt7621: avoid corruption of shared interrupt trigger state
gpio: mt7621: more robust management of IRQ domain teardown
gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips
gpio: mt7621: unify naming style in driver code
drivers/gpio/gpio-mt7621.c | 63 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/4 gpio: mt7621: avoid corruption of shared interrupt trigger state
The bank-shared fields like 'rising' and 'falling' are modified using non-atomic read-modify-write operations. Since every gpio chip instance represents an entire bank of 32 pins, if 'mediatek_gpio_irq_type()' is called concurrently for different IRQs on the same bank a possible overwrite of each other's configuration is possible. Thus, protect this state with 'gpio_generic_lock_irqsave' lock in the same way it is handled in irp_chip 'mediatek_gpio_irq_mask()' and 'mediatek_gpio_irq_unmask()' callbacks.
--- drivers/gpio/gpio-mt7621.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-mt7621.c +2 -0
@@ -187,6 +187,8 @@ mediatek_gpio_irq_type(struct irq_data *d, unsigned int type)struct mtk_gc *rg =gpiochip_get_data (gc);u32 mask =BIT (mt7621_gpio_hwirq_to_offset (d->hwirq, rg)); +guard (gpio_generic_lock_irqsave)(&rg->chip); +if (type ==IRQ_TYPE_PROBE ) {if ((rg->rising | rg->falling | rg->hlevel | rg->llevel) & mask)
Signature · 1 line
2.43.0
PATCH v2 2/4 gpio: mt7621: more robust management of IRQ domain teardown
In reply to Sergio ParacuellosThe driver uses devm_gpiochip_add_data() to register the GPIO chips which means the devres subsystem will unregister them only after the function 'mt7621_gpio_remove()' returns. During the window between domain destruction and devres unregistering the GPIO chips, the chips are still fully active. If a consumer or userspace invokes gpiod_to_irq() during this window, 'mt7621_gpio_to_irq()' can dereference the already-freed irq domain pointer. Thus, manage the IRQ domain teardown using 'devm_add_action_or_reset()' to guarantee it is destroyed strictly after the GPIO chips are removed.
--- drivers/gpio/gpio-mt7621.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpio/gpio-mt7621.c +7 -8
@@ -272,9 +272,9 @@ static const struct irq_chip mt7621_irq_chip = { };static void -mt7621_gpio_remove (struct platform_device *pdev) +mt7621_gpio_remove (void *data) { -struct mtk *priv =platform_get_drvdata (pdev); +struct mtk *priv = data;int offset, virq;if (priv->gpio_irq >0 )
@@ -475,14 +475,14 @@ mediatek_gpio_probe(struct platform_device *pdev)if (mtk->gpio_irq >0 ) { ret =mt7621_gpio_irq_setup (pdev, mtk);if (ret) - goto fail; +return ret; } -return 0 ; + ret =devm_add_action_or_reset (dev, mt7621_gpio_remove, mtk); +if (ret) +return ret; -fail: -mt7621_gpio_remove (pdev); -return ret; +return 0 ; }static const struct of_device_id mediatek_gpio_match[] = {
@@ -493,7 +493,6 @@ MODULE_DEVICE_TABLE(of, mediatek_gpio_match);static struct platform_driver mediatek_gpio_driver = { .probe = mediatek_gpio_probe, - .remove = mt7621_gpio_remove, .driver = { .name ="mt7621_gpio" , .of_match_table = mediatek_gpio_match,
Signature · 1 line
2.43.0
PATCH v2 3/4 gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips
In reply to Sergio ParacuellosFunction 'mediatek_gpio_bank_probe()' registers three GPIO chips using 'devm_gpiochip_add_data()'. At this point, the chips become live and visible to consumers. However, the IRQ domain isn't allocated and set up until 'mt7621_gpio_irq_setup()' is called after the GPIO chips setup finishes. If a consumer requests a GPIO IRQ concurrently 'mt7621_gpio_to_irq()' can be called and pass a NULL irq domain pointer irq_create_mapping(), that can corrupt the mappings or cause a crash. Fix this possible problem seting up irq domain before GPIO chips setup is performed.
--- drivers/gpio/gpio-mt7621.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpio/gpio-mt7621.c +6 -6
@@ -466,12 +466,6 @@ mediatek_gpio_probe(struct platform_device *pdev) mtk->num_gpios =MTK_BANK_WIDTH *MTK_BANK_CNT ;platform_set_drvdata (pdev, mtk); -for (i =0 ; i <MTK_BANK_CNT ; i++) { - ret =mediatek_gpio_bank_probe (dev, i); -if (ret) -return ret; - } -if (mtk->gpio_irq >0 ) { ret =mt7621_gpio_irq_setup (pdev, mtk);if (ret)
@@ -482,6 +476,12 @@ mediatek_gpio_probe(struct platform_device *pdev)if (ret)return ret; +for (i =0 ; i <MTK_BANK_CNT ; i++) { + ret =mediatek_gpio_bank_probe (dev, i); +if (ret) +return ret; + } +return 0 ; }
Signature · 1 line
2.43.0
Bartosz Golaszewski
maintainerRe: [PATCH v2 3/4] gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips
Quoted 9 lines · Sergio Paracuellos
Function '
mediatek_gpio_bank_probe()' registers three GPIO chips using 'devm_gpiochip_add_data()'. At this point, the chips become live and visible to consumers. However, the IRQ domain isn't allocated and set up until 'mt7621_gpio_irq_setup()' is called after the GPIO chips setup finishes. If a consumer requests a GPIO IRQ concurrently 'mt7621_gpio_to_irq()' can be called and pass a NULL irq domain pointerirq_create_mapping(), that can corrupt the mappings or cause a crash. Fix this possible problem seting up irq domain before GPIO chips setup is performed.
Quoted 5 lines
Reported-by Sashiko <[email protected]>Fixes a46f2e5720f5 ("gpio: mt7621: fix interrupt banks mapping on gpio chips")Signed-off-by Sergio Paracuellos <[email protected]>---
Seems like sashiko still complains about this one. I'm not overly worried about this path but since the commit's purpose was to address this very issue, do you want to rework it further?
Bart
Re: [PATCH v2 3/4] gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips
Hi Bartosz,
Quoted 18 lines · Bartosz Golaszewski
Quoted 9 lines · Sergio Paracuellos
Function '
mediatek_gpio_bank_probe()' registers three GPIO chips using 'devm_gpiochip_add_data()'. At this point, the chips become live and visible to consumers. However, the IRQ domain isn't allocated and set up until 'mt7621_gpio_irq_setup()' is called after the GPIO chips setup finishes. If a consumer requests a GPIO IRQ concurrently 'mt7621_gpio_to_irq()' can be called and pass a NULL irq domain pointerirq_create_mapping(), that can corrupt the mappings or cause a crash. Fix this possible problem seting up irq domain before GPIO chips setup is performed.Quoted 5 lines
Reported-by Sashiko <[email protected]>Fixes a46f2e5720f5 ("gpio: mt7621: fix interrupt banks mapping on gpio chips")Signed-off-by Sergio Paracuellos <[email protected]>---
Quoted 3 lines
Seems like sashiko still complains about this one. I'm not overly worried about this path but since the commit's purpose was to address this very issue, do you want to rework it further?
Previous complaint was about the IRQ mapping being NULL because mapping was not created when gpio chips are set up. I think that it made more sense that this new complaint about the reverse order. So I would maintain this PATCH as it is. Thus, I don't want to rework anything here.
Thanks,
Sergio Paracuellos
PATCH v2 4/4 gpio: mt7621: unify naming style in driver code
In reply to Sergio ParacuellosThere is a mix of 'mediatek' and 'mt7621' mix of prefix in different function names along the code of the driver. Be consistent using 'mt7621' for all function prefixes.
--- drivers/gpio/gpio-mt7621.c | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/gpio/gpio-mt7621.c +20 -20
@@ -68,7 +68,7 @@ mt7621_gpio_gc_to_priv(struct gpio_chip *gc) }static inline struct mtk_gc * -to_mediatek_gpio (struct gpio_chip *chip) +to_mt7621_gpio (struct gpio_chip *chip) {struct gpio_generic_chip *gen_gc =to_gpio_generic_chip (chip);
@@ -137,7 +137,7 @@ mt7621_gpio_hwirq_to_offset(irq_hw_number_t hwirq, struct mtk_gc *bank) }static void -mediatek_gpio_irq_unmask (struct irq_data *d) +mt7621_gpio_irq_unmask (struct irq_data *d) {struct gpio_chip *gc =irq_data_get_irq_chip_data (d);struct mtk_gc *rg =gpiochip_get_data (gc);
@@ -159,7 +159,7 @@ mediatek_gpio_irq_unmask(struct irq_data *d) }static void -mediatek_gpio_irq_mask (struct irq_data *d) +mt7621_gpio_irq_mask (struct irq_data *d) {struct gpio_chip *gc =irq_data_get_irq_chip_data (d);struct mtk_gc *rg =gpiochip_get_data (gc);
@@ -181,7 +181,7 @@ mediatek_gpio_irq_mask(struct irq_data *d) }static int -mediatek_gpio_irq_type (struct irq_data *d,unsigned int type) +mt7621_gpio_irq_type (struct irq_data *d,unsigned int type) {struct gpio_chip *gc =irq_data_get_irq_chip_data (d);struct mtk_gc *rg =gpiochip_get_data (gc);
@@ -245,11 +245,11 @@ mt7621_gpio_irq_relres(struct irq_data *d) }static int -mediatek_gpio_xlate (struct gpio_chip *chip, +mt7621_gpio_xlate (struct gpio_chip *chip,const struct of_phandle_args *spec,u32 *flags) {int gpio = spec->args[0 ]; -struct mtk_gc *rg =to_mediatek_gpio (chip); +struct mtk_gc *rg =to_mt7621_gpio (chip);if (rg->bank != gpio /MTK_BANK_WIDTH )return -EINVAL ;
@@ -264,10 +264,10 @@ static const struct irq_chip mt7621_irq_chip = { .name = "mt7621-gpio", .irq_request_resources = mt7621_gpio_irq_reqres, .irq_release_resources = mt7621_gpio_irq_relres, - .irq_mask_ack = mediatek_gpio_irq_mask, - .irq_mask = mediatek_gpio_irq_mask, - .irq_unmask = mediatek_gpio_irq_unmask, - .irq_set_type = mediatek_gpio_irq_type, + .irq_mask_ack = mt7621_gpio_irq_mask, + .irq_mask = mt7621_gpio_irq_mask, + .irq_unmask = mt7621_gpio_irq_unmask, + .irq_set_type = mt7621_gpio_irq_type, .flags = IRQCHIP_IMMUTABLE, };
@@ -380,7 +380,7 @@ mt7621_gpio_to_irq(struct gpio_chip *gc, unsigned int offset) }static int -mediatek_gpio_bank_probe (struct device *dev,int bank) +mt7621_gpio_bank_probe (struct device *dev,int bank) {struct gpio_generic_chip_config config;struct mtk *mtk =dev_get_drvdata (dev);
@@ -416,7 +416,7 @@ mediatek_gpio_bank_probe(struct device *dev, int bank) } rg->chip.gc.of_gpio_n_cells =2 ; - rg->chip.gc.of_xlate = mediatek_gpio_xlate; + rg->chip.gc.of_xlate = mt7621_gpio_xlate; rg->chip.gc.ngpio =MTK_BANK_WIDTH ; rg->chip.gc.label =devm_kasprintf (dev,GFP_KERNEL ,"%s-bank%d" ,dev_name (dev), bank);
@@ -443,7 +443,7 @@ mediatek_gpio_bank_probe(struct device *dev, int bank) }static int -mediatek_gpio_probe (struct platform_device *pdev) +mt7621_gpio_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct mtk *mtk;
@@ -477,7 +477,7 @@ mediatek_gpio_probe(struct platform_device *pdev)return ret;for (i =0 ; i <MTK_BANK_CNT ; i++) { - ret =mediatek_gpio_bank_probe (dev, i); + ret =mt7621_gpio_bank_probe (dev, i);if (ret)return ret; }
@@ -485,18 +485,18 @@ mediatek_gpio_probe(struct platform_device *pdev)return 0 ; } -static const struct of_device_id mediatek_gpio_match[] = { +static const struct of_device_id mt7621_gpio_match[] = { { .compatible ="mediatek,mt7621-gpio" }, {}, }; -MODULE_DEVICE_TABLE (of, mediatek_gpio_match); +MODULE_DEVICE_TABLE (of, mt7621_gpio_match); -static struct platform_driver mediatek_gpio_driver = { - .probe = mediatek_gpio_probe, +static struct platform_driver mt7621_gpio_driver = { + .probe = mt7621_gpio_probe, .driver = { .name ="mt7621_gpio" , - .of_match_table = mediatek_gpio_match, + .of_match_table = mt7621_gpio_match, }, }; -builtin_platform_driver (mediatek_gpio_driver); +builtin_platform_driver (mt7621_gpio_driver);
Signature · 1 line
2.43.0
Bartosz Golaszewski
AppliedRe: (subset) [PATCH v2 0/4] gpio: mt7621: address Sashiko complains and other cleanups
In reply to Sergio ParacuellosQuoted 9 lines · Sergio Paracuellos
This patchset covers some sashiko complains reported at some point when IRQ mapping was being fixed for this driver [0].
I have included 'Fixes' tag and CC to stable for patches 13 since patch 4 is just a cleanup for naming.
Thanks in advance for your time.
[...]
Applied, thanks!
[1/4] gpio: mt7621: avoid corruption of shared interrupt trigger state
https://git.kernel.org/brgl/c/1781172526d1092323af443fa03f00e6de560401 [2/4] gpio: mt7621: more robust management of IRQ domain teardown https://git.kernel.org/brgl/c/839738536adabae1a7e98ed3fc332ce9cc991d27 [3/4] gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips https://git.kernel.org/brgl/c/0e024f58291dfcb28d98c512002e1a80fad69798
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Re: (subset) [PATCH v2 0/4] gpio: mt7621: address Sashiko complains and other cleanups
Quoted 15 lines · Bartosz Golaszewski
Quoted 9 lines · Sergio Paracuellos
This patchset covers some sashiko complains reported at some point when IRQ mapping was being fixed for this driver [0].
I have included 'Fixes' tag and CC to stable for patches 13 since patch 4 is just a cleanup for naming.
Thanks in advance for your time.
[...]
Applied, thanks!
Quoted 8 lines
[1/4] gpio: mt7621: avoid corruption of shared interrupt trigger state
https://git.kernel.org/brgl/c/1781172526d1092323af443fa03f00e6de560401 [2/4] gpio: mt7621: more robust management of IRQ domain teardown https://git.kernel.org/brgl/c/839738536adabae1a7e98ed3fc332ce9cc991d27 [3/4] gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips https://git.kernel.org/brgl/c/0e024f58291dfcb28d98c512002e1a80fad69798Best regards,
Thanks! What about PATCH 4? Are you planning to apply afterwards or should I just forget about it?
Best regards,
Sergio Paracuellos
Quoted 2 lines
--
Bartosz Golaszewski <[email protected]>
Bartosz Golaszewski
maintainerRe: (subset) [PATCH v2 0/4] gpio: mt7621: address Sashiko complains and other cleanups
Quoted 24 lines · Sergio Paracuellos
Quoted 22 lines · Bartosz Golaszewski
Quoted 9 lines · Sergio Paracuellos
This patchset covers some sashiko complains reported at some point when IRQ mapping was being fixed for this driver [0].
I have included 'Fixes' tag and CC to stable for patches 13 since patch 4 is just a cleanup for naming.
Thanks in advance for your time.
[...]
Applied, thanks!
[1/4] gpio: mt7621: avoid corruption of shared interrupt trigger state
https://git.kernel.org/brgl/c/1781172526d1092323af443fa03f00e6de560401 [2/4] gpio: mt7621: more robust management of IRQ domain teardown https://git.kernel.org/brgl/c/839738536adabae1a7e98ed3fc332ce9cc991d27 [3/4] gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips https://git.kernel.org/brgl/c/0e024f58291dfcb28d98c512002e1a80fad69798
Quoted 10 lines
Quoted 1 line
Best regards,
Thanks! What about PATCH 4? Are you planning to apply afterwards or should I just forget about it?
Best regards,
Sergio ParacuellosQuoted 2 lines
--
Bartosz Golaszewski <[email protected]>
It's not a fix and it seems to depend on the three above. Once these three are upstream, I'll pull a mainline tag and apply 4/4. No worries.
Bartosz
Re: (subset) [PATCH v2 0/4] gpio: mt7621: address Sashiko complains and other cleanups
Quoted 32 lines · Bartosz Golaszewski
Quoted 29 lines · Sergio Paracuellos
Quoted 15 lines · Bartosz Golaszewski
Quoted 9 lines · Sergio Paracuellos
This patchset covers some sashiko complains reported at some point when IRQ mapping was being fixed for this driver [0].
I have included 'Fixes' tag and CC to stable for patches 13 since patch 4 is just a cleanup for naming.
Thanks in advance for your time.
[...]
Applied, thanks!
Quoted 8 lines
[1/4] gpio: mt7621: avoid corruption of shared interrupt trigger state
https://git.kernel.org/brgl/c/1781172526d1092323af443fa03f00e6de560401 [2/4] gpio: mt7621: more robust management of IRQ domain teardown https://git.kernel.org/brgl/c/839738536adabae1a7e98ed3fc332ce9cc991d27 [3/4] gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips https://git.kernel.org/brgl/c/0e024f58291dfcb28d98c512002e1a80fad69798Best regards,
Thanks! What about PATCH 4? Are you planning to apply afterwards or should I just forget about it?
Quoted 8 lines
Quoted 5 lines
Best regards,
Sergio ParacuellosQuoted 2 lines
--
Bartosz Golaszewski <[email protected]>It's not a fix and it seems to depend on the three above. Once these three are upstream, I'll pull a mainline tag and apply 4/4. No worries.
Thanks a lot for letting me know.
Best regards,
Sergio Paracuellos
Quoted 2 lines
Bartosz
Bartosz Golaszewski
AppliedRe: (subset) [PATCH v2 0/4] gpio: mt7621: address Sashiko complains and other cleanups
In reply to Sergio ParacuellosQuoted 9 lines · Sergio Paracuellos
This patchset covers some sashiko complains reported at some point when IRQ mapping was being fixed for this driver [0].
I have included 'Fixes' tag and CC to stable for patches 13 since patch 4 is just a cleanup for naming.
Thanks in advance for your time.
[...]
Applied, thanks!
[4/4] gpio: mt7621: unify naming style in driver code
https://git.kernel.org/brgl/c/83957567b1589bcaf5fafbc359cc17f79a59ed29
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Re: (subset) [PATCH v2 0/4] gpio: mt7621: address Sashiko complains and other cleanups
Quoted 9 lines · Bartosz Golaszewski
Quoted 6 lines · Sergio Paracuellos
This patchset covers some sashiko complains reported at some point when IRQ mapping was being fixed for this driver [0].
I have included 'Fixes' tag and CC to stable for patches 13 since patch 4 is just a cleanup for naming.
Quoted 8 lines
Quoted 3 lines
Thanks in advance for your time.
[...]
Applied, thanks!
[4/4] gpio: mt7621: unify naming style in driver code
https://git.kernel.org/brgl/c/83957567b1589bcaf5fafbc359cc17f79a59ed29
Thanks!
Best regards,
Sergio Paracuellos
Quoted 4 lines
Best regards,
--
Bartosz Golaszewski <[email protected]>