public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] rtc: rtc-twl: Use devm_*() functions
@ 2013-12-05  1:03 Jingoo Han
  2013-12-05  1:05 ` [PATCH 2/2] rtc: rtc-vr41xx: " Jingoo Han
  2013-12-05 16:50 ` [PATCH 1/2] rtc: rtc-twl: " Grygorii Strashko
  0 siblings, 2 replies; 5+ messages in thread
From: Jingoo Han @ 2013-12-05  1:03 UTC (permalink / raw)
  To: 'Andrew Morton'
  Cc: linux-kernel, 'Alessandro Zummo', rtc-linux,
	'Jingoo Han', 'Kevin Hilman',
	'Tony Lindgren', 'Grygorii Strashko',
	'Peter Ujfalusi'

Use devm_*() functions to make cleanup paths simpler, and remove
unnecessary remove().

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
 drivers/rtc/rtc-twl.c |   38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index c2e80d7..1915464 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -479,7 +479,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
 	u8 rd_reg;
 
 	if (irq <= 0)
-		goto out1;
+		return ret;
 
 	/* Initialize the register map */
 	if (twl_class_is_4030())
@@ -489,7 +489,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
 
 	ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
 	if (ret < 0)
-		goto out1;
+		return ret;
 
 	if (rd_reg & BIT_RTC_STATUS_REG_POWER_UP_M)
 		dev_warn(&pdev->dev, "Power up reset detected.\n");
@@ -500,7 +500,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
 	/* Clear RTC Power up reset and pending alarm interrupts */
 	ret = twl_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
 	if (ret < 0)
-		goto out1;
+		return ret;
 
 	if (twl_class_is_6030()) {
 		twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
@@ -512,7 +512,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
 	dev_info(&pdev->dev, "Enabling TWL-RTC\n");
 	ret = twl_rtc_write_u8(BIT_RTC_CTRL_REG_STOP_RTC_M, REG_RTC_CTRL_REG);
 	if (ret < 0)
-		goto out1;
+		return ret;
 
 	/* ensure interrupts are disabled, bootloaders can be strange */
 	ret = twl_rtc_write_u8(0, REG_RTC_INTERRUPTS_REG);
@@ -522,34 +522,29 @@ static int twl_rtc_probe(struct platform_device *pdev)
 	/* init cached IRQ enable bits */
 	ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
 	if (ret < 0)
-		goto out1;
+		return ret;
 
 	device_init_wakeup(&pdev->dev, 1);
 
-	rtc = rtc_device_register(pdev->name,
-				  &pdev->dev, &twl_rtc_ops, THIS_MODULE);
+	rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
+					&twl_rtc_ops, THIS_MODULE);
 	if (IS_ERR(rtc)) {
-		ret = PTR_ERR(rtc);
 		dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
 			PTR_ERR(rtc));
-		goto out1;
+		return PTR_ERR(rtc);
 	}
 
-	ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
-				   IRQF_TRIGGER_RISING | IRQF_ONESHOT,
-				   dev_name(&rtc->dev), rtc);
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					twl_rtc_interrupt,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					dev_name(&rtc->dev), rtc);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "IRQ is not free.\n");
-		goto out2;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, rtc);
 	return 0;
-
-out2:
-	rtc_device_unregister(rtc);
-out1:
-	return ret;
 }
 
 /*
@@ -559,9 +554,6 @@ out1:
 static int twl_rtc_remove(struct platform_device *pdev)
 {
 	/* leave rtc running, but disable irqs */
-	struct rtc_device *rtc = platform_get_drvdata(pdev);
-	int irq = platform_get_irq(pdev, 0);
-
 	mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
 	mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
 	if (twl_class_is_6030()) {
@@ -571,10 +563,6 @@ static int twl_rtc_remove(struct platform_device *pdev)
 			REG_INT_MSK_STS_A);
 	}
 
-
-	free_irq(irq, rtc);
-
-	rtc_device_unregister(rtc);
 	return 0;
 }
 
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] rtc: rtc-vr41xx: Use devm_*() functions
  2013-12-05  1:03 [PATCH 1/2] rtc: rtc-twl: Use devm_*() functions Jingoo Han
@ 2013-12-05  1:05 ` Jingoo Han
  2013-12-05 16:50 ` [PATCH 1/2] rtc: rtc-twl: " Grygorii Strashko
  1 sibling, 0 replies; 5+ messages in thread
From: Jingoo Han @ 2013-12-05  1:05 UTC (permalink / raw)
  To: 'Andrew Morton'
  Cc: linux-kernel, 'Alessandro Zummo', rtc-linux,
	'Jingoo Han', 'Yoichi Yuasa'

Use devm_*() functions to make cleanup paths simpler, and remove
unnecessary remove().

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
 drivers/rtc/rtc-vr41xx.c |   50 +++++++++++-----------------------------------
 1 file changed, 12 insertions(+), 38 deletions(-)

diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index aabc22c..88c9c92 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -293,7 +293,7 @@ static int rtc_probe(struct platform_device *pdev)
 	if (!res)
 		return -EBUSY;
 
-	rtc1_base = ioremap(res->start, resource_size(res));
+	rtc1_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
 	if (!rtc1_base)
 		return -EBUSY;
 
@@ -303,13 +303,14 @@ static int rtc_probe(struct platform_device *pdev)
 		goto err_rtc1_iounmap;
 	}
 
-	rtc2_base = ioremap(res->start, resource_size(res));
+	rtc2_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
 	if (!rtc2_base) {
 		retval = -EBUSY;
 		goto err_rtc1_iounmap;
 	}
 
-	rtc = rtc_device_register(rtc_name, &pdev->dev, &vr41xx_rtc_ops, THIS_MODULE);
+	rtc = devm_rtc_device_register(&pdev->dev, rtc_name, &vr41xx_rtc_ops,
+					THIS_MODULE);
 	if (IS_ERR(rtc)) {
 		retval = PTR_ERR(rtc);
 		goto err_iounmap_all;
@@ -330,24 +331,24 @@ static int rtc_probe(struct platform_device *pdev)
 	aie_irq = platform_get_irq(pdev, 0);
 	if (aie_irq <= 0) {
 		retval = -EBUSY;
-		goto err_device_unregister;
+		goto err_iounmap_all;
 	}
 
-	retval = request_irq(aie_irq, elapsedtime_interrupt, 0,
-			     "elapsed_time", pdev);
+	retval = devm_request_irq(&pdev->dev, aie_irq, elapsedtime_interrupt, 0,
+				"elapsed_time", pdev);
 	if (retval < 0)
-		goto err_device_unregister;
+		goto err_iounmap_all;
 
 	pie_irq = platform_get_irq(pdev, 1);
 	if (pie_irq <= 0) {
 		retval = -EBUSY;
-		goto err_free_irq;
+		goto err_iounmap_all;
 	}
 
-	retval = request_irq(pie_irq, rtclong1_interrupt, 0,
-			     "rtclong1", pdev);
+	retval = devm_request_irq(&pdev->dev, pie_irq, rtclong1_interrupt, 0,
+				"rtclong1", pdev);
 	if (retval < 0)
-		goto err_free_irq;
+		goto err_iounmap_all;
 
 	platform_set_drvdata(pdev, rtc);
 
@@ -358,47 +359,20 @@ static int rtc_probe(struct platform_device *pdev)
 
 	return 0;
 
-err_free_irq:
-	free_irq(aie_irq, pdev);
-
-err_device_unregister:
-	rtc_device_unregister(rtc);
-
 err_iounmap_all:
-	iounmap(rtc2_base);
 	rtc2_base = NULL;
 
 err_rtc1_iounmap:
-	iounmap(rtc1_base);
 	rtc1_base = NULL;
 
 	return retval;
 }
 
-static int rtc_remove(struct platform_device *pdev)
-{
-	struct rtc_device *rtc;
-
-	rtc = platform_get_drvdata(pdev);
-	if (rtc)
-		rtc_device_unregister(rtc);
-
-	free_irq(aie_irq, pdev);
-	free_irq(pie_irq, pdev);
-	if (rtc1_base)
-		iounmap(rtc1_base);
-	if (rtc2_base)
-		iounmap(rtc2_base);
-
-	return 0;
-}
-
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:RTC");
 
 static struct platform_driver rtc_platform_driver = {
 	.probe		= rtc_probe,
-	.remove		= rtc_remove,
 	.driver		= {
 		.name	= rtc_name,
 		.owner	= THIS_MODULE,
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] rtc: rtc-twl: Use devm_*() functions
  2013-12-05  1:03 [PATCH 1/2] rtc: rtc-twl: Use devm_*() functions Jingoo Han
  2013-12-05  1:05 ` [PATCH 2/2] rtc: rtc-vr41xx: " Jingoo Han
@ 2013-12-05 16:50 ` Grygorii Strashko
  2013-12-06  1:49   ` Jingoo Han
  1 sibling, 1 reply; 5+ messages in thread
From: Grygorii Strashko @ 2013-12-05 16:50 UTC (permalink / raw)
  To: Jingoo Han, 'Andrew Morton'
  Cc: linux-kernel, 'Alessandro Zummo', rtc-linux,
	'Kevin Hilman', 'Tony Lindgren',
	'Peter Ujfalusi'

On 12/05/2013 03:03 AM, Jingoo Han wrote:
> Use devm_*() functions to make cleanup paths simpler, and remove
> unnecessary remove().
> 
> Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> ---
>   drivers/rtc/rtc-twl.c |   38 +++++++++++++-------------------------
>   1 file changed, 13 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
> index c2e80d7..1915464 100644
> --- a/drivers/rtc/rtc-twl.c
> +++ b/drivers/rtc/rtc-twl.c
> @@ -479,7 +479,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>   	u8 rd_reg;
>   
>   	if (irq <= 0)
> -		goto out1;
> +		return ret;
>   
>   	/* Initialize the register map */
>   	if (twl_class_is_4030())
> @@ -489,7 +489,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>   
>   	ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
>   	if (ret < 0)
> -		goto out1;
> +		return ret;
>   
>   	if (rd_reg & BIT_RTC_STATUS_REG_POWER_UP_M)
>   		dev_warn(&pdev->dev, "Power up reset detected.\n");
> @@ -500,7 +500,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>   	/* Clear RTC Power up reset and pending alarm interrupts */
>   	ret = twl_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
>   	if (ret < 0)
> -		goto out1;
> +		return ret;
>   
>   	if (twl_class_is_6030()) {
>   		twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
> @@ -512,7 +512,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>   	dev_info(&pdev->dev, "Enabling TWL-RTC\n");
>   	ret = twl_rtc_write_u8(BIT_RTC_CTRL_REG_STOP_RTC_M, REG_RTC_CTRL_REG);
>   	if (ret < 0)
> -		goto out1;
> +		return ret;
>   
>   	/* ensure interrupts are disabled, bootloaders can be strange */
>   	ret = twl_rtc_write_u8(0, REG_RTC_INTERRUPTS_REG);
> @@ -522,34 +522,29 @@ static int twl_rtc_probe(struct platform_device *pdev)
>   	/* init cached IRQ enable bits */
>   	ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
>   	if (ret < 0)
> -		goto out1;
> +		return ret;
>   
>   	device_init_wakeup(&pdev->dev, 1);
>   
> -	rtc = rtc_device_register(pdev->name,
> -				  &pdev->dev, &twl_rtc_ops, THIS_MODULE);
> +	rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
> +					&twl_rtc_ops, THIS_MODULE);
>   	if (IS_ERR(rtc)) {
> -		ret = PTR_ERR(rtc);
>   		dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
>   			PTR_ERR(rtc));
> -		goto out1;
> +		return PTR_ERR(rtc);
>   	}
>   
> -	ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
> -				   IRQF_TRIGGER_RISING | IRQF_ONESHOT,
> -				   dev_name(&rtc->dev), rtc);
> +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> +					twl_rtc_interrupt,
> +					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
> +					dev_name(&rtc->dev), rtc);

Looks like this will change driver release order and free_irq
will be called after RTC device is unregistered.
I think, you need to request irq first -> then register RTC device.
Right?

>   	if (ret < 0) {
>   		dev_err(&pdev->dev, "IRQ is not free.\n");
> -		goto out2;
> +		return ret;
>   	}
>   
>   	platform_set_drvdata(pdev, rtc);
>   	return 0;
> -
> -out2:
> -	rtc_device_unregister(rtc);
> -out1:
> -	return ret;
>   }
>   
>   /*
> @@ -559,9 +554,6 @@ out1:
>   static int twl_rtc_remove(struct platform_device *pdev)
>   {
>   	/* leave rtc running, but disable irqs */
> -	struct rtc_device *rtc = platform_get_drvdata(pdev);
> -	int irq = platform_get_irq(pdev, 0);
> -
>   	mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
>   	mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
>   	if (twl_class_is_6030()) {
> @@ -571,10 +563,6 @@ static int twl_rtc_remove(struct platform_device *pdev)
>   			REG_INT_MSK_STS_A);
>   	}
>   
> -
> -	free_irq(irq, rtc);
> -
> -	rtc_device_unregister(rtc);
>   	return 0;
>   }
>   
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] rtc: rtc-twl: Use devm_*() functions
  2013-12-05 16:50 ` [PATCH 1/2] rtc: rtc-twl: " Grygorii Strashko
@ 2013-12-06  1:49   ` Jingoo Han
  2013-12-06 14:53     ` Grygorii Strashko
  0 siblings, 1 reply; 5+ messages in thread
From: Jingoo Han @ 2013-12-06  1:49 UTC (permalink / raw)
  To: 'Grygorii Strashko', 'Andrew Morton'
  Cc: linux-kernel, 'Alessandro Zummo', rtc-linux,
	'Kevin Hilman', 'Tony Lindgren',
	'Peter Ujfalusi', 'Jingoo Han'

On Friday, December 06, 2013 1:51 AM, Grygorii Strashko wrote:
> On 12/05/2013 03:03 AM, Jingoo Han wrote:
> > Use devm_*() functions to make cleanup paths simpler, and remove
> > unnecessary remove().
> >
> > Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> > ---
> >   drivers/rtc/rtc-twl.c |   38 +++++++++++++-------------------------
> >   1 file changed, 13 insertions(+), 25 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
> > index c2e80d7..1915464 100644
> > --- a/drivers/rtc/rtc-twl.c
> > +++ b/drivers/rtc/rtc-twl.c
> > @@ -479,7 +479,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
> >   	u8 rd_reg;
> >
> >   	if (irq <= 0)
> > -		goto out1;
> > +		return ret;
> >
> >   	/* Initialize the register map */
> >   	if (twl_class_is_4030())
> > @@ -489,7 +489,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
> >
> >   	ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
> >   	if (ret < 0)
> > -		goto out1;
> > +		return ret;
> >
> >   	if (rd_reg & BIT_RTC_STATUS_REG_POWER_UP_M)
> >   		dev_warn(&pdev->dev, "Power up reset detected.\n");
> > @@ -500,7 +500,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
> >   	/* Clear RTC Power up reset and pending alarm interrupts */
> >   	ret = twl_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
> >   	if (ret < 0)
> > -		goto out1;
> > +		return ret;
> >
> >   	if (twl_class_is_6030()) {
> >   		twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
> > @@ -512,7 +512,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
> >   	dev_info(&pdev->dev, "Enabling TWL-RTC\n");
> >   	ret = twl_rtc_write_u8(BIT_RTC_CTRL_REG_STOP_RTC_M, REG_RTC_CTRL_REG);
> >   	if (ret < 0)
> > -		goto out1;
> > +		return ret;
> >
> >   	/* ensure interrupts are disabled, bootloaders can be strange */
> >   	ret = twl_rtc_write_u8(0, REG_RTC_INTERRUPTS_REG);
> > @@ -522,34 +522,29 @@ static int twl_rtc_probe(struct platform_device *pdev)
> >   	/* init cached IRQ enable bits */
> >   	ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
> >   	if (ret < 0)
> > -		goto out1;
> > +		return ret;
> >
> >   	device_init_wakeup(&pdev->dev, 1);
> >
> > -	rtc = rtc_device_register(pdev->name,
> > -				  &pdev->dev, &twl_rtc_ops, THIS_MODULE);
> > +	rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
> > +					&twl_rtc_ops, THIS_MODULE);
> >   	if (IS_ERR(rtc)) {
> > -		ret = PTR_ERR(rtc);
> >   		dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
> >   			PTR_ERR(rtc));
> > -		goto out1;
> > +		return PTR_ERR(rtc);
> >   	}
> >
> > -	ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
> > -				   IRQF_TRIGGER_RISING | IRQF_ONESHOT,
> > -				   dev_name(&rtc->dev), rtc);
> > +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> > +					twl_rtc_interrupt,
> > +					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
> > +					dev_name(&rtc->dev), rtc);
> 
> Looks like this will change driver release order and free_irq
> will be called after RTC device is unregistered.
> I think, you need to request irq first -> then register RTC device.
> Right?

Hi Grygorii Strashko,

No, free_irq() will be called before RTC device is unregistered.

In probe(), the following functions are called as below:
  1. devm_rtc_device_register() -> rtc_device_register()
  2. devm_request_threaded_irq() -> request_threaded_irq()

The release functions will be inversely called.
When removing rtc-twl.
  1. devm_irq_release() -> free_irq()
  2. devm_rtc_device_release() -> rtc_device_unregister()

Thus, it is safe.
Thank you for your feedback. :-)

Best regards,
Jingoo Han

> 
> >   	if (ret < 0) {
> >   		dev_err(&pdev->dev, "IRQ is not free.\n");
> > -		goto out2;
> > +		return ret;
> >   	}
> >
> >   	platform_set_drvdata(pdev, rtc);
> >   	return 0;
> > -
> > -out2:
> > -	rtc_device_unregister(rtc);
> > -out1:
> > -	return ret;
> >   }
> >
> >   /*
> > @@ -559,9 +554,6 @@ out1:
> >   static int twl_rtc_remove(struct platform_device *pdev)
> >   {
> >   	/* leave rtc running, but disable irqs */
> > -	struct rtc_device *rtc = platform_get_drvdata(pdev);
> > -	int irq = platform_get_irq(pdev, 0);
> > -
> >   	mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
> >   	mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
> >   	if (twl_class_is_6030()) {
> > @@ -571,10 +563,6 @@ static int twl_rtc_remove(struct platform_device *pdev)
> >   			REG_INT_MSK_STS_A);
> >   	}
> >
> > -
> > -	free_irq(irq, rtc);
> > -
> > -	rtc_device_unregister(rtc);
> >   	return 0;
> >   }
> >
> >


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] rtc: rtc-twl: Use devm_*() functions
  2013-12-06  1:49   ` Jingoo Han
@ 2013-12-06 14:53     ` Grygorii Strashko
  0 siblings, 0 replies; 5+ messages in thread
From: Grygorii Strashko @ 2013-12-06 14:53 UTC (permalink / raw)
  To: Jingoo Han, 'Andrew Morton'
  Cc: linux-kernel, 'Alessandro Zummo', rtc-linux,
	'Kevin Hilman', 'Tony Lindgren',
	'Peter Ujfalusi'

On 12/06/2013 03:49 AM, Jingoo Han wrote:
> On Friday, December 06, 2013 1:51 AM, Grygorii Strashko wrote:
>> On 12/05/2013 03:03 AM, Jingoo Han wrote:
>>> Use devm_*() functions to make cleanup paths simpler, and remove
>>> unnecessary remove().
>>>
>>> Signed-off-by: Jingoo Han <jg1.han@samsung.com>
>>> ---
>>>    drivers/rtc/rtc-twl.c |   38 +++++++++++++-------------------------
>>>    1 file changed, 13 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
>>> index c2e80d7..1915464 100644
>>> --- a/drivers/rtc/rtc-twl.c
>>> +++ b/drivers/rtc/rtc-twl.c
>>> @@ -479,7 +479,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>>>    	u8 rd_reg;
>>>
>>>    	if (irq <= 0)
>>> -		goto out1;
>>> +		return ret;
>>>
>>>    	/* Initialize the register map */
>>>    	if (twl_class_is_4030())
>>> @@ -489,7 +489,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>>>
>>>    	ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
>>>    	if (ret < 0)
>>> -		goto out1;
>>> +		return ret;
>>>
>>>    	if (rd_reg & BIT_RTC_STATUS_REG_POWER_UP_M)
>>>    		dev_warn(&pdev->dev, "Power up reset detected.\n");
>>> @@ -500,7 +500,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>>>    	/* Clear RTC Power up reset and pending alarm interrupts */
>>>    	ret = twl_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
>>>    	if (ret < 0)
>>> -		goto out1;
>>> +		return ret;
>>>
>>>    	if (twl_class_is_6030()) {
>>>    		twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
>>> @@ -512,7 +512,7 @@ static int twl_rtc_probe(struct platform_device *pdev)
>>>    	dev_info(&pdev->dev, "Enabling TWL-RTC\n");
>>>    	ret = twl_rtc_write_u8(BIT_RTC_CTRL_REG_STOP_RTC_M, REG_RTC_CTRL_REG);
>>>    	if (ret < 0)
>>> -		goto out1;
>>> +		return ret;
>>>
>>>    	/* ensure interrupts are disabled, bootloaders can be strange */
>>>    	ret = twl_rtc_write_u8(0, REG_RTC_INTERRUPTS_REG);
>>> @@ -522,34 +522,29 @@ static int twl_rtc_probe(struct platform_device *pdev)
>>>    	/* init cached IRQ enable bits */
>>>    	ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
>>>    	if (ret < 0)
>>> -		goto out1;
>>> +		return ret;
>>>
>>>    	device_init_wakeup(&pdev->dev, 1);
>>>
>>> -	rtc = rtc_device_register(pdev->name,
>>> -				  &pdev->dev, &twl_rtc_ops, THIS_MODULE);
>>> +	rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
>>> +					&twl_rtc_ops, THIS_MODULE);
>>>    	if (IS_ERR(rtc)) {
>>> -		ret = PTR_ERR(rtc);
>>>    		dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
>>>    			PTR_ERR(rtc));
>>> -		goto out1;
>>> +		return PTR_ERR(rtc);
>>>    	}
>>>
>>> -	ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
>>> -				   IRQF_TRIGGER_RISING | IRQF_ONESHOT,
>>> -				   dev_name(&rtc->dev), rtc);
>>> +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
>>> +					twl_rtc_interrupt,
>>> +					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
>>> +					dev_name(&rtc->dev), rtc);
>>
>> Looks like this will change driver release order and free_irq
>> will be called after RTC device is unregistered.
>> I think, you need to request irq first -> then register RTC device.
>> Right?
>
> Hi Grygorii Strashko,
>
> No, free_irq() will be called before RTC device is unregistered.
>
> In probe(), the following functions are called as below:
>    1. devm_rtc_device_register() -> rtc_device_register()
>    2. devm_request_threaded_irq() -> request_threaded_irq()
>
> The release functions will be inversely called.
> When removing rtc-twl.
>    1. devm_irq_release() -> free_irq()
>    2. devm_rtc_device_release() -> rtc_device_unregister()
>
> Thus, it is safe.
> Thank you for your feedback. :-)
>

You are right. Sorry, my mistake :)

Regards,
-grygorii


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-06 13:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-05  1:03 [PATCH 1/2] rtc: rtc-twl: Use devm_*() functions Jingoo Han
2013-12-05  1:05 ` [PATCH 2/2] rtc: rtc-vr41xx: " Jingoo Han
2013-12-05 16:50 ` [PATCH 1/2] rtc: rtc-twl: " Grygorii Strashko
2013-12-06  1:49   ` Jingoo Han
2013-12-06 14:53     ` Grygorii Strashko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox