diff mbox series

[-next,1/2] i2c: mt7621: fix missing clk_disable_unprepare() on error in mtk_i2c_probe()

Message ID 20220513100819.2711845-1-yangyingliang@huawei.com
State Superseded
Headers show
Series [-next,1/2] i2c: mt7621: fix missing clk_disable_unprepare() on error in mtk_i2c_probe() | expand

Commit Message

Yang Yingliang May 13, 2022, 10:08 a.m. UTC
Fix the missing clk_disable_unprepare() before return
from mtk_i2c_probe() in the error handling case.

Fixes: d04913ec5f89 ("i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/i2c/busses/i2c-mt7621.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Stefan Roese May 13, 2022, 12:07 p.m. UTC | #1
On 13.05.22 12:08, Yang Yingliang wrote:
> Fix the missing clk_disable_unprepare() before return
> from mtk_i2c_probe() in the error handling case.
> 
> Fixes: d04913ec5f89 ("i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C driver")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   drivers/i2c/busses/i2c-mt7621.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
> index 45fe4a7fe0c0..f117c3d9ca19 100644
> --- a/drivers/i2c/busses/i2c-mt7621.c
> +++ b/drivers/i2c/busses/i2c-mt7621.c
> @@ -304,7 +304,8 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	if (i2c->bus_freq == 0) {
>   		dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_disable_clk;
>   	}
>   
>   	adap = &i2c->adap;
> @@ -322,10 +323,13 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	ret = i2c_add_adapter(adap);
>   	if (ret < 0)
> -		return ret;
> +		goto err_disable_clk;
>   
>   	dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);
>   
> +err_disable_clk:
> +	clk_disable_unprepare(i2c->clk);
> +
>   	return ret;
>   }
>   

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan
Stefan Roese May 13, 2022, 12:07 p.m. UTC | #2
On 13.05.22 12:08, Yang Yingliang wrote:
> Use devm_platform_get_and_ioremap_resource() to simplify
> code.
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   drivers/i2c/busses/i2c-mt7621.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
> index f117c3d9ca19..0d849379a236 100644
> --- a/drivers/i2c/busses/i2c-mt7621.c
> +++ b/drivers/i2c/busses/i2c-mt7621.c
> @@ -270,18 +270,15 @@ static void mtk_i2c_init(struct mtk_i2c *i2c)
>   
>   static int mtk_i2c_probe(struct platform_device *pdev)
>   {
> -	struct resource *res;
>   	struct mtk_i2c *i2c;
>   	struct i2c_adapter *adap;
>   	int ret;
>   
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -
>   	i2c = devm_kzalloc(&pdev->dev, sizeof(struct mtk_i2c), GFP_KERNEL);
>   	if (!i2c)
>   		return -ENOMEM;
>   
> -	i2c->base = devm_ioremap_resource(&pdev->dev, res);
> +	i2c->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
>   	if (IS_ERR(i2c->base))
>   		return PTR_ERR(i2c->base);
>   

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan
Christophe JAILLET May 13, 2022, 4:15 p.m. UTC | #3
Le 13/05/2022 à 12:08, Yang Yingliang a écrit :
> Fix the missing clk_disable_unprepare() before return
> from mtk_i2c_probe() in the error handling case.
> 
> Fixes: d04913ec5f89 ("i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C driver")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   drivers/i2c/busses/i2c-mt7621.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
> index 45fe4a7fe0c0..f117c3d9ca19 100644
> --- a/drivers/i2c/busses/i2c-mt7621.c
> +++ b/drivers/i2c/busses/i2c-mt7621.c
> @@ -304,7 +304,8 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	if (i2c->bus_freq == 0) {
>   		dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_disable_clk;
>   	}
>   
>   	adap = &i2c->adap;
> @@ -322,10 +323,13 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	ret = i2c_add_adapter(adap);
>   	if (ret < 0)
> -		return ret;
> +		goto err_disable_clk;
>   
>   	dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);

Hi,

should'nt we have a:
	return 0;
here?

otherwise we will call clk_disable_unprepare() even on the normal path.

CJ

>   
> +err_disable_clk:
> +	clk_disable_unprepare(i2c->clk);
> +
>   	return ret;
>   }
>
Yang Yingliang May 14, 2022, 2:11 a.m. UTC | #4
On 2022/5/14 0:15, Christophe JAILLET wrote:
> Le 13/05/2022 à 12:08, Yang Yingliang a écrit :
>> Fix the missing clk_disable_unprepare() before return
>> from mtk_i2c_probe() in the error handling case.
>>
>> Fixes: d04913ec5f89 ("i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C 
>> driver")
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   drivers/i2c/busses/i2c-mt7621.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-mt7621.c 
>> b/drivers/i2c/busses/i2c-mt7621.c
>> index 45fe4a7fe0c0..f117c3d9ca19 100644
>> --- a/drivers/i2c/busses/i2c-mt7621.c
>> +++ b/drivers/i2c/busses/i2c-mt7621.c
>> @@ -304,7 +304,8 @@ static int mtk_i2c_probe(struct platform_device 
>> *pdev)
>>         if (i2c->bus_freq == 0) {
>>           dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
>> -        return -EINVAL;
>> +        ret = -EINVAL;
>> +        goto err_disable_clk;
>>       }
>>         adap = &i2c->adap;
>> @@ -322,10 +323,13 @@ static int mtk_i2c_probe(struct platform_device 
>> *pdev)
>>         ret = i2c_add_adapter(adap);
>>       if (ret < 0)
>> -        return ret;
>> +        goto err_disable_clk;
>>         dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);
>
> Hi,
>
> should'nt we have a:
>     return 0;
> here?
>
> otherwise we will call clk_disable_unprepare() even on the normal path.
Yes, I missed that.

Thanks,
Yang
>
> CJ
>
>>   +err_disable_clk:
>> +    clk_disable_unprepare(i2c->clk);
>> +
>>       return ret;
>>   }
>
> .
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index 45fe4a7fe0c0..f117c3d9ca19 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -304,7 +304,8 @@  static int mtk_i2c_probe(struct platform_device *pdev)
 
 	if (i2c->bus_freq == 0) {
 		dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_disable_clk;
 	}
 
 	adap = &i2c->adap;
@@ -322,10 +323,13 @@  static int mtk_i2c_probe(struct platform_device *pdev)
 
 	ret = i2c_add_adapter(adap);
 	if (ret < 0)
-		return ret;
+		goto err_disable_clk;
 
 	dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);
 
+err_disable_clk:
+	clk_disable_unprepare(i2c->clk);
+
 	return ret;
 }