Skip to contentSkip to conversation

Revert "pinctrl: freescale: imx: Use 'devm_of_iomap()' to avoid a resource leak in case of error in 'imx_pinctrl_probe()'"

PATCH Superseded [email protected] 6 participants 12 messages Jun 8, 2020 – Jun 9, 2020

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "pinctrl: freescale: imx: Use 'devm_of_iomap()' to avoid a resource leak in case of error in 'imx_pinctrl_probe()'"

From: Haibo Chen <[email protected]>

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx.c +3 -4
index cb7e0f08d2cf..1f81569c7ae3 100644
@@ -824,13 +824,12 @@ int imx_pinctrl_probe(struct platform_device *pdev,
 				return -EINVAL;
 			}
 
-			ipctl->input_sel_base = devm_of_iomap(&pdev->dev, np,
-							      0, NULL);
+			ipctl->input_sel_base = of_iomap(np, 0);
 			of_node_put(np);
-			if (IS_ERR(ipctl->input_sel_base)) {
+			if (!ipctl->input_sel_base) {
 				dev_err(&pdev->dev,
 					"iomuxc input select base address not found\n");
-				return PTR_ERR(ipctl->input_sel_base);
+				return -ENOMEM;
 			}
 		}
 	}
Signature · 1 line
2.17.1
author
#1 lore raw

+ [email protected]

Quoted 52 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 2020年6月8日 18:00
To: Aisheng Dong <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Cc: [email protected]; BOUGH CHEN <[email protected]>
Subject: [PATCH] Revert "pinctrl: freescale: imx: Use 'devm_of_iomap()' to avoid a resource leak in case of error in 'imx_pinctrl_probe()'"

From: Haibo Chen <[email protected]>

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx.c +3 -5
index cb7e0f08d2cf..1f81569c7ae3 100644
@@ -824,13 +824,12 @@ int imx_pinctrl_probe(struct platform_device *pdev,
 				return -EINVAL;
 			}
 
-			ipctl->input_sel_base = devm_of_iomap(&pdev->dev, np,
-							      0, NULL);
+			ipctl->input_sel_base = of_iomap(np, 0);
 			of_node_put(np);
-			if (IS_ERR(ipctl->input_sel_base)) {
+			if (!ipctl->input_sel_base) {
 				dev_err(&pdev->dev,
 					"iomuxc input select base address not found\n");
-				return PTR_ERR(ipctl->input_sel_base);
+				return -ENOMEM;
 			}
 		}
 	}
--

2.17.1

maintainer
#2 lore raw
In reply to [email protected]

Hi Haibo,

Quoted 7 lines · On Mon, Jun 8, 2020 at 7:10 AM <[email protected]> wrote:

From: Haibo Chen <[email protected]>

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

Quoted 5 lines
[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

You missed your Signed-off-by tag.

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to [email protected]
Quoted 7 lines

From: [email protected] <[email protected]>
Sent: Monday, June 8, 2020 6:00 PM

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

Quoted 7 lines
[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

Better add your sign-off.
Otherwise:

Maybe you or Christophe could resubmit another proper fix for the original issue.

Regards
Aisheng

Quoted 28 lines
---
 drivers/pinctrl/freescale/pinctrl-imx.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx.c +3 -5
index cb7e0f08d2cf..1f81569c7ae3 100644
@@ -824,13 +824,12 @@ int imx_pinctrl_probe(struct platform_device *pdev,
 				return -EINVAL;
 			}
 
-			ipctl->input_sel_base = devm_of_iomap(&pdev->dev, np,
-							      0, NULL);
+			ipctl->input_sel_base = of_iomap(np, 0);
 			of_node_put(np);
-			if (IS_ERR(ipctl->input_sel_base)) {
+			if (!ipctl->input_sel_base) {
 				dev_err(&pdev->dev,
 					"iomuxc input select base address not found\n");
-				return PTR_ERR(ipctl->input_sel_base);
+				return -ENOMEM;
 			}
 		}
 	}
--

2.17.1

#4 lore raw
Quoted 13 lines · Aisheng Dong
Quoted 13 lines

From: [email protected] <[email protected]>
Sent: Monday, June 8, 2020 6:00 PM

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16
Quoted 7 lines
Quoted 1 line

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

Better add your sign-off.
Otherwise:

Maybe you or Christophe could resubmit another proper fix for the original issue.

I'm really sorry about that. This was largely my fault.

I still don't understand how commit ba403242615c caused a problem.

It sounds like in the original code ipctl->input_sel_base was released somehow? I do a git grep input_sel_base and it doesn't show anything. What am I missing?

regards,
dan carpenter

author
#5 lore raw
Quoted 37 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: 2020年6月8日 22:45
To: Aisheng Dong <[email protected]>
Cc: BOUGH CHEN <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Christophe JAILLET <[email protected]>; [email protected]
Subject: Re: [PATCH] Revert "pinctrl: freescale: imx: Use 'devm_of_iomap()' to avoid a resource leak in case of error in 'imx_pinctrl_probe()'"

Quoted 7 lines · Aisheng Dong
Quoted 7 lines

From: [email protected] <[email protected]>
Sent: Monday, June 8, 2020 6:00 PM

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

Quoted 5 lines
Quoted 5 lines
[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error

-16

Quoted 8 lines
Quoted 2 lines

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

Better add your sign-off.
Otherwise:

Maybe you or Christophe could resubmit another proper fix for the original

issue.

Quoted 8 lines

I'm really sorry about that. This was largely my fault.

I still don't understand how commit ba403242615c caused a problem.

It sounds like in the original code ipctl->input_sel_base was released somehow? I do a git grep input_sel_base and it doesn't show anything. What am I missing?

Hi Dan,

I can give you a detail explain why this patch trigger issues. Take our imx7d-sdb board as example, in dts file we can see to nodes:
440 iomuxc_lpsr: iomuxc-lpsr@302c0000 {

441                                 compatible = "fsl,imx7d-iomuxc-lpsr";
442                                 reg = <0x302c0000 0x10000>;
443                                 fsl,input-sel = <&iomuxc>;

444 };
And
493 iomuxc: pinctrl@30330000 {
494 compatible = "fsl,imx7d-iomuxc";
495 reg = <0x30330000 0x10000>;
496 };

First time when probe the iomuxc_lpsr, due to it has "fsl,input-sel", so in the pinctrl driver, it will use API devm_of_iomap() to handle the iomuxc for the first time. Devm_of_iomap() use the API devm_request_mem_region() for the region <0x30330000-0x3033ffff>. Then, when probe the iomuxc, the pinctrl driver call the API devm_platform_ioremap_resource(), this API also call the devm_request_mem_region() for the same region <0x30330000-0x3033ffff>.
So we see the log as following:

[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16

I will send a V2 patch to add my sign-off-by and fix tag.

Best Regards
Haibo Chen

Quoted 2 lines

regards,
dan carpenter

#6 lore raw
In reply to Aisheng Dong
Quoted 7 lines · Aisheng Dong
Quoted 7 lines

From: [email protected] <[email protected]>
Sent: Monday, June 8, 2020 6:00 PM

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

Quoted 7 lines
Quoted 7 lines
[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

Btw, the git revert command really sets you up for failure by generating a patch in the wrong format. You did well to write a good commit message. I would probably also change the subject, the From:
header and add a Fixes tag and a Signed-off by. The Fixes tag should be:

Fixes ba403242615c ("pinctrl: freescale: imx: Use 'devm_of_iomap()' to avoid a resource leak in case of error in 'imx_pinctrl_probe()'")

regards,
dan carpenter

maintainer
#7 lore raw
Quoted 20 lines

From: Dan Carpenter <[email protected]>
Sent: Monday, June 8, 2020 10:49 PM

Quoted 7 lines · Aisheng Dong
Quoted 7 lines

From: [email protected] <[email protected]>
Sent: Monday, June 8, 2020 6:00 PM

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

Quoted 5 lines
Quoted 5 lines
[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error

-16

Quoted 2 lines
Quoted 2 lines

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

Quoted 9 lines

Btw, the git revert command really sets you up for failure by generating a patch in the wrong format. You did well to write a good commit message. I would probably also change the subject, the From:
header and add a Fixes tag and a Signed-off by. The Fixes tag should be:

Fixes ba403242615c ("pinctrl: freescale: imx: Use 'devm_of_iomap()' to avoid a

resource leak in case of error in 'imx_pinctrl_probe()'")

By searching the kernel log, it seems most people didn't add Fixes tag for a Revert patch. But anyway, I'm fine to add it.
e.g.
commit cf9c94456ebafc6d75a834e58dfdc8ae71a3acbc

Author: Greg Kroah-Hartman <[email protected]>
Date:   Tue May 12 10:22:44 2020 +0200

Revert "tty: hvc: Fix data abort due to race in hvc_open"

This reverts commit e2bd1dcbe1aa34ff5570b3427c530e4332ecf0fe.

In discussion on the mailing list, it has been determined that this is not the correct type of fix for this issue. Revert it so that we can do this correctly.

Regards
Aisheng

Quoted 2 lines

regards,
dan carpenter

#8 lore raw
Quoted 26 lines · Aisheng Dong
Quoted 26 lines

From: Dan Carpenter <[email protected]>
Sent: Monday, June 8, 2020 10:49 PM

Quoted 7 lines · Aisheng Dong
Quoted 7 lines

From: [email protected] <[email protected]>
Sent: Monday, June 8, 2020 6:00 PM

This patch block system booting, find on imx7d-sdb board. From the dts we can see, iomux and iomux_lpsr share the memory region [0x30330000-0x3033ffff], so will trigger the following issue:

Quoted 5 lines
Quoted 5 lines
[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error

-16

Quoted 2 lines
Quoted 2 lines

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

Btw, the git revert command really sets you up for failure by generating a patch in the wrong format. You did well to write a good commit message. I would probably also change the subject, the From:
header and add a Fixes tag and a Signed-off by. The Fixes tag should be:

Quoted 6 lines
Quoted 3 lines
Fixes ba403242615c ("pinctrl: freescale: imx: Use 'devm_of_iomap()' to avoid a

resource leak in case of error in 'imx_pinctrl_probe()'")

By searching the kernel log, it seems most people didn't add Fixes tag for a Revert patch. But anyway, I'm fine to add it.

Yeah. It's really complicated to get revert patches right. The revert command was created 15 years ago and it doesn't match what we expect from commits today. Commit 40da7d9a93c8 ("NTB: Revert the change to use the NTB device dev for DMA allocations") is an example of a well written revert commit.

I'm sort of surprised that patches where the subject starts with Revert don't break Greg's email sorting scripts.

regards,
dan carpenter

#9 lore raw

PATCH 1/1 lib: devres: add a comment about the devm_of_iomap() function

In reply to Aisheng Dong

We recently introduced a bug when we tried to convert of_iomap() to devm_of_iomap(). The problem was that there were two drivers mapping the same io region. The first driver was using of_iomap() and the second driver was using devm_of_iomap() and the kernel booted fine. When we converted the first drive to use devm_of_iomap() then the second driver failed with -EBUSY and the kernel couldn't boot.

Let's add a comment to prevent this sort of mistake in the future.

---
 lib/devres.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/devres.c +6 -0
index 6ef51f159c54b..0abe7c1cc4681 100644
@@ -204,6 +204,12 @@ void __iomem *devm_ioremap_resource_wc(struct device *dev,
  *	base = devm_of_iomap(&pdev->dev, node, 0, NULL);
  *	if (IS_ERR(base))
  *		return PTR_ERR(base);
+ *
+ * Please Note: This is not a one-to-one replacement for of_iomap() because the
+ * of_iomap() function does not track whether the region is already mapped.  If
+ * two drivers try to map the same memory, the of_iomap() function will succeed
+ * but the the devm_of_iomap() function will return -EBUSY.
+ *
  */
 void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index,
 			    resource_size_t *size)
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#10 lore raw

Re: [PATCH] lib: devres: add a comment about the devm_of_iomap() function

Quoted 11 lines · Dan Carpenter

We recently introduced a bug when we tried to convert of_iomap() to devm_of_iomap(). The problem was that there were two drivers mapping the same io region. The first driver was using of_iomap() and the second driver was using devm_of_iomap() and the kernel booted fine. When we converted the first drive to use devm_of_iomap() then the second driver failed with -EBUSY and the kernel couldn't boot.

Let's add a comment to prevent this sort of mistake in the future.

Good idea,

#11 lore raw
In reply to Aisheng Dong

Le 08/06/2020 à 16:06, Aisheng Dong a écrit :

Quoted 13 lines
Quoted 13 lines

From: [email protected] <[email protected]>
Sent: Monday, June 8, 2020 6:00 PM

This patch block system booting, find on imx7d-sdb board.
From the dts we can see, iomux and iomux_lpsr share the memory region
[0x30330000-0x3033ffff], so will trigger the following issue:

[    0.179561] imx7d-pinctrl 302c0000.iomuxc-lpsr: initialized IMX pinctrl
driver
[    0.191742] imx7d-pinctrl 30330000.pinctrl: can't request region for
resource [mem 0x30330000-0x3033ffff]
[    0.191842] imx7d-pinctrl: probe of 30330000.pinctrl failed with error -16
Quoted 4 lines
Quoted 1 line

This reverts commit ba403242615c2c99e27af7984b1650771a2cc2c9.

Better add your sign-off.
Otherwise:

You can also add a "Apologies-From:" tag with my name :). Sorry for this bogus patch.

CJ

Quoted 33 lines

Maybe you or Christophe could resubmit another proper fix for the original issue.

Regards
Aisheng

Quoted 28 lines
---
  drivers/pinctrl/freescale/pinctrl-imx.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx.c +3 -5
index cb7e0f08d2cf..1f81569c7ae3 100644
@@ -824,13 +824,12 @@ int imx_pinctrl_probe(struct platform_device *pdev,
  				return -EINVAL;
  			}
 
-			ipctl->input_sel_base = devm_of_iomap(&pdev->dev, np,
-							      0, NULL);
+			ipctl->input_sel_base = of_iomap(np, 0);
  			of_node_put(np);
-			if (IS_ERR(ipctl->input_sel_base)) {
+			if (!ipctl->input_sel_base) {
  				dev_err(&pdev->dev,
  					"iomuxc input select base address not found\n");
-				return PTR_ERR(ipctl->input_sel_base);
+				return -ENOMEM;
  			}
  		}
  	}
--

2.17.1