Skip to contentSkip to conversation

pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

PATCH Superseded Wei Yongjun 6 participants 11 messages Jan 25, 2017 – Mar 15, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/samsung/pinctrl-samsung.c +1 -1
index 3bc925f..9c03eab 100644
@@ -1009,7 +1009,7 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
 		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
 		virt_base[i] = devm_ioremap(&pdev->dev, res->start,
 						resource_size(res));
-		if (IS_ERR(virt_base[i]))
+		if (!virt_base[i])
 			return ERR_PTR(-EIO);
 	}
#1 lore raw

PATCH 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

Hi Wei,

2017-01-25 23:03 GMT+09:00 Wei Yongjun <[email protected]>:

Quoted 18 lines

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/samsung/pinctrl-samsung.c +0 -0
index 3bc925f..9c03eab 100644

drivers/pinctrl/samsung/pinctrl-samsung.c samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, · line 1012

Quoted 5 lines
drivers/pinctrl/samsung/pinctrl-samsung.c +1 -1
@@ -1009,7 +1009,7 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
                res = platform_get_resource(pdev, IORESOURCE_MEM, i);
                virt_base[i] = devm_ioremap(&pdev->dev, res->start,
                                                resource_size(res));
-               if (IS_ERR(virt_base[i]))
+               if (!virt_base[i])

I'd rather replace devm_ioremap() (and explicit resource struct dereferencing, without any checks by the way), with devm_ioremap_resource() (which actually returns ERR_PTR()s, so no need to change the condition with it).

Best regards,
Tomasz

#2 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

In reply to Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). Fix by using devm_ioremap_resource instead of devm_ioremap.

Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
v1 -> v2: use devm_ioremap_resource instead of devm_ioremap

---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pinctrl/samsung/pinctrl-samsung.c +2 -3
index d79eada..6dec061 100644
@@ -988,10 +988,9 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
 
 	for (i = 0; i < ctrl->nr_ext_resources + 1; i++) {
 		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-		virt_base[i] = devm_ioremap(&pdev->dev, res->start,
-						resource_size(res));
+		virt_base[i] = devm_ioremap_resource(&pdev->dev, res);
 		if (IS_ERR(virt_base[i]))
-			return ERR_PTR(-EIO);
+			return ERR_CAST(virt_base[i]);
 	}
 
 	bank = d->pin_banks;
#3 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

Quoted 5 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). Fix by using devm_ioremap_resource instead of devm_ioremap.

Quoted 8 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
v1 -> v2: use devm_ioremap_resource instead of devm_ioremap

---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Best regards,
Krzysztof

#4 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

In reply to Wei Yongjun
Quoted 10 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). Fix by using devm_ioremap_resource instead of devm_ioremap.

Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
v1 -> v2: use devm_ioremap_resource instead of devm_ioremap

Patch applied with Krzysztof's ACK.

Yours,
Linus Walleij

#5 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

Hi All,

Quoted 7 lines · Linus Walleij
Quoted 5 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). Fix by using devm_ioremap_resource instead of devm_ioremap.

Quoted 6 lines
Quoted 5 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
v1 -> v2: use devm_ioremap_resource instead of devm_ioremap

Patch applied with Krzysztof's ACK.

Sadly this patch breaks support for IMEM pinctrl block on Exynos5433/TM2 and it took us some time to find the source of the problem.

devm_ioremap_resource() is not functionally a full equivalent of devm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x11090000 0x1000> range in their reg property. devm_ioremap_resource() maps given resource exclusively for the device, while devm_ioremap() allows non-exclusive mappings.

This patch has to be reverted asap.

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#6 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

2017-02-21 22:49 GMT+09:00 Marek Szyprowski <[email protected]>:

Quoted 23 lines

Hi All,

Quoted 8 lines · Linus Walleij
Quoted 5 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). Fix by using devm_ioremap_resource instead of devm_ioremap.

Quoted 7 lines
Quoted 5 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
v1 -> v2: use devm_ioremap_resource instead of devm_ioremap

Patch applied with Krzysztof's ACK.

Sadly this patch breaks support for IMEM pinctrl block on Exynos5433/TM2 and it took us some time to find the source of the problem.

Quoted 8 lines

devm_ioremap_resource() is not functionally a full equivalent of devm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x11090000 0x1000> range in their reg property. devm_ioremap_resource() maps given resource exclusively for the device, while devm_ioremap() allows non-exclusive mappings.

This patch has to be reverted asap.

Are IMEM and ALIVE pincontrollers really separate then? Typically one models the hardware as different blocks when the registers are separate and that's also why devm_ioremap_resource() behaves like it does. Maybe in this case there should be only one pin controller defined instead?

In any case, I agree that the patch should be reverted for now.

Best regards,
Tomasz

#7 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

In reply to Marek Szyprowski
Quoted 23 lines · Marek Szyprowski

Hi All,

Quoted 8 lines · Linus Walleij
Quoted 5 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap() returns NULL pointer not ERR_PTR(). Fix by using devm_ioremap_resource instead of devm_ioremap.

Quoted 7 lines
Quoted 5 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple

IORESOURCE_MEM for one pin-bank")

---
v1 -> v2: use devm_ioremap_resource instead of devm_ioremap

Patch applied with Krzysztof's ACK.

Sadly this patch breaks support for IMEM pinctrl block on Exynos5433/TM2 and it took us some time to find the source of the problem.

Quoted 8 lines

devm_ioremap_resource() is not functionally a full equivalent of devm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x11090000 0x1000> range in their reg property. devm_ioremap_resource() maps given resource exclusively for the device, while devm_ioremap() allows non-exclusive mappings.

This patch has to be reverted asap.

Damn, the additional request_mem_region() raised my concerns but I didn't compare it with actual DTS layout... Which brings us to two important lessons:
1. Do not accept untested code.
2. Do not fix two things at the same time.

I vote for the revert as well + original version of patch (these two could be squashed) + a need of Tested-by. Otherwise an untested fix might not be a fix at all.

Best regards,
Krzysztof

#8 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

In reply to Marek Szyprowski
Quoted 11 lines · Marek Szyprowski

Sadly this patch breaks support for IMEM pinctrl block on Exynos5433/TM2 and it took us some time to find the source of the problem.

devm_ioremap_resource() is not functionally a full equivalent of devm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x11090000 0x1000> range in their reg property. devm_ioremap_resource() maps given resource exclusively for the device, while devm_ioremap() allows non-exclusive mappings.

This patch has to be reverted asap.

Patch reverted for fixes, copying the above text as commit message.

Yours,
Linus Walleij

#9 lore raw

PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()

Hi Linus,

I have posted proper fix some times ago[1], no need to revert.

[1]: https://www.spinics.net/lists/linux-samsung-soc/msg58395.html

Regards
Andrzej

Quoted 21 lines · Linus Walleij
Quoted 11 lines · Marek Szyprowski

Sadly this patch breaks support for IMEM pinctrl block on Exynos5433/TM2 and it took us some time to find the source of the problem.

devm_ioremap_resource() is not functionally a full equivalent of devm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x11090000 0x1000> range in their reg property. devm_ioremap_resource() maps given resource exclusively for the device, while devm_ioremap() allows non-exclusive mappings.

This patch has to be reverted asap.

Patch reverted for fixes, copying the above text as commit message.

Yours,
Linus Walleij