memory: fsl_ifc: Switch to modern devm and platform IRQ APIs
cover memory: fsl_ifc: Switch to modern devm and platform IRQ APIs
Convert the Freescale IFC controller driver from legacy OF-specific APIs to modern platform-device and devm-based equivalents. This eliminates manual resource tracking in error paths and remove(), simplifying the driver and reducing LoC by ~40%.
Patch 1 replaces irq_of_parse_and_map() with platform_get_irq() / platform_get_irq_optional() and fixes unconditional free_irq() calls on the optional NAND IRQ.
Patch 2 replaces of_iomap() with devm_platform_ioremap_resource(), dropping the manual iounmap in remove/error paths and fixing a missing free_irq on the main IRQ request_irq failure. Patch 3 switches from request_irq to devm_request_irq, removing the error-path labels entirely and reducing remove() to just of_platform_depopulate.
Rosen Penev (3):
memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to
platform IRQ API
memory: fsl_ifc: Use devm_platform_ioremap_resource and fix error
paths
memory: fsl_ifc: Use devm_request_irq and simplify remove
drivers/memory/fsl_ifc.c | 68 ++++++++++++---------------------------- 1 file changed, 20 insertions(+), 48 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/3 memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API
Switch from irq_of_parse_and_map() to platform_get_irq() for the main controller IRQ, and use platform_get_irq_optional() for the NAND IRQ which is optional. Guard free_irq() calls on the NAND IRQ with a nand_irq > 0 check to avoid passing invalid IRQ numbers on platforms without a dedicated NAND interrupt line.
--- drivers/memory/fsl_ifc.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
drivers/memory/fsl_ifc.c +16 -18
@@ -89,12 +89,10 @@ static void fsl_ifc_ctrl_remove(struct platform_device *dev)struct fsl_ifc_ctrl *ctrl =dev_get_drvdata (&dev->dev);of_platform_depopulate (&dev->dev); -free_irq (ctrl->nand_irq, ctrl); +if (ctrl->nand_irq >0 ) +free_irq (ctrl->nand_irq, ctrl);free_irq (ctrl->irq, ctrl); -irq_dispose_mapping (ctrl->nand_irq); -irq_dispose_mapping (ctrl->irq); -iounmap (ctrl->gregs);dev_set_drvdata (&dev->dev,NULL );
@@ -247,22 +245,18 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev) fsl_ifc_ctrl_dev->rregs = addr;/* get the Controller level irq */ - fsl_ifc_ctrl_dev->irq =irq_of_parse_and_map (dev->dev.of_node,0 ); -if (fsl_ifc_ctrl_dev->irq ==0 ) { + fsl_ifc_ctrl_dev->irq =platform_get_irq (dev,0 ); +if (fsl_ifc_ctrl_dev->irq <0 ) {dev_err (&dev->dev,"failed to get irq resource for IFC\n" ); - ret = -ENODEV ; + ret = fsl_ifc_ctrl_dev->irq; goto err; } -/* get the nand machine irq */ - fsl_ifc_ctrl_dev->nand_irq = -irq_of_parse_and_map (dev->dev.of_node,1 ); - fsl_ifc_ctrl_dev->dev = &dev->dev; ret =fsl_ifc_ctrl_init (fsl_ifc_ctrl_dev);if (ret <0 ) - goto err_unmap_nandirq; + goto err;init_waitqueue_head (&fsl_ifc_ctrl_dev->nand_wait);
@@ -271,10 +265,16 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)if (ret !=0 ) {dev_err (&dev->dev,"failed to install irq (%d)\n" , fsl_ifc_ctrl_dev->irq); - goto err_unmap_nandirq; + goto err; } -if (fsl_ifc_ctrl_dev->nand_irq) { +/* get the nand machine irq */ + fsl_ifc_ctrl_dev->nand_irq =platform_get_irq_optional (dev,1 ); +if (fsl_ifc_ctrl_dev->nand_irq <0 ) { + ret = fsl_ifc_ctrl_dev->nand_irq; + goto err_free_irq; + } +if (fsl_ifc_ctrl_dev->nand_irq >0 ) { ret =request_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_nand_irq,0 ,"fsl-ifc-nand" , fsl_ifc_ctrl_dev);if (ret !=0 ) {
@@ -292,12 +292,10 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)return 0 ; err_free_nandirq: -free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); +if (fsl_ifc_ctrl_dev->nand_irq >0 ) +free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); err_free_irq:free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -err_unmap_nandirq: -irq_dispose_mapping (fsl_ifc_ctrl_dev->nand_irq); -irq_dispose_mapping (fsl_ifc_ctrl_dev->irq); err:iounmap (fsl_ifc_ctrl_dev->gregs);return ret;
Signature · 1 line
2.54.0
Krzysztof Kozlowski
maintainerRe: [PATCH 1/3] memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API
drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 274
Quoted 13 lines · Rosen Penev
drivers/memory/fsl_ifc.c +5
-2@@ -271,10 +265,16 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)if (ret !=0 ) {dev_err (&dev->dev,"failed to install irq (%d)\n" , fsl_ifc_ctrl_dev->irq); - goto err_unmap_nandirq; + goto err; } -if (fsl_ifc_ctrl_dev->nand_irq) { +/* get the nand machine irq */ + fsl_ifc_ctrl_dev->nand_irq =platform_get_irq_optional (dev,1 ); +if (fsl_ifc_ctrl_dev->nand_irq <0 ) { + ret = fsl_ifc_ctrl_dev->nand_irq;
How did you test it? Looks like you change the logic and fail the probe on missing IRQ.
Best regards,
Krzysztof
Re: [PATCH 1/3] memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API
Quoted 10 lines · Krzysztof Kozlowski
Quoted 8 lines · Rosen Penev
drivers/memory/fsl_ifc.c +1
-1@@ -271,10 +265,16 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)if (ret !=0 ) {dev_err (&dev->dev,"failed to install irq (%d)\n" , fsl_ifc_ctrl_dev->irq); - goto err_unmap_nandirq; + goto err; }
Quoted 8 lines
drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 274
Quoted 5 lines
drivers/memory/fsl_ifc.c +4
-1-if (fsl_ifc_ctrl_dev->nand_irq) { +/* get the nand machine irq */ + fsl_ifc_ctrl_dev->nand_irq =platform_get_irq_optional (dev,1 ); +if (fsl_ifc_ctrl_dev->nand_irq <0 ) { + ret = fsl_ifc_ctrl_dev->nand_irq;How did you test it? Looks like you change the logic and fail the probe on missing IRQ.
Yeah this was wrong. I assumed the optional part was the irq itself but it's just the error message.
Quoted 4 lines
Best regards,
Krzysztof
PATCH 2/3 memory: fsl_ifc: Use devm_platform_ioremap_resource and fix error paths
In reply to Rosen PenevReplace of_iomap() with devm_platform_ioremap_resource() for automatic resource management, eliminating manual iounmap in remove and error paths. devm_ioremap_resource() reserves the region and checks for overlaps, which is safe here since the IFC controller register space and child chip-select ranges are always at distinct addresses in all DTS files.
Also fix the request_irq failure path to properly free the registered main IRQ, and remove an incorrect nand_irq < 0 check that treated a missing optional NAND IRQ as a fatal error.
--- drivers/memory/fsl_ifc.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
drivers/memory/fsl_ifc.c +6 -19
@@ -92,10 +92,6 @@ static void fsl_ifc_ctrl_remove(struct platform_device *dev)if (ctrl->nand_irq >0 )free_irq (ctrl->nand_irq, ctrl);free_irq (ctrl->irq, ctrl); - -iounmap (ctrl->gregs); - -dev_set_drvdata (&dev->dev,NULL ); }/*
@@ -213,11 +209,9 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)dev_set_drvdata (&dev->dev, fsl_ifc_ctrl_dev);/* IOMAP the entire IFC region */ - fsl_ifc_ctrl_dev->gregs =of_iomap (dev->dev.of_node,0 ); -if (!fsl_ifc_ctrl_dev->gregs) { -dev_err (&dev->dev,"failed to get memory region\n" ); -return -ENODEV ; - } + fsl_ifc_ctrl_dev->gregs =devm_platform_ioremap_resource (dev,0 ); +if (IS_ERR (fsl_ifc_ctrl_dev->gregs)) +return PTR_ERR (fsl_ifc_ctrl_dev->gregs);if (of_property_read_bool (dev->dev.of_node,"little-endian" )) { fsl_ifc_ctrl_dev->little_endian = true;
@@ -248,15 +242,14 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev) fsl_ifc_ctrl_dev->irq =platform_get_irq (dev,0 );if (fsl_ifc_ctrl_dev->irq <0 ) {dev_err (&dev->dev,"failed to get irq resource for IFC\n" ); - ret = fsl_ifc_ctrl_dev->irq; - goto err; +return fsl_ifc_ctrl_dev->irq; } fsl_ifc_ctrl_dev->dev = &dev->dev; ret =fsl_ifc_ctrl_init (fsl_ifc_ctrl_dev);if (ret <0 ) - goto err; +return ret;init_waitqueue_head (&fsl_ifc_ctrl_dev->nand_wait);
@@ -265,15 +258,11 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)if (ret !=0 ) {dev_err (&dev->dev,"failed to install irq (%d)\n" , fsl_ifc_ctrl_dev->irq); - goto err; + goto err_free_irq; }/* get the nand machine irq */ fsl_ifc_ctrl_dev->nand_irq =platform_get_irq_optional (dev,1 ); -if (fsl_ifc_ctrl_dev->nand_irq <0 ) { - ret = fsl_ifc_ctrl_dev->nand_irq; - goto err_free_irq; - }if (fsl_ifc_ctrl_dev->nand_irq >0 ) { ret =request_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_nand_irq,0 ,"fsl-ifc-nand" , fsl_ifc_ctrl_dev);
@@ -296,8 +285,6 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); err_free_irq:free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -err: -iounmap (fsl_ifc_ctrl_dev->gregs);return ret; }
Signature · 1 line
2.54.0
PATCH 3/3 memory: fsl_ifc: Use devm_request_irq and simplify remove
In reply to Rosen PenevSwitch from request_irq to devm_request_irq, eliminating the error path labels and free_irq calls in remove(). Since both IRQs are now devm-managed, the remove function only needs of_platform_depopulate to tear down child devices before devm cleanup fires.
--- drivers/memory/fsl_ifc.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-)
drivers/memory/fsl_ifc.c +10 -23
@@ -86,12 +86,7 @@ static int fsl_ifc_ctrl_init(struct fsl_ifc_ctrl *ctrl)static void fsl_ifc_ctrl_remove (struct platform_device *dev) { -struct fsl_ifc_ctrl *ctrl =dev_get_drvdata (&dev->dev); -of_platform_depopulate (&dev->dev); -if (ctrl->nand_irq >0 ) -free_irq (ctrl->nand_irq, ctrl); -free_irq (ctrl->irq, ctrl); }/*
@@ -253,39 +248,31 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)init_waitqueue_head (&fsl_ifc_ctrl_dev->nand_wait); - ret =request_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_irq,IRQF_SHARED , -"fsl-ifc" , fsl_ifc_ctrl_dev); + ret =devm_request_irq (&dev->dev, fsl_ifc_ctrl_dev->irq, + fsl_ifc_ctrl_irq,IRQF_SHARED , +"fsl-ifc" , fsl_ifc_ctrl_dev);if (ret !=0 ) {dev_err (&dev->dev,"failed to install irq (%d)\n" , fsl_ifc_ctrl_dev->irq); - goto err_free_irq; +return ret; }/* get the nand machine irq */ fsl_ifc_ctrl_dev->nand_irq =platform_get_irq_optional (dev,1 );if (fsl_ifc_ctrl_dev->nand_irq >0 ) { - ret =request_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_nand_irq, -0 ,"fsl-ifc-nand" , fsl_ifc_ctrl_dev); + ret =devm_request_irq (&dev->dev, + fsl_ifc_ctrl_dev->nand_irq, + fsl_ifc_nand_irq,0 , +"fsl-ifc-nand" , fsl_ifc_ctrl_dev);if (ret !=0 ) {dev_err (&dev->dev,"failed to install irq (%d)\n" , fsl_ifc_ctrl_dev->nand_irq); - goto err_free_irq; +return ret; } }/* legacy dts may still use "simple-bus" compatible */ - ret =of_platform_default_populate (dev->dev.of_node,NULL , &dev->dev); -if (ret) - goto err_free_nandirq; - -return 0 ; - -err_free_nandirq: -if (fsl_ifc_ctrl_dev->nand_irq >0 ) -free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); -err_free_irq: -free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -return ret; +return of_platform_default_populate (dev->dev.of_node,NULL , &dev->dev); }static const struct of_device_id fsl_ifc_match[] = {
Signature · 1 line
2.54.0
Krzysztof Kozlowski
maintainerRe: [PATCH 3/3] memory: fsl_ifc: Use devm_request_irq and simplify remove
drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 275
Quoted 8 lines · Rosen Penev
drivers/memory/fsl_ifc.c +1
-7- -err_free_nandirq: -if (fsl_ifc_ctrl_dev->nand_irq >0 ) -free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); -err_free_irq: -free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -return ret; +return of_platform_default_populate (dev->dev.of_node,NULL , &dev->dev);
This can be devm as well, in this patch.
Quoted 3 lines
}
static const struct
of_device_idfsl_ifc_match[] = {
Best regards,
Krzysztof
Re: [PATCH 3/3] memory: fsl_ifc: Use devm_request_irq and simplify remove
Quoted 12 lines · Krzysztof Kozlowski
drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 275
Quoted 8 lines · Rosen Penev
drivers/memory/fsl_ifc.c +1
-7- -err_free_nandirq: -if (fsl_ifc_ctrl_dev->nand_irq >0 ) -free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); -err_free_irq: -free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -return ret; +return of_platform_default_populate (dev->dev.of_node,NULL , &dev->dev);This can be devm as well, in this patch.
Not sure I follow. Although of_platform_default_populate is probably not needed here anymore. Will test.
This series means nothing though, since this driver never probes. I sent a patch but no action has been taken:
https://lore.kernel.org/all/[email protected]/
Quoted 9 lines
Quoted 5 lines
}
static const struct
of_device_idfsl_ifc_match[] = {Best regards,
Krzysztof
Krzysztof Kozlowski
maintainerRe: [PATCH 3/3] memory: fsl_ifc: Use devm_request_irq and simplify remove
Quoted 13 lines · Rosen Penev
Quoted 12 lines · Krzysztof Kozlowski
drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 275
Quoted 8 lines · Rosen Penev
drivers/memory/fsl_ifc.c +1
-7- -err_free_nandirq: -if (fsl_ifc_ctrl_dev->nand_irq >0 ) -free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); -err_free_irq: -free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -return ret; +return of_platform_default_populate (dev->dev.of_node,NULL , &dev->dev);This can be devm as well, in this patch.
Quoted 1 line
Not sure I follow.
Use devm resource managed variant.
Best regards,
Krzysztof
Re: [PATCH 3/3] memory: fsl_ifc: Use devm_request_irq and simplify remove
Quoted 15 lines · Krzysztof Kozlowski
Quoted 13 lines · Rosen Penev
Quoted 12 lines · Krzysztof Kozlowski
drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 275
Quoted 8 lines · Rosen Penev
drivers/memory/fsl_ifc.c +1
-7- -err_free_nandirq: -if (fsl_ifc_ctrl_dev->nand_irq >0 ) -free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); -err_free_irq: -free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -return ret; +return of_platform_default_populate (dev->dev.of_node,NULL , &dev->dev);This can be devm as well, in this patch.
Quoted 3 lines
Quoted 1 line
Not sure I follow.
Use devm resource managed variant.
What's the devm version of of_platform_default_populate?
Quoted 3 lines
Best regards,
Krzysztof
Krzysztof Kozlowski
maintainerRe: [PATCH 3/3] memory: fsl_ifc: Use devm_request_irq and simplify remove
Quoted 16 lines · Rosen Penev
Quoted 15 lines · Krzysztof Kozlowski
Quoted 13 lines · Rosen Penev
Quoted 12 lines · Krzysztof Kozlowski
drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 275
Quoted 8 lines · Rosen Penev
drivers/memory/fsl_ifc.c +1
-7- -err_free_nandirq: -if (fsl_ifc_ctrl_dev->nand_irq >0 ) -free_irq (fsl_ifc_ctrl_dev->nand_irq, fsl_ifc_ctrl_dev); -err_free_irq: -free_irq (fsl_ifc_ctrl_dev->irq, fsl_ifc_ctrl_dev); -return ret; +return of_platform_default_populate (dev->dev.of_node,NULL , &dev->dev);This can be devm as well, in this patch.
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Not sure I follow.
Use devm resource managed variant.
What's the devm version of
of_platform_default_populate?
Indeed, "default" variant does not have a devm. Patch is fine.
Best regards,
Krzysztof