Bhumika Goyal
2017-Jan-09 15:21 UTC
[PATCH] vhost: scsi: constify target_core_fabric_ops structures
Declare target_core_fabric_ops strucrues as const as they are only passed as an argument to the functions target_register_template and target_unregister_template. The arguments are of type const struct target_core_fabric_ops *, so target_core_fabric_ops structures having this property can be declared const. Done using Coccinelle: @r disable optional_qualifier@ identifier i; position p; @@ static struct target_core_fabric_ops i at p={...}; @ok@ position p; identifier r.i; @@ ( target_register_template(&i at p) | target_unregister_template(&i at p) ) @bad@ position p!={r.p,ok.p}; identifier r.i; @@ i at p @depends on !bad disable optional_qualifier@ identifier r.i; @@ +const struct target_core_fabric_ops i; File size before: drivers/vhost/scsi.o text data bss dec hex filename 18063 2985 40 21088 5260 drivers/vhost/scsi.o File size after: drivers/vhost/scsi.o text data bss dec hex filename 18479 2601 40 21120 5280 drivers/vhost/scsi.o Signed-off-by: Bhumika Goyal <bhumirks at gmail.com> --- drivers/vhost/scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 253310c..620366d 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn) NULL, }; -static struct target_core_fabric_ops vhost_scsi_ops = { +static const struct target_core_fabric_ops vhost_scsi_ops = { .module = THIS_MODULE, .name = "vhost", .get_fabric_name = vhost_scsi_get_fabric_name, -- 1.9.1
Jason Wang
2017-Jan-10 02:50 UTC
[PATCH] vhost: scsi: constify target_core_fabric_ops structures
On 2017?01?09? 23:21, Bhumika Goyal wrote:> Declare target_core_fabric_ops strucrues as const as they are only > passed as an argument to the functions target_register_template and > target_unregister_template. The arguments are of type const struct > target_core_fabric_ops *, so target_core_fabric_ops structures having > this property can be declared const. > Done using Coccinelle: > > @r disable optional_qualifier@ > identifier i; > position p; > @@ > static struct target_core_fabric_ops i at p={...}; > > @ok@ > position p; > identifier r.i; > @@ > ( > target_register_template(&i at p) > | > target_unregister_template(&i at p) > ) > @bad@ > position p!={r.p,ok.p}; > identifier r.i; > @@ > i at p > > @depends on !bad disable optional_qualifier@ > identifier r.i; > @@ > +const > struct target_core_fabric_ops i; > > File size before: drivers/vhost/scsi.o > text data bss dec hex filename > 18063 2985 40 21088 5260 drivers/vhost/scsi.o > > File size after: drivers/vhost/scsi.o > text data bss dec hex filename > 18479 2601 40 21120 5280 drivers/vhost/scsi.o > > Signed-off-by: Bhumika Goyal <bhumirks at gmail.com> > --- > drivers/vhost/scsi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c > index 253310c..620366d 100644 > --- a/drivers/vhost/scsi.c > +++ b/drivers/vhost/scsi.c > @@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn) > NULL, > }; > > -static struct target_core_fabric_ops vhost_scsi_ops = { > +static const struct target_core_fabric_ops vhost_scsi_ops = { > .module = THIS_MODULE, > .name = "vhost", > .get_fabric_name = vhost_scsi_get_fabric_name,Acked-by: Jason Wang <jasowang at redhat.com>
Michael S. Tsirkin
2017-Jan-10 05:11 UTC
[PATCH] vhost: scsi: constify target_core_fabric_ops structures
On Mon, Jan 09, 2017 at 08:51:02PM +0530, Bhumika Goyal wrote:> Declare target_core_fabric_ops strucrues as const as they are only > passed as an argument to the functions target_register_template and > target_unregister_template. The arguments are of type const struct > target_core_fabric_ops *, so target_core_fabric_ops structures having > this property can be declared const. > Done using Coccinelle: > > @r disable optional_qualifier@ > identifier i; > position p; > @@ > static struct target_core_fabric_ops i at p={...}; > > @ok@ > position p; > identifier r.i; > @@ > ( > target_register_template(&i at p) > | > target_unregister_template(&i at p) > ) > @bad@ > position p!={r.p,ok.p}; > identifier r.i; > @@ > i at p > > @depends on !bad disable optional_qualifier@ > identifier r.i; > @@ > +const > struct target_core_fabric_ops i; > > File size before: drivers/vhost/scsi.o > text data bss dec hex filename > 18063 2985 40 21088 5260 drivers/vhost/scsi.o > > File size after: drivers/vhost/scsi.o > text data bss dec hex filename > 18479 2601 40 21120 5280 drivers/vhost/scsi.oWhat are these numbers trying to prove?> Signed-off-by: Bhumika Goyal <bhumirks at gmail.com> > --- > drivers/vhost/scsi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c > index 253310c..620366d 100644 > --- a/drivers/vhost/scsi.c > +++ b/drivers/vhost/scsi.c > @@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn) > NULL, > }; > > -static struct target_core_fabric_ops vhost_scsi_ops = { > +static const struct target_core_fabric_ops vhost_scsi_ops = { > .module = THIS_MODULE, > .name = "vhost", > .get_fabric_name = vhost_scsi_get_fabric_name,If it can be const it probably should ...> -- > 1.9.1
Bhumika Goyal
2017-Jan-10 12:41 UTC
[PATCH] vhost: scsi: constify target_core_fabric_ops structures
On Tue, Jan 10, 2017 at 10:41 AM, Michael S. Tsirkin <mst at redhat.com> wrote:> On Mon, Jan 09, 2017 at 08:51:02PM +0530, Bhumika Goyal wrote: >> Declare target_core_fabric_ops strucrues as const as they are only >> passed as an argument to the functions target_register_template and >> target_unregister_template. The arguments are of type const struct >> target_core_fabric_ops *, so target_core_fabric_ops structures having >> this property can be declared const. >> Done using Coccinelle: >> >> @r disable optional_qualifier@ >> identifier i; >> position p; >> @@ >> static struct target_core_fabric_ops i at p={...}; >> >> @ok@ >> position p; >> identifier r.i; >> @@ >> ( >> target_register_template(&i at p) >> | >> target_unregister_template(&i at p) >> ) >> @bad@ >> position p!={r.p,ok.p}; >> identifier r.i; >> @@ >> i at p >> >> @depends on !bad disable optional_qualifier@ >> identifier r.i; >> @@ >> +const >> struct target_core_fabric_ops i; >> >> File size before: drivers/vhost/scsi.o >> text data bss dec hex filename >> 18063 2985 40 21088 5260 drivers/vhost/scsi.o >> >> File size after: drivers/vhost/scsi.o >> text data bss dec hex filename >> 18479 2601 40 21120 5280 drivers/vhost/scsi.o > > What are these numbers trying to prove? >These numbers show that adding const has decreased the size of the data segment and increased the size of the text segment, suggesting that the changed code has been compiled and the const annotation has had an effect. Thanks, Bhumika> >> Signed-off-by: Bhumika Goyal <bhumirks at gmail.com> >> --- >> drivers/vhost/scsi.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c >> index 253310c..620366d 100644 >> --- a/drivers/vhost/scsi.c >> +++ b/drivers/vhost/scsi.c >> @@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn) >> NULL, >> }; >> >> -static struct target_core_fabric_ops vhost_scsi_ops = { >> +static const struct target_core_fabric_ops vhost_scsi_ops = { >> .module = THIS_MODULE, >> .name = "vhost", >> .get_fabric_name = vhost_scsi_get_fabric_name, > > If it can be const it probably should ... > >> -- >> 1.9.1
Seemingly Similar Threads
- [PATCH] vhost: scsi: constify target_core_fabric_ops structures
- [PATCH] vhost: scsi: constify target_core_fabric_ops structures
- [PATCH] vhost: scsi: constify target_core_fabric_ops structures
- [PATCH] vhost: scsi: constify target_core_fabric_ops structures
- [PATCH] vhost: scsi: constify target_core_fabric_ops structures