Commit d748c981 authored by Russell King's avatar Russell King Committed by Alexandre Belloni

rtc: armada38x: make struct rtc_class_ops const

Armada38x wants to modify its rtc_class_ops to remove the interrupt
handling when there is no usable interrupt, but this means we leave
function pointers in writable memory.

Since rtc_class_ops is small, arrange to have two instances, one for
when we have interrupts, and one for when we have none, both marked
const.  This allows the compiler to place them in read-only memory,
which is better than placing them in __ro_after_init.

Thanks to Bhumika Goyal <bhumirks@gmail.com> for pointing out that
the structure was writable and submitting a patch to add
__ro_after_init.
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 8bc57e7f
...@@ -262,7 +262,7 @@ static irqreturn_t armada38x_rtc_alarm_irq(int irq, void *data) ...@@ -262,7 +262,7 @@ static irqreturn_t armada38x_rtc_alarm_irq(int irq, void *data)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static struct rtc_class_ops armada38x_rtc_ops = { static const struct rtc_class_ops armada38x_rtc_ops = {
.read_time = armada38x_rtc_read_time, .read_time = armada38x_rtc_read_time,
.set_time = armada38x_rtc_set_time, .set_time = armada38x_rtc_set_time,
.read_alarm = armada38x_rtc_read_alarm, .read_alarm = armada38x_rtc_read_alarm,
...@@ -270,8 +270,15 @@ static struct rtc_class_ops armada38x_rtc_ops = { ...@@ -270,8 +270,15 @@ static struct rtc_class_ops armada38x_rtc_ops = {
.alarm_irq_enable = armada38x_rtc_alarm_irq_enable, .alarm_irq_enable = armada38x_rtc_alarm_irq_enable,
}; };
static const struct rtc_class_ops armada38x_rtc_ops_noirq = {
.read_time = armada38x_rtc_read_time,
.set_time = armada38x_rtc_set_time,
.read_alarm = armada38x_rtc_read_alarm,
};
static __init int armada38x_rtc_probe(struct platform_device *pdev) static __init int armada38x_rtc_probe(struct platform_device *pdev)
{ {
const struct rtc_class_ops *ops;
struct resource *res; struct resource *res;
struct armada38x_rtc *rtc; struct armada38x_rtc *rtc;
int ret; int ret;
...@@ -307,22 +314,25 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev) ...@@ -307,22 +314,25 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev)
0, pdev->name, rtc) < 0) { 0, pdev->name, rtc) < 0) {
dev_warn(&pdev->dev, "Interrupt not available.\n"); dev_warn(&pdev->dev, "Interrupt not available.\n");
rtc->irq = -1; rtc->irq = -1;
}
platform_set_drvdata(pdev, rtc);
if (rtc->irq != -1) {
device_init_wakeup(&pdev->dev, 1);
ops = &armada38x_rtc_ops;
} else {
/* /*
* If there is no interrupt available then we can't * If there is no interrupt available then we can't
* use the alarm * use the alarm
*/ */
armada38x_rtc_ops.set_alarm = NULL; ops = &armada38x_rtc_ops_noirq;
armada38x_rtc_ops.alarm_irq_enable = NULL;
} }
platform_set_drvdata(pdev, rtc);
if (rtc->irq != -1)
device_init_wakeup(&pdev->dev, 1);
/* Update RTC-MBUS bridge timing parameters */ /* Update RTC-MBUS bridge timing parameters */
rtc_update_mbus_timing_params(rtc); rtc_update_mbus_timing_params(rtc);
rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
&armada38x_rtc_ops, THIS_MODULE); ops, THIS_MODULE);
if (IS_ERR(rtc->rtc_dev)) { if (IS_ERR(rtc->rtc_dev)) {
ret = PTR_ERR(rtc->rtc_dev); ret = PTR_ERR(rtc->rtc_dev);
dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
......
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