Skip to contentSkip to conversation

usb: gadget: configfs: make config_item_type const

PATCH In review Bhumika Goyal 2 participants 3 messages Oct 12, 2017 – Oct 14, 2017 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: configfs: make config_item_type const

This is a followup patch for:
https://patchwork.kernel.org/patch/9999649/ and
https://lkml.org/lkml/2017/10/11/375

Make config_item_type structures const as they are either passed to a function having the argument as const or stored in the const "ci_type" field of a config_item structure.

Done using Coccinelle.

---
 drivers/usb/gadget/configfs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/gadget/configfs.c +5 -5
index a22a892..c90a266 100644
@@ -505,13 +505,13 @@ static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item,
 	NULL,
 };
 
-static struct config_item_type gadget_config_type = {
+static const struct config_item_type gadget_config_type = {
 	.ct_item_ops	= &gadget_config_item_ops,
 	.ct_attrs	= gadget_config_attrs,
 	.ct_owner	= THIS_MODULE,
 };
 
-static struct config_item_type gadget_root_type = {
+static const struct config_item_type gadget_root_type = {
 	.ct_item_ops	= &gadget_root_item_ops,
 	.ct_attrs	= gadget_root_attrs,
 	.ct_owner	= THIS_MODULE,
@@ -593,7 +593,7 @@ static void function_drop(
 	.drop_item      = &function_drop,
 };
 
-static struct config_item_type functions_type = {
+static const struct config_item_type functions_type = {
 	.ct_group_ops   = &functions_ops,
 	.ct_owner       = THIS_MODULE,
 };
@@ -694,7 +694,7 @@ static void config_desc_drop(
 	.drop_item      = &config_desc_drop,
 };
 
-static struct config_item_type config_desc_type = {
+static const struct config_item_type config_desc_type = {
 	.ct_group_ops   = &config_desc_ops,
 	.ct_owner       = THIS_MODULE,
 };
@@ -1475,7 +1475,7 @@ static void gadgets_drop(struct config_group *group, struct config_item *item)
 	.drop_item      = &gadgets_drop,
 };
 
-static struct config_item_type gadgets_type = {
+static const struct config_item_type gadgets_type = {
 	.ct_group_ops   = &gadgets_ops,
 	.ct_owner       = THIS_MODULE,
 };
Signature · 1 line
1.9.1
#1 lore raw
Quoted 10 lines · Bhumika Goyal

This is a followup patch for:
https://patchwork.kernel.org/patch/9999649/ and
https://lkml.org/lkml/2017/10/11/375

Make config_item_type structures const as they are either passed to a function having the argument as const or stored in the const "ci_type" field of a config_item structure.

Done using Coccinelle.

Actually, this patch is dependent on the patches in the links
https://lkml.org/lkml/2017/10/11/375 and
https://patchwork.kernel.org/patch/9999649/. Therefore, this patch won't be correct unless the patches in these links gets applied.

Quoted 55 lines
---
 drivers/usb/gadget/configfs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/gadget/configfs.c +5 -6
index a22a892..c90a266 100644
@@ -505,13 +505,13 @@ static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item,
        NULL,
 };
 
-static struct config_item_type gadget_config_type = {
+static const struct config_item_type gadget_config_type = {
        .ct_item_ops    = &gadget_config_item_ops,
        .ct_attrs       = gadget_config_attrs,
        .ct_owner       = THIS_MODULE,
 };
 
-static struct config_item_type gadget_root_type = {
+static const struct config_item_type gadget_root_type = {
        .ct_item_ops    = &gadget_root_item_ops,
        .ct_attrs       = gadget_root_attrs,
        .ct_owner       = THIS_MODULE,
@@ -593,7 +593,7 @@ static void function_drop(
        .drop_item      = &function_drop,
 };
 
-static struct config_item_type functions_type = {
+static const struct config_item_type functions_type = {
        .ct_group_ops   = &functions_ops,
        .ct_owner       = THIS_MODULE,
 };
@@ -694,7 +694,7 @@ static void config_desc_drop(
        .drop_item      = &config_desc_drop,
 };
 
-static struct config_item_type config_desc_type = {
+static const struct config_item_type config_desc_type = {
        .ct_group_ops   = &config_desc_ops,
        .ct_owner       = THIS_MODULE,
 };
@@ -1475,7 +1475,7 @@ static void gadgets_drop(struct config_group *group, struct config_item *item)
        .drop_item      = &gadgets_drop,
 };
 
-static struct config_item_type gadgets_type = {
+static const struct config_item_type gadgets_type = {
        .ct_group_ops   = &gadgets_ops,
        .ct_owner       = THIS_MODULE,
 };
--

1.9.1

#2 lore raw
In reply to Bhumika Goyal
reproduce:

Hi Bhumika,

[auto build test WARNING on balbi-usb/next]
[also build test WARNING on v4.14-rc4 next-20171013]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Bhumika-Goyal/usb-gadget-configfs-make-config_item_type-const/20171014-133441
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: i386-randconfig-x014-201741 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

drivers/usb/gadget/configfs.c: In function 'config_desc_make':

>> drivers/usb/gadget/configfs.c:668:5: warning: passing argument 3 of 'config_group_init_type_name' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
        &gadget_config_type);
        ^
   In file included from drivers/usb/gadget/configfs.c:1:0:
   include/linux/configfs.h:102:13: note: expected 'struct config_item_type *' but argument is of type 'const struct config_item_type *'
    extern void config_group_init_type_name(struct config_group *group,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/usb/gadget/configfs.c: In function 'gadgets_make':
   drivers/usb/gadget/configfs.c:1421:48: warning: passing argument 3 of 'config_group_init_type_name' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     config_group_init_type_name(&gi->group, name, &gadget_root_type);
                                                   ^
   In file included from drivers/usb/gadget/configfs.c:1:0:
   include/linux/configfs.h:102:13: note: expected 'struct config_item_type *' but argument is of type 'const struct config_item_type *'
    extern void config_group_init_type_name(struct config_group *group,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/usb/gadget/configfs.c:1424:4: warning: passing argument 3 of 'config_group_init_type_name' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
       &functions_type);
       ^
   In file included from drivers/usb/gadget/configfs.c:1:0:
   include/linux/configfs.h:102:13: note: expected 'struct config_item_type *' but argument is of type 'const struct config_item_type *'
    extern void config_group_init_type_name(struct config_group *group,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/usb/gadget/configfs.c:1428:4: warning: passing argument 3 of 'config_group_init_type_name' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
       &config_desc_type);
       ^
   In file included from drivers/usb/gadget/configfs.c:1:0:
   include/linux/configfs.h:102:13: note: expected 'struct config_item_type *' but argument is of type 'const struct config_item_type *'
    extern void config_group_init_type_name(struct config_group *group,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/usb/gadget/configfs.c: At top level:
>> drivers/usb/gadget/configfs.c:1487:15: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]

.ci_type = &gadgets_type,
^

vim +668 drivers/usb/gadget/configfs.c

88af8bbe Sebastian Andrzej Siewior 2012-12-23  620  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  621  static struct config_group *config_desc_make(
88af8bbe Sebastian Andrzej Siewior 2012-12-23  622  		struct config_group *group,
88af8bbe Sebastian Andrzej Siewior 2012-12-23  623  		const char *name)
88af8bbe Sebastian Andrzej Siewior 2012-12-23  624  {
88af8bbe Sebastian Andrzej Siewior 2012-12-23  625  	struct gadget_info *gi;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  626  	struct config_usb_cfg *cfg;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  627  	char buf[MAX_NAME_LEN];
88af8bbe Sebastian Andrzej Siewior 2012-12-23  628  	char *num_str;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  629  	u8 num;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  630  	int ret;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  631  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  632  	gi = container_of(group, struct gadget_info, configs_group);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  633  	ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  634  	if (ret >= MAX_NAME_LEN)
88af8bbe Sebastian Andrzej Siewior 2012-12-23  635  		return ERR_PTR(-ENAMETOOLONG);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  636  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  637  	num_str = strchr(buf, '.');
88af8bbe Sebastian Andrzej Siewior 2012-12-23  638  	if (!num_str) {
88af8bbe Sebastian Andrzej Siewior 2012-12-23  639  		pr_err("Unable to locate . in name.bConfigurationValue\n");
88af8bbe Sebastian Andrzej Siewior 2012-12-23  640  		return ERR_PTR(-EINVAL);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  641  	}
88af8bbe Sebastian Andrzej Siewior 2012-12-23  642  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  643  	*num_str = '\0';
88af8bbe Sebastian Andrzej Siewior 2012-12-23  644  	num_str++;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  645  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  646  	if (!strlen(buf))
88af8bbe Sebastian Andrzej Siewior 2012-12-23  647  		return ERR_PTR(-EINVAL);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  648  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  649  	ret = kstrtou8(num_str, 0, &num);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  650  	if (ret)
88af8bbe Sebastian Andrzej Siewior 2012-12-23  651  		return ERR_PTR(ret);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  652  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  653  	cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  654  	if (!cfg)
88af8bbe Sebastian Andrzej Siewior 2012-12-23  655  		return ERR_PTR(-ENOMEM);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  656  	cfg->c.label = kstrdup(buf, GFP_KERNEL);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  657  	if (!cfg->c.label) {
88af8bbe Sebastian Andrzej Siewior 2012-12-23  658  		ret = -ENOMEM;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  659  		goto err;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  660  	}
88af8bbe Sebastian Andrzej Siewior 2012-12-23  661  	cfg->c.bConfigurationValue = num;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  662  	cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  663  	cfg->c.bmAttributes = USB_CONFIG_ATT_ONE;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  664  	INIT_LIST_HEAD(&cfg->string_list);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  665  	INIT_LIST_HEAD(&cfg->func_list);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  666  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  667  	config_group_init_type_name(&cfg->group, name,
88af8bbe Sebastian Andrzej Siewior 2012-12-23 @668  				&gadget_config_type);
1ae1602d Christoph Hellwig         2016-02-26  669  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  670  	config_group_init_type_name(&cfg->strings_group, "strings",
88af8bbe Sebastian Andrzej Siewior 2012-12-23  671  			&gadget_config_name_strings_type);
1ae1602d Christoph Hellwig         2016-02-26  672  	configfs_add_default_group(&cfg->strings_group, &cfg->group);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  673  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  674  	ret = usb_add_config_only(&gi->cdev, &cfg->c);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  675  	if (ret)
88af8bbe Sebastian Andrzej Siewior 2012-12-23  676  		goto err;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  677  
88af8bbe Sebastian Andrzej Siewior 2012-12-23  678  	return &cfg->group;
88af8bbe Sebastian Andrzej Siewior 2012-12-23  679  err:
88af8bbe Sebastian Andrzej Siewior 2012-12-23  680  	kfree(cfg->c.label);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  681  	kfree(cfg);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  682  	return ERR_PTR(ret);
88af8bbe Sebastian Andrzej Siewior 2012-12-23  683  }
88af8bbe Sebastian Andrzej Siewior 2012-12-23  684  

:::::: The code at line 668 was first introduced by commit
:::::: 88af8bbe4ef781031ad3370847553f3b42ba0076 usb: gadget: the start of the configfs interface

:::::: TO: Sebastian Andrzej Siewior <[email protected]> :::::: CC: Felipe Balbi <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation