diff mbox

pinctrl: samsung: Fix memory mapping code

Message ID 1487749442-23806-1-git-send-email-a.hajda@samsung.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Andrzej Hajda Feb. 22, 2017, 7:44 a.m. UTC
Some pinctrls share memory regions, and devm_ioremap_resource does not
allow to share resources, in opposition to devm_ioremap.
This patch restores back usage of devm_ioremap function, but with proper
error handling and logging.

Fixes: baafaca ("pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()")
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Marek Szyprowski Feb. 22, 2017, 7:59 a.m. UTC | #1
Hi,

On 2017-02-22 08:44, Andrzej Hajda wrote:
> Some pinctrls share memory regions, and devm_ioremap_resource does not
> allow to share resources, in opposition to devm_ioremap.
> This patch restores back usage of devm_ioremap function, but with proper
> error handling and logging.
>
> Fixes: baafaca ("pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()")
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
>   drivers/pinctrl/samsung/pinctrl-samsung.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> index f9ddba7..ebecff8 100644
> --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> @@ -988,9 +988,12 @@ 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_resource(&pdev->dev, res);
> -		if (IS_ERR(virt_base[i]))
> -			return ERR_CAST(virt_base[i]);
> +		virt_base[i] = devm_ioremap(&pdev->dev, res->start,
> +						resource_size(res));
> +		if (!virt_base[i]) {
> +			dev_err(&pdev->dev, "failed to ioremap %pR\n", res);
> +			return ERR_PTR(-EIO);
> +		}
>   	}
>   
>   	bank = d->pin_banks;

Best regards
Krzysztof Kozlowski Feb. 22, 2017, 5:02 p.m. UTC | #2
On Wed, Feb 22, 2017 at 08:44:02AM +0100, Andrzej Hajda wrote:
> Some pinctrls share memory regions, and devm_ioremap_resource does not
> allow to share resources, in opposition to devm_ioremap.
> This patch restores back usage of devm_ioremap function, but with proper
> error handling and logging.
> 
> Fixes: baafaca ("pinctrl: samsung: Fix return value check in samsung_pinctrl_get_soc_data()")
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> ---
>  drivers/pinctrl/samsung/pinctrl-samsung.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> index f9ddba7..ebecff8 100644
> --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> @@ -988,9 +988,12 @@ 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_resource(&pdev->dev, res);
> -		if (IS_ERR(virt_base[i]))
> -			return ERR_CAST(virt_base[i]);
> +		virt_base[i] = devm_ioremap(&pdev->dev, res->start,
> +						resource_size(res));

A little bit out of scope of this patch: don't we need here a check
for if (!res)? With devm_ioremap_resource it wasn't needed but
platform_get_resource might return NULL and here you are dereferencing
it.

This might be though a separate patch as you try to revert broken
behavior to previous code.


Best regards,
Krzysztof


> +		if (!virt_base[i]) {
> +			dev_err(&pdev->dev, "failed to ioremap %pR\n", res);
> +			return ERR_PTR(-EIO);
> +		}
>  	}
>  
>  	bank = d->pin_banks;
> -- 
> 2.7.4
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index f9ddba7..ebecff8 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -988,9 +988,12 @@  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_resource(&pdev->dev, res);
-		if (IS_ERR(virt_base[i]))
-			return ERR_CAST(virt_base[i]);
+		virt_base[i] = devm_ioremap(&pdev->dev, res->start,
+						resource_size(res));
+		if (!virt_base[i]) {
+			dev_err(&pdev->dev, "failed to ioremap %pR\n", res);
+			return ERR_PTR(-EIO);
+		}
 	}
 
 	bank = d->pin_banks;