Skip to contentSkip to conversation

rtc: constify rtc_class_ops structures

PATCH Applied Bhumika Goyal 2 participants 2 messages Jan 5, 2017 – Jan 11, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: constify rtc_class_ops structures

Declare rtc_class_ops structures as const as they are only passed as an argument to the function devm_rtc_device_register. This argument is of type const struct rtc_class_ops *, so rtc_class_ops structures having this property can be declared const.
Done using Coccinelle:

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct rtc_class_ops i@p = {...};

@ok1@
identifier r1.i;
position p;
@@
devm_rtc_device_register(...,&i@p,...)

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct rtc_class_ops i;

File size details:

   text	   data	    bss	    dec	    hex	filename
    559	    320	      0	    879	    36f	drivers/rtc/rtc-dm355evm.o
    671	    192	      0	    863	    35f	drivers/rtc/rtc-dm355evm.o
   4727	    320	      0	   5047	   13b7	drivers/rtc/rtc-imxdi.o
   4855	    192	      0	   5047	   13b7	drivers/rtc/rtc-imxdi.o

1269 192 0 1461 5b5 drivers/rtc/rtc-mxc.o

File size remains unchanged for : drivers/rtc/rtc-mxc.o

---
 drivers/rtc/rtc-dm355evm.c | 2 +-
 drivers/rtc/rtc-imxdi.c    | 2 +-
 drivers/rtc/rtc-mxc.c      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/rtc-dm355evm.c +1 -1
index 94067f8..f225cd8 100644
@@ -116,7 +116,7 @@ static int dm355evm_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	return 0;
 }
 
-static struct rtc_class_ops dm355evm_rtc_ops = {
+static const struct rtc_class_ops dm355evm_rtc_ops = {
 	.read_time	= dm355evm_rtc_read_time,
 	.set_time	= dm355evm_rtc_set_time,
 };
drivers/rtc/rtc-imxdi.c +1 -1
index 67b56b8..71266ec 100644
@@ -668,7 +668,7 @@ static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 	return 0;
 }
 
-static struct rtc_class_ops dryice_rtc_ops = {
+static const struct rtc_class_ops dryice_rtc_ops = {
 	.read_time		= dryice_rtc_read_time,
 	.set_mmss		= dryice_rtc_set_mmss,
 	.alarm_irq_enable	= dryice_rtc_alarm_irq_enable,
drivers/rtc/rtc-mxc.c +1 -1
index 359876a..7731912 100644
@@ -353,7 +353,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 }
 
 /* RTC layer */
-static struct rtc_class_ops mxc_rtc_ops = {
+static const struct rtc_class_ops mxc_rtc_ops = {
 	.release		= mxc_rtc_release,
 	.read_time		= mxc_rtc_read_time,
 	.set_mmss64		= mxc_rtc_set_mmss,
Signature · 11 lines
1.9.1

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#1 lore raw
Quoted 41 lines · Bhumika Goyal

Declare rtc_class_ops structures as const as they are only passed as an argument to the function devm_rtc_device_register. This argument is of type const struct rtc_class_ops *, so rtc_class_ops structures having this property can be declared const.
Done using Coccinelle:

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct rtc_class_ops i@p = {...};

@ok1@
identifier r1.i;
position p;
@@
devm_rtc_device_register(...,&i@p,...)

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct rtc_class_ops i;

File size details:

   text	   data	    bss	    dec	    hex	filename
    559	    320	      0	    879	    36f	drivers/rtc/rtc-dm355evm.o
    671	    192	      0	    863	    35f	drivers/rtc/rtc-dm355evm.o
   4727	    320	      0	   5047	   13b7	drivers/rtc/rtc-imxdi.o
   4855	    192	      0	   5047	   13b7	drivers/rtc/rtc-imxdi.o
   1269     192       0    1461     5b5 drivers/rtc/rtc-mxc.o
Quoted 9 lines

File size remains unchanged for : drivers/rtc/rtc-mxc.o

---
 drivers/rtc/rtc-dm355evm.c | 2 +-
 drivers/rtc/rtc-imxdi.c    | 2 +-
 drivers/rtc/rtc-mxc.c      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

Signature · 13 lines
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.