Skip to contentSkip to conversation

memory: fsl_ifc: Switch to modern devm and platform IRQ APIs

PATCH In review Rosen Penev 2 participants 11 messages Jul 21 – Sep 10 Memory controller drivers

lore
Share & tools
lore
#0 lore raw

v2 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.
Patch 4 removes of_platform_default_populate.

Rosen Penev (4):
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
memory: fsl_ifc: drop simple-bus emulation

 drivers/memory/fsl_ifc.c | 101 +++++++++++++--------------------------
 1 file changed, 32 insertions(+), 69 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/4 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.

Get IRQs first as they can return a probe defferal error. Helps avoid doing actual work in such a case.

Assisted-by opencode:big-pickle
---
 drivers/memory/fsl_ifc.c | 43 ++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 22 deletions(-)
drivers/memory/fsl_ifc.c +21 -22
index e89e0c6cc4bc..dce94d8b05b9 100644
@@ -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);
@@ -204,9 +202,21 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 	int ret = 0;
 	int version, banks;
 	void __iomem *addr;
+	int nand_irq;
+	int irq;
 
 	dev_info(&dev->dev, "Freescale Integrated Flash Controller\n");
 
+	/* get the Controller level irq */
+	irq = platform_get_irq(dev, 0);
+	if (irq < 0)
+		return irq;
+
+	/* get the nand machine irq */
+	nand_irq = platform_get_irq_optional(dev, 1);
+	if (nand_irq == -EPROBE_DEFER)
+		return nand_irq;
+
 	fsl_ifc_ctrl_dev = devm_kzalloc(&dev->dev, sizeof(*fsl_ifc_ctrl_dev),
 					GFP_KERNEL);
 	if (!fsl_ifc_ctrl_dev)
@@ -246,23 +256,13 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 		addr += PGOFFSET_4K;
 	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) {
-		dev_err(&dev->dev, "failed to get irq resource for IFC\n");
-		ret = -ENODEV;
-		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->irq = irq;
 
 	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 +271,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_unmap_nandirq;
+		goto err;
 	}
 
-	if (fsl_ifc_ctrl_dev->nand_irq) {
+	fsl_ifc_ctrl_dev->nand_irq = nand_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 +293,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.55.0
#2 lore raw

Re: [PATCHv2 1/4] memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API

Quoted 20 lines · Rosen Penev

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.

Get IRQs first as they can return a probe defferal error. Helps avoid doing actual work in such a case.

Assisted-by opencode:big-pickle
---
 drivers/memory/fsl_ifc.c | 43 ++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 22 deletions(-)
drivers/memory/fsl_ifc.c +0 -0
index e89e0c6cc4bc..dce94d8b05b9 100644

drivers/memory/fsl_ifc.c static void fsl_ifc_ctrl_remove(struct platform_device *dev) · line 92

Quoted 5 lines
drivers/memory/fsl_ifc.c +1 -1
@@ -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)

0 is a valid IRQ for Linux, I think.

Quoted 10 lines
drivers/memory/fsl_ifc.c +1 -3
+		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);

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 206

Quoted 5 lines
drivers/memory/fsl_ifc.c +2 -0
@@ -204,9 +202,21 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 	int ret = 0;
 	int version, banks;
 	void __iomem *addr;
+	int nand_irq;
+	int irq;

Why do you need the intermediate variables?

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 212

Quoted 6 lines
drivers/memory/fsl_ifc.c +3 -0
 	dev_info(&dev->dev, "Freescale Integrated Flash Controller\n");
 
+	/* get the Controller level irq */
+	irq = platform_get_irq(dev, 0);
+	if (irq < 0)

... as also shown here.

Quoted 37 lines
drivers/memory/fsl_ifc.c +9 -12
+		return irq;
+
+	/* get the nand machine irq */
+	nand_irq = platform_get_irq_optional(dev, 1);
+	if (nand_irq == -EPROBE_DEFER)
+		return nand_irq;
+
 	fsl_ifc_ctrl_dev = devm_kzalloc(&dev->dev, sizeof(*fsl_ifc_ctrl_dev),
 					GFP_KERNEL);
 	if (!fsl_ifc_ctrl_dev)
@@ -246,23 +256,13 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 		addr += PGOFFSET_4K;
 	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) {
-		dev_err(&dev->dev, "failed to get irq resource for IFC\n");
-		ret = -ENODEV;
-		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->irq = irq;
 
 	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);
 

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 278

Quoted 10 lines
drivers/memory/fsl_ifc.c +3 -2
@@ -271,10 +271,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_unmap_nandirq;
+		goto err;
 	}
 
-	if (fsl_ifc_ctrl_dev->nand_irq) {
+	fsl_ifc_ctrl_dev->nand_irq = nand_irq;
+	if (fsl_ifc_ctrl_dev->nand_irq > 0) {

...but not here.

Quoted 8 lines
drivers/memory/fsl_ifc.c +0 -1
 		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 +293,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);

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 302

Quoted 10 lines
drivers/memory/fsl_ifc.c +2 -3
+	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;

Best regards,
Krzysztof

#3 lore raw

Re: [PATCHv2 1/4] memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API

Quoted 24 lines · Krzysztof Kozlowski
Quoted 22 lines · Rosen Penev

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.

Get IRQs first as they can return a probe defferal error. Helps avoid doing actual work in such a case.

Assisted-by opencode:big-pickle
---
 drivers/memory/fsl_ifc.c | 43 ++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 22 deletions(-)
drivers/memory/fsl_ifc.c +0 -0
index e89e0c6cc4bc..dce94d8b05b9 100644
@@ -89,12 +89,10 @@ static void fsl_ifc_ctrl_remove(struct platform_device *dev)
      struct fsl_ifc_ctrl *ctrl = dev_get_drvdata(&dev->dev);
 
Quoted 5 lines

drivers/memory/fsl_ifc.c static void fsl_ifc_ctrl_remove(struct platform_device *dev) · line 92

Quoted 3 lines
drivers/memory/fsl_ifc.c +1 -1
      of_platform_depopulate(&dev->dev);
-     free_irq(ctrl->nand_irq, ctrl);
+     if (ctrl->nand_irq > 0)

0 is a valid IRQ for Linux, I think.

No. platform_get_irq has

WARN(ret == 0, "0 is an invalid IRQ number\n")

and 0 is an error with irq_of_parse_and_map.

Quoted 9 lines
Quoted 9 lines
drivers/memory/fsl_ifc.c +1 -3
+             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);
 
Quoted 9 lines

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 206

Quoted 7 lines
drivers/memory/fsl_ifc.c +2 -0
      dev_set_drvdata(&dev->dev, NULL);
@@ -204,9 +202,21 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
      int ret = 0;
      int version, banks;
      void __iomem *addr;
+     int nand_irq;
+     int irq;

Why do you need the intermediate variables?

In order to call platform_get_irq before any allocation happens in probe.

Quoted 54 lines

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 212

Quoted 7 lines
drivers/memory/fsl_ifc.c +3 -0
      dev_info(&dev->dev, "Freescale Integrated Flash Controller\n");
 
+     /* get the Controller level irq */
+     irq = platform_get_irq(dev, 0);
+     if (irq < 0)

... as also shown here.

Quoted 44 lines
drivers/memory/fsl_ifc.c +10 -13
+             return irq;
+
+     /* get the nand machine irq */
+     nand_irq = platform_get_irq_optional(dev, 1);
+     if (nand_irq == -EPROBE_DEFER)
+             return nand_irq;
+
      fsl_ifc_ctrl_dev = devm_kzalloc(&dev->dev, sizeof(*fsl_ifc_ctrl_dev),
                                      GFP_KERNEL);
      if (!fsl_ifc_ctrl_dev)
@@ -246,23 +256,13 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
              addr += PGOFFSET_4K;
      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) {
-             dev_err(&dev->dev, "failed to get irq resource for IFC\n");
-             ret = -ENODEV;
-             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->irq = irq;
 
      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 +271,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_unmap_nandirq;
+             goto err;
      }
 
Quoted 5 lines

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 278

Quoted 3 lines
drivers/memory/fsl_ifc.c +2 -1
-     if (fsl_ifc_ctrl_dev->nand_irq) {
+     fsl_ifc_ctrl_dev->nand_irq = nand_irq;
+     if (fsl_ifc_ctrl_dev->nand_irq > 0) {

...but not here.

Will fix.

Quoted 23 lines
Quoted 9 lines
drivers/memory/fsl_ifc.c +0 -1
              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 +293,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);

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 302

Quoted 10 lines
drivers/memory/fsl_ifc.c +2 -3
+     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;

Best regards,
Krzysztof

#4 lore raw

Re: [PATCHv2 1/4] memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API

Quoted 10 lines · Rosen Penev
Quoted 9 lines · Krzysztof Kozlowski

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 206

Quoted 7 lines
      dev_set_drvdata(&dev->dev, NULL);
drivers/memory/fsl_ifc.c +2 -0
@@ -204,9 +202,21 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
      int ret = 0;
      int version, banks;
      void __iomem *addr;
+     int nand_irq;
+     int irq;

Why do you need the intermediate variables?

Quoted 2 lines

In order to call platform_get_irq before any allocation happens in probe.

Quoted 1 line

But allocation is the first thing the probe is doing.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCHv2 1/4] memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API

Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · Rosen Penev
Quoted 9 lines · Krzysztof Kozlowski

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 206

Quoted 7 lines
      dev_set_drvdata(&dev->dev, NULL);
drivers/memory/fsl_ifc.c +2 -0
@@ -204,9 +202,21 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
      int ret = 0;
      int version, banks;
      void __iomem *addr;
+     int nand_irq;
+     int irq;

Why do you need the intermediate variables?

Quoted 4 lines
Quoted 2 lines

In order to call platform_get_irq before any allocation happens in probe.

Quoted 1 line

But allocation is the first thing the probe is doing.

We're going in circles.

It's better to return -EPROBE_DEFER as early as possible to avoid doing anything.

Quoted 3 lines

Best regards,
Krzysztof

#6 lore raw

Re: [PATCHv2 1/4] memory: fsl_ifc: Fix optional NAND IRQ handling and migrate to platform IRQ API

Quoted 13 lines · Rosen Penev
Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · Rosen Penev
Quoted 9 lines · Krzysztof Kozlowski

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 206

Quoted 7 lines
      dev_set_drvdata(&dev->dev, NULL);
drivers/memory/fsl_ifc.c +2 -0
@@ -204,9 +202,21 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
      int ret = 0;
      int version, banks;
      void __iomem *addr;
+     int nand_irq;
+     int irq;

Why do you need the intermediate variables?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

In order to call platform_get_irq before any allocation happens in probe.

Quoted 1 line

But allocation is the first thing the probe is doing.

We're going in circles.

It's better to return -EPROBE_DEFER as early as possible to avoid doing anything.

Then you would be getting all resources like that in every driver... and we don't. Plus deferred probe on IRQ is highly unlikely.

Best regards,
Krzysztof

#7 lore raw

PATCH v2 2/4 memory: fsl_ifc: Use devm_platform_ioremap_resource and fix error paths

In reply to Rosen Penev

Replace 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.

As one of the errors is -EPROBE_DEFER, run it before anything else to avoid doing actual work in such a case.

Assisted-by opencode:big-pickle
---
 drivers/memory/fsl_ifc.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/memory/fsl_ifc.c +9 -14
index dce94d8b05b9..7e6800fc8480 100644
@@ -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);
 }
 
 /*
@@ -201,6 +197,7 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 {
 	int ret = 0;
 	int version, banks;
+	void __iomem *gregs;
 	void __iomem *addr;
 	int nand_irq;
 	int irq;
@@ -217,6 +214,11 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 	if (nand_irq == -EPROBE_DEFER)
 		return nand_irq;
 
+	/* IOMAP the entire IFC region */
+	gregs = devm_platform_ioremap_resource(dev, 0);
+	if (IS_ERR(gregs))
+		return PTR_ERR(gregs);
+
 	fsl_ifc_ctrl_dev = devm_kzalloc(&dev->dev, sizeof(*fsl_ifc_ctrl_dev),
 					GFP_KERNEL);
 	if (!fsl_ifc_ctrl_dev)
@@ -224,12 +226,7 @@ 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 = gregs;
 
 	if (of_property_read_bool(dev->dev.of_node, "little-endian")) {
 		fsl_ifc_ctrl_dev->little_endian = true;
@@ -262,7 +259,7 @@ static int fsl_ifc_ctrl_probe(struct platform_device *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);
 
@@ -271,7 +268,7 @@ 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;
 	}
 
 	fsl_ifc_ctrl_dev->nand_irq = nand_irq;
@@ -297,8 +294,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.55.0
#8 lore raw

Re: [PATCHv2 2/4] memory: fsl_ifc: Use devm_platform_ioremap_resource and fix error paths

Quoted 32 lines · Rosen Penev

Replace 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.

As one of the errors is -EPROBE_DEFER, run it before anything else to avoid doing actual work in such a case.

Assisted-by opencode:big-pickle
---
 drivers/memory/fsl_ifc.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/memory/fsl_ifc.c +0 -4
index dce94d8b05b9..7e6800fc8480 100644
@@ -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);
 }
 
 /*

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 200

Quoted 4 lines
drivers/memory/fsl_ifc.c +1 -0
@@ -201,6 +197,7 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 {
 	int ret = 0;
 	int version, banks;
+	void __iomem *gregs;

Why another local variable?

Quoted 16 lines
drivers/memory/fsl_ifc.c +5 -0
 	void __iomem *addr;
 	int nand_irq;
 	int irq;
@@ -217,6 +214,11 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 	if (nand_irq == -EPROBE_DEFER)
 		return nand_irq;
 
+	/* IOMAP the entire IFC region */
+	gregs = devm_platform_ioremap_resource(dev, 0);
+	if (IS_ERR(gregs))
+		return PTR_ERR(gregs);
+
 	fsl_ifc_ctrl_dev = devm_kzalloc(&dev->dev, sizeof(*fsl_ifc_ctrl_dev),
 					GFP_KERNEL);
 	if (!fsl_ifc_ctrl_dev)

drivers/memory/fsl_ifc.c static int fsl_ifc_ctrl_probe(struct platform_device *dev) · line 228

Quoted 5 lines
drivers/memory/fsl_ifc.c +0 -2
@@ -224,12 +226,7 @@ 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);

This is not equivalent and commit msg does not address that. Old code allowed multiple maps of the same address space but new code bails with EBUSY.

Again, I asked last time - how did you test it?

Please mark the patches as RFT.

Best regards,
Krzysztof

#9 lore raw

PATCH v2 3/4 memory: fsl_ifc: Use devm_request_irq and simplify remove

In reply to Rosen Penev

Switch 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.

Remove dev_err calls on failure as devm_request_irq() already does this.

Don't bother using the irq variables in the struct. They were only used to free the irqs in _remove.

Assisted-by opencode:big-pickle
---
 drivers/memory/fsl_ifc.c | 47 ++++++++++------------------------------
 1 file changed, 12 insertions(+), 35 deletions(-)
drivers/memory/fsl_ifc.c +12 -35
index 7e6800fc8480..7fea6a356b55 100644
@@ -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,8 +248,6 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 		addr += PGOFFSET_4K;
 	fsl_ifc_ctrl_dev->rregs = addr;
 
-	fsl_ifc_ctrl_dev->irq = irq;
-
 	fsl_ifc_ctrl_dev->dev = &dev->dev;
 
 	ret = fsl_ifc_ctrl_init(fsl_ifc_ctrl_dev);
@@ -263,38 +256,22 @@ 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);
-	if (ret != 0) {
-		dev_err(&dev->dev, "failed to install irq (%d)\n",
-			fsl_ifc_ctrl_dev->irq);
-		goto err_free_irq;
-	}
+	ret = devm_request_irq(&dev->dev, irq,
+			       fsl_ifc_ctrl_irq, IRQF_SHARED,
+			       "fsl-ifc", fsl_ifc_ctrl_dev);
+	if (ret)
+		return ret;
 
-	fsl_ifc_ctrl_dev->nand_irq = nand_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) {
-			dev_err(&dev->dev, "failed to install irq (%d)\n",
-				fsl_ifc_ctrl_dev->nand_irq);
-			goto err_free_irq;
-		}
+	if (nand_irq > 0) {
+		ret = devm_request_irq(&dev->dev,
+				       nand_irq, fsl_ifc_nand_irq, 0,
+				       "fsl-ifc-nand", fsl_ifc_ctrl_dev);
+		if (ret)
+			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.55.0
#10 lore raw

PATCH v2 4/4 memory: fsl_ifc: drop simple-bus emulation

In reply to Rosen Penev

of_platform_default_populate() in fsl_ifc_ctrl_probe() was a workaround for legacy device trees that lacked "simple-bus" on the IFC node. Commit 103478597591 ("powerpc/85xx: Add fsl,ifc to common device ids") ensures the IFC node is populated as a platform device via of_platform_bus_probe(), so the driver no longer needs to manually populate its children -- they are handled by their own dedicated drivers (NAND, NOR, etc.) matching on their own compatibles.

Drop the of_platform_default_populate() call and the corresponding of_platform_depopulate() in fsl_ifc_ctrl_remove(), which is now dead code and can be removed entirely.

Assisted-by opencode:big-pickle
---
 drivers/memory/fsl_ifc.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/memory/fsl_ifc.c +1 -9
index 7fea6a356b55..c591b89a1dd4 100644
@@ -15,7 +15,6 @@
 #include <linux/slab.h>
 #include <linux/io.h>
 #include <linux/of.h>
-#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/fsl_ifc.h>
 #include <linux/irqdomain.h>
@@ -84,11 +83,6 @@ static int fsl_ifc_ctrl_init(struct fsl_ifc_ctrl *ctrl)
 	return 0;
 }
 
-static void fsl_ifc_ctrl_remove(struct platform_device *dev)
-{
-	of_platform_depopulate(&dev->dev);
-}
-
 /*
  * NAND events are split between an operational interrupt which only
  * receives OPC, and an error interrupt that receives everything else,
@@ -270,8 +264,7 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 			return ret;
 	}
 
-	/* legacy dts may still use "simple-bus" compatible */
-	return of_platform_default_populate(dev->dev.of_node, NULL, &dev->dev);
+	return 0;
 }
 
 static const struct of_device_id fsl_ifc_match[] = {
@@ -287,7 +280,6 @@ static struct platform_driver fsl_ifc_ctrl_driver = {
 		.of_match_table = fsl_ifc_match,
 	},
 	.probe       = fsl_ifc_ctrl_probe,
-	.remove  = fsl_ifc_ctrl_remove,
 };
 
 static int __init fsl_ifc_init(void)
Signature · 1 line
2.55.0