Message ID | 1482751862-18699-1-git-send-email-bhumirks@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Mon, Dec 26, 2016 at 05:01:02PM +0530, Bhumika Goyal wrote: > The object armada38x_rtc_ops of type rtc_class_ops structure is not > modified after getting initialized by armada38x_rtc_probe. Apart from > getting referenced in init it is also passed as an argument to the function > devm_rtc_device_register but this argument is of type const struct > rtc_class_ops *. Therefore add __ro_after_init to its declaration. What I'd prefer here is for the structure to be duplicated, with one copy having the alarm methods and one which does not. Both can then be made "const" (so placed into the read-only section at link time) and the probe function select between the two. I think that's a cleaner and better solution, even though it's slightly larger. I'm not a fan of __ro_after_init being used where other solutions are possible.
On Mon, Jan 2, 2017 at 6:06 AM, Russell King - ARM Linux <linux@armlinux.org.uk> wrote: > On Mon, Dec 26, 2016 at 05:01:02PM +0530, Bhumika Goyal wrote: >> The object armada38x_rtc_ops of type rtc_class_ops structure is not >> modified after getting initialized by armada38x_rtc_probe. Apart from >> getting referenced in init it is also passed as an argument to the function >> devm_rtc_device_register but this argument is of type const struct >> rtc_class_ops *. Therefore add __ro_after_init to its declaration. > > What I'd prefer here is for the structure to be duplicated, with one > copy having the alarm methods and one which does not. Both can then > be made "const" (so placed into the read-only section at link time) > and the probe function select between the two. > > I think that's a cleaner and better solution, even though it's > slightly larger. > > I'm not a fan of __ro_after_init being used where other solutions are > possible. Can the pointer that points to the struct rtc_class_ops be made ro_after_init? -Kees
On Tue, Jan 03, 2017 at 01:18:29PM -0800, Kees Cook wrote: > On Mon, Jan 2, 2017 at 6:06 AM, Russell King - ARM Linux > <linux@armlinux.org.uk> wrote: > > On Mon, Dec 26, 2016 at 05:01:02PM +0530, Bhumika Goyal wrote: > >> The object armada38x_rtc_ops of type rtc_class_ops structure is not > >> modified after getting initialized by armada38x_rtc_probe. Apart from > >> getting referenced in init it is also passed as an argument to the function > >> devm_rtc_device_register but this argument is of type const struct > >> rtc_class_ops *. Therefore add __ro_after_init to its declaration. > > > > What I'd prefer here is for the structure to be duplicated, with one > > copy having the alarm methods and one which does not. Both can then > > be made "const" (so placed into the read-only section at link time) > > and the probe function select between the two. > > > > I think that's a cleaner and better solution, even though it's > > slightly larger. > > > > I'm not a fan of __ro_after_init being used where other solutions are > > possible. > > Can the pointer that points to the struct rtc_class_ops be made ro_after_init? It's passed into the RTC core code, and probably stored in some dynamically allocated object, so probably no. It's the same class of problem as every file_operations pointer in the kernel, or the thousand other operations structure pointers that a running kernel has.
diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c index 9a3f2a6..7883c7f 100644 --- a/drivers/rtc/rtc-armada38x.c +++ b/drivers/rtc/rtc-armada38x.c @@ -202,7 +202,7 @@ static irqreturn_t armada38x_rtc_alarm_irq(int irq, void *data) return IRQ_HANDLED; } -static struct rtc_class_ops armada38x_rtc_ops = { +static struct rtc_class_ops armada38x_rtc_ops __ro_after_init = { .read_time = armada38x_rtc_read_time, .set_time = armada38x_rtc_set_time, .read_alarm = armada38x_rtc_read_alarm,
The object armada38x_rtc_ops of type rtc_class_ops structure is not modified after getting initialized by armada38x_rtc_probe. Apart from getting referenced in init it is also passed as an argument to the function devm_rtc_device_register but this argument is of type const struct rtc_class_ops *. Therefore add __ro_after_init to its declaration. Signed-off-by: Bhumika Goyal <bhumirks@gmail.com> --- drivers/rtc/rtc-armada38x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)