diff mbox series

[-next] i2c: efm32: Use devm_platform_get_and_ioremap_resource()

Message ID 20200918082508.32427-1-bobo.shaobowang@huawei.com
State Accepted
Commit 795ee9b8a1076915c3b08eb73cf9fd4da9c52ae6
Headers show
Series [-next] i2c: efm32: Use devm_platform_get_and_ioremap_resource() | expand

Commit Message

Wangshaobo (bobo) Sept. 18, 2020, 8:25 a.m. UTC
Make use of devm_platform_get_and_ioremap_resource() provided by
driver core platform instead of duplicated analogue. dev_err() is
removed because it has been done in devm_ioremap_resource().

Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>
---
 drivers/i2c/busses/i2c-efm32.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Uwe Kleine-König Sept. 18, 2020, 9:20 a.m. UTC | #1
On Fri, Sep 18, 2020 at 04:25:08PM +0800, Wang ShaoBo wrote:
> Make use of devm_platform_get_and_ioremap_resource() provided by

> driver core platform instead of duplicated analogue. dev_err() is

> removed because it has been done in devm_ioremap_resource().

> 

> Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>

> ---

>  drivers/i2c/busses/i2c-efm32.c | 12 +++---------

>  1 file changed, 3 insertions(+), 9 deletions(-)

> 

> diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c

> index 838ce0947191..f6e13ceeb2b3 100644

> --- a/drivers/i2c/busses/i2c-efm32.c

> +++ b/drivers/i2c/busses/i2c-efm32.c

> @@ -332,21 +332,15 @@ static int efm32_i2c_probe(struct platform_device *pdev)

>  		return ret;

>  	}

>  

> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

> -	if (!res) {

> -		dev_err(&pdev->dev, "failed to determine base address\n");

> -		return -ENODEV;

> -	}

> +	ddata->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);

> +	if (IS_ERR(ddata->base))

> +		return PTR_ERR(ddata->base);

>  

>  	if (resource_size(res) < 0x42) {

>  		dev_err(&pdev->dev, "memory resource too small\n");

>  		return -EINVAL;

>  	}

>  

> -	ddata->base = devm_ioremap_resource(&pdev->dev, res);

> -	if (IS_ERR(ddata->base))

> -		return PTR_ERR(ddata->base);

> -

>  	ret = platform_get_irq(pdev, 0);

>  	if (ret <= 0) {

>  		if (!ret)


Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>


Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
Yicong Yang Sept. 18, 2020, 10:01 a.m. UTC | #2
On 2020/9/18 16:25, Wang ShaoBo wrote:
> Make use of devm_platform_get_and_ioremap_resource() provided by
> driver core platform instead of duplicated analogue. dev_err() is
> removed because it has been done in devm_ioremap_resource().
>
> Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>
> ---
>  drivers/i2c/busses/i2c-efm32.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c
> index 838ce0947191..f6e13ceeb2b3 100644
> --- a/drivers/i2c/busses/i2c-efm32.c
> +++ b/drivers/i2c/busses/i2c-efm32.c
> @@ -332,21 +332,15 @@ static int efm32_i2c_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	if (!res) {
> -		dev_err(&pdev->dev, "failed to determine base address\n");
> -		return -ENODEV;
> -	}
> +	ddata->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> +	if (IS_ERR(ddata->base))
> +		return PTR_ERR(ddata->base);
>  
>  	if (resource_size(res) < 0x42) {

res is not assigned. should it be removed?


>  		dev_err(&pdev->dev, "memory resource too small\n");
>  		return -EINVAL;
>  	}
>  
> -	ddata->base = devm_ioremap_resource(&pdev->dev, res);
> -	if (IS_ERR(ddata->base))
> -		return PTR_ERR(ddata->base);
> -
>  	ret = platform_get_irq(pdev, 0);
>  	if (ret <= 0) {
>  		if (!ret)
Wangshaobo (bobo) Sept. 18, 2020, 10:37 a.m. UTC | #3
在 2020/9/18 18:01, Yicong Yang 写道:
> On 2020/9/18 16:25, Wang ShaoBo wrote:

>> Make use of devm_platform_get_and_ioremap_resource() provided by

>> driver core platform instead of duplicated analogue. dev_err() is

>> removed because it has been done in devm_ioremap_resource().

>>

>> Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>

>> ---

>>   drivers/i2c/busses/i2c-efm32.c | 12 +++---------

>>   1 file changed, 3 insertions(+), 9 deletions(-)

>>

>> diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c

>> index 838ce0947191..f6e13ceeb2b3 100644

>> --- a/drivers/i2c/busses/i2c-efm32.c

>> +++ b/drivers/i2c/busses/i2c-efm32.c

>> @@ -332,21 +332,15 @@ static int efm32_i2c_probe(struct platform_device *pdev)

>>   		return ret;

>>   	}

>>   

>> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

>> -	if (!res) {

>> -		dev_err(&pdev->dev, "failed to determine base address\n");

>> -		return -ENODEV;

>> -	}

>> +	ddata->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);

>> +	if (IS_ERR(ddata->base))

>> +		return PTR_ERR(ddata->base);

>>   

>>   	if (resource_size(res) < 0x42) {

> res is not assigned. should it be removed?


I am not sure what you want to ask, but devm_platform_get_and_ioremap_resource() will
assign variable res a value, if it is NULL, internal devm_ioremap_resource() will return error
at the begining, so at this time if(IS_ERR(ddata->base)) true and terminate the process,
which is as same as the original sentences work.

>>   		dev_err(&pdev->dev, "memory resource too small\n");

>>   		return -EINVAL;

>>   	}

>>   

>> -	ddata->base = devm_ioremap_resource(&pdev->dev, res);

>> -	if (IS_ERR(ddata->base))

>> -		return PTR_ERR(ddata->base);

>> -

>>   	ret = platform_get_irq(pdev, 0);

>>   	if (ret <= 0) {

>>   		if (!ret)

> .
Wolfram Sang Sept. 29, 2020, 7:38 p.m. UTC | #4
On Fri, Sep 18, 2020 at 04:25:08PM +0800, Wang ShaoBo wrote:
> Make use of devm_platform_get_and_ioremap_resource() provided by
> driver core platform instead of duplicated analogue. dev_err() is
> removed because it has been done in devm_ioremap_resource().
> 
> Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c
index 838ce0947191..f6e13ceeb2b3 100644
--- a/drivers/i2c/busses/i2c-efm32.c
+++ b/drivers/i2c/busses/i2c-efm32.c
@@ -332,21 +332,15 @@  static int efm32_i2c_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(&pdev->dev, "failed to determine base address\n");
-		return -ENODEV;
-	}
+	ddata->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(ddata->base))
+		return PTR_ERR(ddata->base);
 
 	if (resource_size(res) < 0x42) {
 		dev_err(&pdev->dev, "memory resource too small\n");
 		return -EINVAL;
 	}
 
-	ddata->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(ddata->base))
-		return PTR_ERR(ddata->base);
-
 	ret = platform_get_irq(pdev, 0);
 	if (ret <= 0) {
 		if (!ret)