Patchwork [1/2] rtc: davinci: fix crash on boot

login
register
mail settings
Submitter Wolfram Sang
Date May 5, 2011, 9:46 a.m.
Message ID <1304588775-30408-1-git-send-email-w.sang@pengutronix.de>
Download mbox | patch
Permalink /patch/94216/
State New
Headers show

Comments

Wolfram Sang - May 5, 2011, 9:46 a.m.
Commit f44f7f96a20 ("RTC: Initialize kernel state from RTC") caused a
crash when initializing the driver.

The reason is that rtc_device_register() calls rtc_read_alarm() after
that change, when the driver does not have all driver data set up yet.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: john stultz <johnstul@us.ibm.com>
---

Found by this coccinelle-script:

@ init @
identifier drvdata, ptr;
@@

	struct drvdata {
		...
 	 	void *ptr;
		...
	};

@ main depends on init @
expression E, ret;
identifier data;
@@
+	platform_set_drvdata(E, data);
	ret = rtc_device_register(...);
	...
-	platform_set_drvdata(E, data);

and then manually edited.

 drivers/rtc/rtc-davinci.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
john stultz - May 5, 2011, 6:54 p.m.
On Thu, 2011-05-05 at 11:46 +0200, Wolfram Sang wrote:
> Commit f44f7f96a20 ("RTC: Initialize kernel state from RTC") caused a
> crash when initializing the driver.
> 
> The reason is that rtc_device_register() calls rtc_read_alarm() after
> that change, when the driver does not have all driver data set up yet.
> 
> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
> Cc: john stultz <johnstul@us.ibm.com>

Thanks for catching this!

Acked-by: John Stultz <johnstul@us.ibm.com>

Patch

diff --git a/drivers/rtc/rtc-davinci.c b/drivers/rtc/rtc-davinci.c
index 8d46838..755e1fe 100644
--- a/drivers/rtc/rtc-davinci.c
+++ b/drivers/rtc/rtc-davinci.c
@@ -524,6 +524,8 @@  static int __init davinci_rtc_probe(struct platform_device *pdev)
 		goto fail2;
 	}
 
+	platform_set_drvdata(pdev, davinci_rtc);
+
 	davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
 				    &davinci_rtc_ops, THIS_MODULE);
 	if (IS_ERR(davinci_rtc->rtc)) {
@@ -553,8 +555,6 @@  static int __init davinci_rtc_probe(struct platform_device *pdev)
 
 	rtcss_write(davinci_rtc, PRTCSS_RTC_CCTRL_CAEN, PRTCSS_RTC_CCTRL);
 
-	platform_set_drvdata(pdev, davinci_rtc);
-
 	device_init_wakeup(&pdev->dev, 0);
 
 	return 0;
@@ -562,6 +562,7 @@  static int __init davinci_rtc_probe(struct platform_device *pdev)
 fail4:
 	rtc_device_unregister(davinci_rtc->rtc);
 fail3:
+	platform_set_drvdata(pdev, NULL);
 	iounmap(davinci_rtc->base);
 fail2:
 	release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size);