diff mbox series

rtc: pic32: Add error handling in pic32_rtc_probe()

Message ID 20221122121721.1647168-1-cuigaosheng1@huawei.com
State Superseded
Headers show
Series rtc: pic32: Add error handling in pic32_rtc_probe() | expand

Commit Message

cuigaosheng Nov. 22, 2022, 12:17 p.m. UTC
The pic32_rtc_enable(pdata, 0) and clk_disable_unprepare(pdata->clk)
should be called in the error handling of devm_rtc_allocate_device(),
fix it.

Fixes: 6515e23b9fde ("rtc: pic32: convert to devm_rtc_allocate_device")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/rtc/rtc-pic32.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Alexandre Belloni Nov. 22, 2022, 1:47 p.m. UTC | #1
On 22/11/2022 20:17:21+0800, Gaosheng Cui wrote:
> The pic32_rtc_enable(pdata, 0) and clk_disable_unprepare(pdata->clk)
> should be called in the error handling of devm_rtc_allocate_device(),
> fix it.
> 
> Fixes: 6515e23b9fde ("rtc: pic32: convert to devm_rtc_allocate_device")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
>  drivers/rtc/rtc-pic32.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-pic32.c b/drivers/rtc/rtc-pic32.c
> index 7fb9145c43bd..258136e3fe96 100644
> --- a/drivers/rtc/rtc-pic32.c
> +++ b/drivers/rtc/rtc-pic32.c
> @@ -331,8 +331,10 @@ static int pic32_rtc_probe(struct platform_device *pdev)
>  	device_init_wakeup(&pdev->dev, 1);
>  
>  	pdata->rtc = devm_rtc_allocate_device(&pdev->dev);

A better solution is to move this call earlier in .probe

> -	if (IS_ERR(pdata->rtc))
> -		return PTR_ERR(pdata->rtc);
> +	if (IS_ERR(pdata->rtc)) {
> +		ret = PTR_ERR(pdata->rtc);
> +		goto err_nortc;
> +	}
>  
>  	pdata->rtc->ops = &pic32_rtcops;
>  	pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-pic32.c b/drivers/rtc/rtc-pic32.c
index 7fb9145c43bd..258136e3fe96 100644
--- a/drivers/rtc/rtc-pic32.c
+++ b/drivers/rtc/rtc-pic32.c
@@ -331,8 +331,10 @@  static int pic32_rtc_probe(struct platform_device *pdev)
 	device_init_wakeup(&pdev->dev, 1);
 
 	pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
-	if (IS_ERR(pdata->rtc))
-		return PTR_ERR(pdata->rtc);
+	if (IS_ERR(pdata->rtc)) {
+		ret = PTR_ERR(pdata->rtc);
+		goto err_nortc;
+	}
 
 	pdata->rtc->ops = &pic32_rtcops;
 	pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;