pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()
Subsystems (4)
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.
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
@@ -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 ); }
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 notERR_PTR(). TheIS_ERR()test in the return value check should be replaced with NULL test.Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple
IORESOURCE_MEMfor one pin-bank")Signed-off-by Wei Yongjun <[email protected]>--- drivers/pinctrl/samsung/pinctrl-samsung.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pinctrl/samsung/pinctrl-samsung.c +0
-0
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
PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()
In reply to Wei YongjunFrom: 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.
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
@@ -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;
Krzysztof Kozlowski
maintainerPATCH 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 notERR_PTR(). Fix by usingdevm_ioremap_resourceinstead ofdevm_ioremap.
Quoted 8 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple
IORESOURCE_MEMfor one pin-bank")Signed-off-by Wei Yongjun <[email protected]>---
v1 -> v2: usedevm_ioremap_resourceinstead ofdevm_ioremap--- drivers/pinctrl/samsung/pinctrl-samsung.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Best regards,
Krzysztof
PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()
In reply to Wei YongjunQuoted 10 lines · Wei Yongjun
From: Wei Yongjun <[email protected]>
In case of error, the function
devm_ioremap()returns NULL pointer notERR_PTR(). Fix by usingdevm_ioremap_resourceinstead ofdevm_ioremap.Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple
IORESOURCE_MEMfor one pin-bank")Signed-off-by Wei Yongjun <[email protected]>---
v1 -> v2: usedevm_ioremap_resourceinstead ofdevm_ioremap
Patch applied with Krzysztof's ACK.
Yours,
Linus Walleij
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 notERR_PTR(). Fix by usingdevm_ioremap_resourceinstead ofdevm_ioremap.
Quoted 6 lines
Quoted 5 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple
IORESOURCE_MEMfor one pin-bank")Signed-off-by Wei Yongjun <[email protected]>---
v1 -> v2: usedevm_ioremap_resourceinstead ofdevm_ioremapPatch 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
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 notERR_PTR(). Fix by usingdevm_ioremap_resourceinstead ofdevm_ioremap.Quoted 7 lines
Quoted 5 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple
IORESOURCE_MEMfor one pin-bank")Signed-off-by Wei Yongjun <[email protected]>---
v1 -> v2: usedevm_ioremap_resourceinstead ofdevm_ioremapPatch 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 ofdevm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x110900000x1000> range in their reg property.devm_ioremap_resource()maps given resource exclusively for the device, whiledevm_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
Krzysztof Kozlowski
maintainerPATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()
In reply to Marek SzyprowskiQuoted 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 notERR_PTR(). Fix by usingdevm_ioremap_resourceinstead ofdevm_ioremap.Quoted 7 lines
Quoted 5 lines
Fixes 8b1bd11c1f8f ("pinctrl: samsung: Add the support the multiple
IORESOURCE_MEMfor one pin-bank")Signed-off-by Wei Yongjun <[email protected]>---
v1 -> v2: usedevm_ioremap_resourceinstead ofdevm_ioremapPatch 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 ofdevm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x110900000x1000> range in their reg property.devm_ioremap_resource()maps given resource exclusively for the device, whiledevm_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
PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()
In reply to Marek SzyprowskiQuoted 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 ofdevm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x110900000x1000> range in their reg property.devm_ioremap_resource()maps given resource exclusively for the device, whiledevm_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
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 ofdevm_ioremap(). The problem here is that registers for IMEM and ALIVE pin controllers are shared and both devices have <0x110900000x1000> range in their reg property.devm_ioremap_resource()maps given resource exclusively for the device, whiledevm_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
PATCH v2 1/1 pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()
Quoted 3 lines · Andrzej Hajda
I have posted proper fix some times ago[1], no need to revert.
[1]: https://www.spinics.net/lists/linux-samsung-soc/msg58395.html
OK fixed that now.
Unreverted the revert, applied your patch.
Yours,
Linus Walleij