Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1555821

[PATCH] usb: gadget: constify usb_gadget_ops structures

From Bhumika Goyal <bhumirks@gmail.com>
Newsgroups linux.kernel
Subject [PATCH] usb: gadget: constify usb_gadget_ops structures
Date 2017-01-10 20:00 +0100
Message-ID <sY9Oi-4Tu-35@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Declare usb_gadget_ops structures as const as they are only stored in
the ops field of a usb_gadget structure. This field is of type const, so
usb_gadget_ops structures having this property can be declared const
too.
Done using Coccinelle:

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

@ok1@
identifier r1.i;
position p;
struct fotg210_udc fotg210;
@@
fotg210.gadget.ops=&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 usb_gadget_ops i;

File size before:
   text	   data	    bss	    dec	    hex	filename
   7559	    384	      8	   7951	   1f0f	usb/gadget/udc/fotg210-udc.o

File size after:
   text	   data	    bss	    dec	    hex	filename
   7655	    288	      8	   7951	   1f0f	usb/gadget/udc/fotg210-udc.o

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index 6ba122c..f40b391 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -1058,7 +1058,7 @@ static int fotg210_udc_stop(struct usb_gadget *g)
 	return 0;
 }
 
-static struct usb_gadget_ops fotg210_gadget_ops = {
+static const struct usb_gadget_ops fotg210_gadget_ops = {
 	.udc_start		= fotg210_udc_start,
 	.udc_stop		= fotg210_udc_stop,
 };
-- 
1.9.1

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] usb: gadget: constify usb_gadget_ops structures Bhumika Goyal <bhumirks@gmail.com> - 2017-01-10 20:00 +0100

csiph-web