netconsole: make config_item_type const

Message ID 1507811352-9962-1-git-send-email-bhumirks@gmail.com
State Not Applicable
Delegated to: David Miller
Headers show
Series
  • netconsole: make config_item_type const
Related show

Commit Message

Bhumika Goyal Oct. 12, 2017, 12:29 p.m.
This is a followup patch for: https://lkml.org/lkml/2017/10/11/375 and
https://patchwork.kernel.org/patch/9999649/

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

Done using Coccienlle.

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
 drivers/net/netconsole.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bhumika Goyal Oct. 12, 2017, 3:04 p.m. | #1
On Thu, Oct 12, 2017 at 2:29 PM, Bhumika Goyal <bhumirks@gmail.com> wrote:
> This is a followup patch for: https://lkml.org/lkml/2017/10/11/375 and
> https://patchwork.kernel.org/patch/9999649/
>
> Make these structures const as they are either passed to the functions
> having the argument as const or stored as a reference in the "ci_type"
> const field of a config_item structure.
>
> Done using Coccienlle.
>

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.

> Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
> ---
>  drivers/net/netconsole.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 0e27920..be9aa36 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -616,7 +616,7 @@ static void netconsole_target_release(struct config_item *item)
>         .release                = netconsole_target_release,
>  };
>
> -static struct config_item_type netconsole_target_type = {
> +static const struct config_item_type netconsole_target_type = {
>         .ct_attrs               = netconsole_target_attrs,
>         .ct_item_ops            = &netconsole_target_item_ops,
>         .ct_owner               = THIS_MODULE,
> @@ -682,7 +682,7 @@ static void drop_netconsole_target(struct config_group *group,
>         .drop_item      = drop_netconsole_target,
>  };
>
> -static struct config_item_type netconsole_subsys_type = {
> +static const struct config_item_type netconsole_subsys_type = {
>         .ct_group_ops   = &netconsole_subsys_group_ops,
>         .ct_owner       = THIS_MODULE,
>  };
> --
> 1.9.1
>
kbuild test robot Oct. 14, 2017, 7:26 p.m. | #2
Hi Bhumika,

[auto build test WARNING on net-next/master]
[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/netconsole-make-config_item_type-const/20171015-014833
config: x86_64-randconfig-x005-201742 (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=x86_64 

All warnings (new ones prefixed by >>):

   drivers/net/netconsole.c: In function 'make_netconsole_target':
>> drivers/net/netconsole.c:650:46: warning: passing argument 3 of 'config_item_init_type_name' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     config_item_init_type_name(&nt->item, name, &netconsole_target_type);
                                                 ^
   In file included from drivers/net/netconsole.c:49:0:
   include/linux/configfs.h:73:13: note: expected 'struct config_item_type *' but argument is of type 'const struct config_item_type *'
    extern void config_item_init_type_name(struct config_item *item,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netconsole.c: At top level:
>> drivers/net/netconsole.c:695:15: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
       .ci_type = &netconsole_subsys_type,
                  ^

vim +650 drivers/net/netconsole.c

0bcc1816 Satyam Sharma 2007-08-10  624  
0bcc1816 Satyam Sharma 2007-08-10  625  /*
0bcc1816 Satyam Sharma 2007-08-10  626   * Group operations and type for netconsole_subsys.
0bcc1816 Satyam Sharma 2007-08-10  627   */
0bcc1816 Satyam Sharma 2007-08-10  628  
f89ab861 Joel Becker   2008-07-17  629  static struct config_item *make_netconsole_target(struct config_group *group,
f89ab861 Joel Becker   2008-07-17  630  						  const char *name)
0bcc1816 Satyam Sharma 2007-08-10  631  {
0bcc1816 Satyam Sharma 2007-08-10  632  	unsigned long flags;
0bcc1816 Satyam Sharma 2007-08-10  633  	struct netconsole_target *nt;
0bcc1816 Satyam Sharma 2007-08-10  634  
0bcc1816 Satyam Sharma 2007-08-10  635  	/*
0bcc1816 Satyam Sharma 2007-08-10  636  	 * Allocate and initialize with defaults.
698cf1c6 Tejun Heo     2015-06-25  637  	 * Target is disabled at creation (!enabled).
0bcc1816 Satyam Sharma 2007-08-10  638  	 */
0bcc1816 Satyam Sharma 2007-08-10  639  	nt = kzalloc(sizeof(*nt), GFP_KERNEL);
e404decb Joe Perches   2012-01-29  640  	if (!nt)
a6795e9e Joel Becker   2008-07-17  641  		return ERR_PTR(-ENOMEM);
0bcc1816 Satyam Sharma 2007-08-10  642  
0bcc1816 Satyam Sharma 2007-08-10  643  	nt->np.name = "netconsole";
0bcc1816 Satyam Sharma 2007-08-10  644  	strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
0bcc1816 Satyam Sharma 2007-08-10  645  	nt->np.local_port = 6665;
0bcc1816 Satyam Sharma 2007-08-10  646  	nt->np.remote_port = 6666;
1667c942 Joe Perches   2015-03-02  647  	eth_broadcast_addr(nt->np.remote_mac);
0bcc1816 Satyam Sharma 2007-08-10  648  
0bcc1816 Satyam Sharma 2007-08-10  649  	/* Initialize the config_item member */
0bcc1816 Satyam Sharma 2007-08-10 @650  	config_item_init_type_name(&nt->item, name, &netconsole_target_type);
0bcc1816 Satyam Sharma 2007-08-10  651  
0bcc1816 Satyam Sharma 2007-08-10  652  	/* Adding, but it is disabled */
0bcc1816 Satyam Sharma 2007-08-10  653  	spin_lock_irqsave(&target_list_lock, flags);
0bcc1816 Satyam Sharma 2007-08-10  654  	list_add(&nt->list, &target_list);
0bcc1816 Satyam Sharma 2007-08-10  655  	spin_unlock_irqrestore(&target_list_lock, flags);
0bcc1816 Satyam Sharma 2007-08-10  656  
f89ab861 Joel Becker   2008-07-17  657  	return &nt->item;
0bcc1816 Satyam Sharma 2007-08-10  658  }
0bcc1816 Satyam Sharma 2007-08-10  659  
0bcc1816 Satyam Sharma 2007-08-10  660  static void drop_netconsole_target(struct config_group *group,
0bcc1816 Satyam Sharma 2007-08-10  661  				   struct config_item *item)
0bcc1816 Satyam Sharma 2007-08-10  662  {
0bcc1816 Satyam Sharma 2007-08-10  663  	unsigned long flags;
0bcc1816 Satyam Sharma 2007-08-10  664  	struct netconsole_target *nt = to_target(item);
0bcc1816 Satyam Sharma 2007-08-10  665  
0bcc1816 Satyam Sharma 2007-08-10  666  	spin_lock_irqsave(&target_list_lock, flags);
0bcc1816 Satyam Sharma 2007-08-10  667  	list_del(&nt->list);
0bcc1816 Satyam Sharma 2007-08-10  668  	spin_unlock_irqrestore(&target_list_lock, flags);
0bcc1816 Satyam Sharma 2007-08-10  669  
0bcc1816 Satyam Sharma 2007-08-10  670  	/*
0bcc1816 Satyam Sharma 2007-08-10  671  	 * The target may have never been enabled, or was manually disabled
0bcc1816 Satyam Sharma 2007-08-10  672  	 * before being removed so netpoll may have already been cleaned up.
0bcc1816 Satyam Sharma 2007-08-10  673  	 */
0bcc1816 Satyam Sharma 2007-08-10  674  	if (nt->enabled)
0bcc1816 Satyam Sharma 2007-08-10  675  		netpoll_cleanup(&nt->np);
0bcc1816 Satyam Sharma 2007-08-10  676  
0bcc1816 Satyam Sharma 2007-08-10  677  	config_item_put(&nt->item);
0bcc1816 Satyam Sharma 2007-08-10  678  }
0bcc1816 Satyam Sharma 2007-08-10  679  
0bcc1816 Satyam Sharma 2007-08-10  680  static struct configfs_group_operations netconsole_subsys_group_ops = {
0bcc1816 Satyam Sharma 2007-08-10  681  	.make_item	= make_netconsole_target,
0bcc1816 Satyam Sharma 2007-08-10  682  	.drop_item	= drop_netconsole_target,
0bcc1816 Satyam Sharma 2007-08-10  683  };
0bcc1816 Satyam Sharma 2007-08-10  684  
5de3a121 Bhumika Goyal 2017-10-12  685  static const struct config_item_type netconsole_subsys_type = {
0bcc1816 Satyam Sharma 2007-08-10  686  	.ct_group_ops	= &netconsole_subsys_group_ops,
0bcc1816 Satyam Sharma 2007-08-10  687  	.ct_owner	= THIS_MODULE,
0bcc1816 Satyam Sharma 2007-08-10  688  };
0bcc1816 Satyam Sharma 2007-08-10  689  
0bcc1816 Satyam Sharma 2007-08-10  690  /* The netconsole configfs subsystem */
0bcc1816 Satyam Sharma 2007-08-10  691  static struct configfs_subsystem netconsole_subsys = {
0bcc1816 Satyam Sharma 2007-08-10  692  	.su_group	= {
0bcc1816 Satyam Sharma 2007-08-10  693  		.cg_item	= {
0bcc1816 Satyam Sharma 2007-08-10  694  			.ci_namebuf	= "netconsole",
0bcc1816 Satyam Sharma 2007-08-10 @695  			.ci_type	= &netconsole_subsys_type,
0bcc1816 Satyam Sharma 2007-08-10  696  		},
0bcc1816 Satyam Sharma 2007-08-10  697  	},
0bcc1816 Satyam Sharma 2007-08-10  698  };
0bcc1816 Satyam Sharma 2007-08-10  699  

:::::: The code at line 650 was first introduced by commit
:::::: 0bcc1816188e570bde1d56a208996660f2633ae0 [NET] netconsole: Support dynamic reconfiguration using configfs

:::::: TO: Satyam Sharma <satyam@infradead.org>
:::::: CC: David S. Miller <davem@sunset.davemloft.net>

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

Patch

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 0e27920..be9aa36 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -616,7 +616,7 @@  static void netconsole_target_release(struct config_item *item)
 	.release		= netconsole_target_release,
 };
 
-static struct config_item_type netconsole_target_type = {
+static const struct config_item_type netconsole_target_type = {
 	.ct_attrs		= netconsole_target_attrs,
 	.ct_item_ops		= &netconsole_target_item_ops,
 	.ct_owner		= THIS_MODULE,
@@ -682,7 +682,7 @@  static void drop_netconsole_target(struct config_group *group,
 	.drop_item	= drop_netconsole_target,
 };
 
-static struct config_item_type netconsole_subsys_type = {
+static const struct config_item_type netconsole_subsys_type = {
 	.ct_group_ops	= &netconsole_subsys_group_ops,
 	.ct_owner	= THIS_MODULE,
 };