Skip to content

Commit

Permalink
rtc: ep93xx: Initialize drvdata before registering device
Browse files Browse the repository at this point in the history
Commit f44f7f9 ("RTC: Initialize kernel state from RTC") uncovered
an issue in a number of RTC drivers, where the drivers call
rtc_device_register before initializing the device or platform drvdata.

This frequently results in null pointer dereferences when the
rtc_device_register immediately makes use of the rtc device, calling
rtc_read_alarm.

The solution is to ensure the drvdata is initialized prior to registering
the rtc device.

CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: rtc-linux@googlegroups.com
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
[Fixed up commit log -jstultz]
Signed-off-by: John Stultz <john.stultz@linaro.org>
  • Loading branch information
Wolfram Sang authored and John Stultz committed May 7, 2011
1 parent f4e708a commit 92d921c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/rtc/rtc-ep93xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
return -ENXIO;

pdev->dev.platform_data = ep93xx_rtc;
platform_set_drvdata(pdev, rtc);

rtc = rtc_device_register(pdev->name,
&pdev->dev, &ep93xx_rtc_ops, THIS_MODULE);
Expand All @@ -159,18 +160,16 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
goto exit;
}

platform_set_drvdata(pdev, rtc);

err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
if (err)
goto fail;

return 0;

fail:
platform_set_drvdata(pdev, NULL);
rtc_device_unregister(rtc);
exit:
platform_set_drvdata(pdev, NULL);
pdev->dev.platform_data = NULL;
return err;
}
Expand Down

0 comments on commit 92d921c

Please sign in to comment.