Commit 92d921c5 authored by Wolfram Sang's avatar Wolfram Sang Committed by John Stultz

rtc: ep93xx: Initialize drvdata before registering device

Commit f44f7f96 ("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: default avatarWolfram Sang <w.sang@pengutronix.de>
[Fixed up commit log -jstultz]
Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
parent f4e708ae
...@@ -151,6 +151,7 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev) ...@@ -151,6 +151,7 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
return -ENXIO; return -ENXIO;
pdev->dev.platform_data = ep93xx_rtc; pdev->dev.platform_data = ep93xx_rtc;
platform_set_drvdata(pdev, rtc);
rtc = rtc_device_register(pdev->name, rtc = rtc_device_register(pdev->name,
&pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE);
...@@ -159,8 +160,6 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev) ...@@ -159,8 +160,6 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
goto exit; goto exit;
} }
platform_set_drvdata(pdev, rtc);
err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
if (err) if (err)
goto fail; goto fail;
...@@ -168,9 +167,9 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev) ...@@ -168,9 +167,9 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev)
return 0; return 0;
fail: fail:
platform_set_drvdata(pdev, NULL);
rtc_device_unregister(rtc); rtc_device_unregister(rtc);
exit: exit:
platform_set_drvdata(pdev, NULL);
pdev->dev.platform_data = NULL; pdev->dev.platform_data = NULL;
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment