gpio: mpc8xxx: Fix 3 errors related to the error handling path of the 'mpc8xxx_probe()'
Subsystems (2)
cover gpio: mpc8xxx: Fix 3 errors related to the error handling path of the 'mpc8xxx_probe()'
This has been split in 3 patches because:
- the root issue of patch 1 and 3 is not the same commit as the one for patch 2.
- the strategy to fix the issues is not the same
- patch 1: add a new call in the rror handling path
- patch 3: switch to a resource managed function
They could be merged together if easier to review. The subject would then be something like "gpio: mpc8xxx: Fix the error handling path of 'mpc8xxx_probe()'"
If prefered, 'devm_add_action_or_reset()' could be used to switch the probe to a fully managed resource function and remove the 'remove' function. That's mostly a matter of taste.
If such an option is preferred, I'm a bit puzzled by the 'irq_set_chained_handler_and_data()' call in the remove function because I don't see why it is there.
Also see the comment at the end of patch 1 also related to this function call.
Christophe JAILLET (3):
gpio: mpc8xxx: Fix a resources leak in the error handling path of
'mpc8xxx_probe()'
gpio: mpc8xxx: Fix a potential double iounmap call in
'mpc8xxx_probe()' gpio: mpc8xxx: Use 'devm_gpiochip_add_data()' to simplify the code and
avoid a leak
drivers/gpio/gpio-mpc8xxx.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/3 gpio: mpc8xxx: Fix a resources leak in the error handling path of 'mpc8xxx_probe()'
Commit 698b8eeaed72 ("gpio/mpc8xxx: change irq handler from chained to normal") has introduced a new 'goto err;' at the very end of the function, but has not updated the error handling path accordingly.
Add the now missing 'irq_domain_remove()' call which balances a previous 'irq_domain_create_linear() call.
---
Is the 'irq_set_chained_handler_and_data()' of the remove function also needed here?
--- drivers/gpio/gpio-mpc8xxx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-mpc8xxx.c +2 -0
@@ -416,6 +416,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)return 0 ; err: +if (mpc8xxx_gc->irq) +irq_domain_remove (mpc8xxx_gc->irq);iounmap (mpc8xxx_gc->regs);return ret; }
Signature · 1 line
2.30.2
Bartosz Golaszewski
AppliedRe: [PATCH 1/3] gpio: mpc8xxx: Fix a resources leak in the error handling path of 'mpc8xxx_probe()'
Quoted 31 lines · Christophe JAILLET
Commit
698b8eeaed72("gpio/mpc8xxx: change irq handler from chained to normal") has introduced a new 'goto err;' at the very end of the function, but has not updated the error handling path accordingly.Add the now missing '
irq_domain_remove()' call which balances a previous 'irq_domain_create_linear()call.Fixes 698b8eeaed72 ("gpio/mpc8xxx: change irq handler from chained to normal")Signed-off-by Christophe JAILLET <[email protected]>---
Is the 'irq_set_chained_handler_and_data()' of the remove function also needed here?--- drivers/gpio/gpio-mpc8xxx.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpio/gpio-mpc8xxx.c +2
-1@@ -416,6 +416,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)return 0 ; err: +if (mpc8xxx_gc->irq) +irq_domain_remove (mpc8xxx_gc->irq);iounmap (mpc8xxx_gc->regs);return ret; } --
Quoted 2 lines
2.30.2
Applied, thanks!
Bart
PATCH 2/3 gpio: mpc8xxx: Fix a potential double iounmap call in 'mpc8xxx_probe()'
In reply to Christophe JAILLETCommit 76c47d1449fc ("gpio: mpc8xxx: Add ACPI support") has switched to a managed version when dealing with 'mpc8xxx_gc->regs'. So the corresponding 'iounmap()' call in the error handling path and in the remove should be removed to avoid a double unmap.
This also allows some simplification in the probe. All the error handling paths related to managed resources can be direct returns and a NULL check in what remains in the error handling path can be removed.
--- drivers/gpio/gpio-mpc8xxx.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpio/gpio-mpc8xxx.c +4 -7
@@ -332,7 +332,7 @@ static int mpc8xxx_probe(struct platform_device *pdev) mpc8xxx_gc->regs +GPIO_DIR ,NULL , BGPIOF_BIG_ENDIAN);if (ret) - goto err; +return ret;dev_dbg (&pdev->dev,"GPIO registers are LITTLE endian\n" ); }else { ret = bgpio_init(gc, &pdev->dev, 4,
@@ -342,7 +342,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)BGPIOF_BIG_ENDIAN | BGPIOF_BIG_ENDIAN_BYTE_ORDER);if (ret) - goto err; +return ret;dev_dbg (&pdev->dev,"GPIO registers are BIG endian\n" ); }
@@ -384,7 +384,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)if (ret) {dev_err (&pdev->dev,"GPIO chip registration failed with status %d\n" , ret); - goto err; +return ret; } mpc8xxx_gc->irqn =platform_get_irq (pdev,0 );
@@ -416,9 +416,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)return 0 ; err: -if (mpc8xxx_gc->irq) -irq_domain_remove (mpc8xxx_gc->irq); -iounmap (mpc8xxx_gc->regs); +irq_domain_remove (mpc8xxx_gc->irq);return ret; }
@@ -432,7 +430,6 @@ static int mpc8xxx_remove(struct platform_device *pdev) }gpiochip_remove (&mpc8xxx_gc->gc); -iounmap (mpc8xxx_gc->regs);return 0 ; }
Signature · 1 line
2.30.2
Bartosz Golaszewski
AppliedRe: [PATCH 2/3] gpio: mpc8xxx: Fix a potential double iounmap call in 'mpc8xxx_probe()'
Quoted 67 lines · Christophe JAILLET
Commit
76c47d1449fc("gpio: mpc8xxx: Add ACPI support") has switched to a managed version when dealing with 'mpc8xxx_gc->regs'. So the corresponding 'iounmap()' call in the error handling path and in the remove should be removed to avoid a double unmap.This also allows some simplification in the probe. All the error handling paths related to managed resources can be direct returns and a NULL check in what remains in the error handling path can be removed.
Fixes 76c47d1449fc ("gpio: mpc8xxx: Add ACPI support")Signed-off-by Christophe JAILLET <[email protected]>--- drivers/gpio/gpio-mpc8xxx.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/gpio/gpio-mpc8xxx.c +4
-8@@ -332,7 +332,7 @@ static int mpc8xxx_probe(struct platform_device *pdev) mpc8xxx_gc->regs +GPIO_DIR ,NULL , BGPIOF_BIG_ENDIAN);if (ret) - goto err; +return ret;dev_dbg (&pdev->dev,"GPIO registers are LITTLE endian\n" ); }else { ret = bgpio_init(gc, &pdev->dev, 4,@@ -342,7 +342,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)BGPIOF_BIG_ENDIAN | BGPIOF_BIG_ENDIAN_BYTE_ORDER);if (ret) - goto err; +return ret;dev_dbg (&pdev->dev,"GPIO registers are BIG endian\n" ); }@@ -384,7 +384,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)if (ret) {dev_err (&pdev->dev,"GPIO chip registration failed with status %d\n" , ret); - goto err; +return ret; } mpc8xxx_gc->irqn =platform_get_irq (pdev,0 );@@ -416,9 +416,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)return 0 ; err: -if (mpc8xxx_gc->irq) -irq_domain_remove (mpc8xxx_gc->irq); -iounmap (mpc8xxx_gc->regs); +irq_domain_remove (mpc8xxx_gc->irq);return ret; }@@ -432,7 +430,6 @@ static int mpc8xxx_remove(struct platform_device *pdev) }gpiochip_remove (&mpc8xxx_gc->gc); -iounmap (mpc8xxx_gc->regs);return 0 ; } --
Quoted 2 lines
2.30.2
Applied, thanks!
Bart
PATCH 3/3 gpio: mpc8xxx: Use 'devm_gpiochip_add_data()' to simplify the code and avoid a leak
In reply to Christophe JAILLETIf an error occurs after a 'gpiochip_add_data()' call it must be undone by a corresponding 'gpiochip_remove()' as already done in the remove function.
To simplify the code a fix a leak in the error handling path of the probe, use the managed version instead (i.e. 'devm_gpiochip_add_data()')
--- drivers/gpio/gpio-mpc8xxx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpio/gpio-mpc8xxx.c +1 -3
@@ -380,7 +380,7 @@ static int mpc8xxx_probe(struct platform_device *pdev) is_acpi_node(fwnode)) gc->write_reg (mpc8xxx_gc->regs +GPIO_IBE ,0xffffffff ); - ret =gpiochip_add_data (gc, mpc8xxx_gc); + ret =devm_gpiochip_add_data (&pdev->dev, gc, mpc8xxx_gc);if (ret) {dev_err (&pdev->dev,"GPIO chip registration failed with status %d\n" , ret);
@@ -429,8 +429,6 @@ static int mpc8xxx_remove(struct platform_device *pdev)irq_domain_remove (mpc8xxx_gc->irq); } -gpiochip_remove (&mpc8xxx_gc->gc); -return 0 ; }
Signature · 1 line
2.30.2
Bartosz Golaszewski
AppliedRe: [PATCH 3/3] gpio: mpc8xxx: Use 'devm_gpiochip_add_data()' to simplify the code and avoid a leak
Quoted 36 lines · Christophe JAILLET
If an error occurs after a '
gpiochip_add_data()' call it must be undone by a corresponding 'gpiochip_remove()' as already done in the remove function.To simplify the code a fix a leak in the error handling path of the probe, use the managed version instead (i.e. '
devm_gpiochip_add_data()')Fixes 698b8eeaed72 ("gpio/mpc8xxx: change irq handler from chained to normal")Signed-off-by Christophe JAILLET <[email protected]>--- drivers/gpio/gpio-mpc8xxx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpio/gpio-mpc8xxx.c +1
-4@@ -380,7 +380,7 @@ static int mpc8xxx_probe(struct platform_device *pdev) is_acpi_node(fwnode)) gc->write_reg (mpc8xxx_gc->regs +GPIO_IBE ,0xffffffff ); - ret =gpiochip_add_data (gc, mpc8xxx_gc); + ret =devm_gpiochip_add_data (&pdev->dev, gc, mpc8xxx_gc);if (ret) {dev_err (&pdev->dev,"GPIO chip registration failed with status %d\n" , ret);@@ -429,8 +429,6 @@ static int mpc8xxx_remove(struct platform_device *pdev)irq_domain_remove (mpc8xxx_gc->irq); } -gpiochip_remove (&mpc8xxx_gc->gc); -return 0 ; } --
Quoted 2 lines
2.30.2
Applied, thanks!
Bart
Quoted 25 lines · Christophe JAILLET
This has been split in 3 patches because:
- the root issue of patch 1 and 3 is not the same commit as the one for patch 2.
- the strategy to fix the issues is not the same
- patch 1: add a new call in the rror handling path
- patch 3: switch to a resource managed functionThey could be merged together if easier to review. The subject would then be something like "gpio: mpc8xxx: Fix the error handling path of '
mpc8xxx_probe()'"If prefered, '
devm_add_action_or_reset()' could be used to switch the probe to a fully managed resource function and remove the 'remove' function. That's mostly a matter of taste.If such an option is preferred, I'm a bit puzzled by the '
irq_set_chained_handler_and_data()' call in the remove function because I don't see why it is there.
Also see the comment at the end of patch 1 also related to this function call.Christophe JAILLET (3):
gpio: mpc8xxx: Fix a resources leak in the error handling path of'mpc8xxx_probe()' gpio: mpc8xxx: Fix a potential double iounmap call in 'mpc8xxx_probe()'
Quoted 9 lines
gpio: mpc8xxx: Use '
devm_gpiochip_add_data()' to simplify the code and
avoid a leakdrivers/gpio/gpio-mpc8xxx.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)--
2.30.2
Hi Christophe,
These look good but I'm leaving for a couple days in an hour so I won't be able to send a PR to Linus before the next release. I'll make these part of my regular PR for the upcoming merge window.
Bart