Commit 227c43c3 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller

[NETLABEL]: Shrink the genl-ops registration code.

Turning them to array and registration in a loop saves
80 lines of code and ~300 bytes from text section.
Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
Acked-by: default avatarPaul Moore <paul.moore@hp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f47b7257
...@@ -718,36 +718,35 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info) ...@@ -718,36 +718,35 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info)
* NetLabel Generic NETLINK Command Definitions * NetLabel Generic NETLINK Command Definitions
*/ */
static struct genl_ops netlbl_cipsov4_genl_c_add = { static struct genl_ops netlbl_cipsov4_ops[] = {
{
.cmd = NLBL_CIPSOV4_C_ADD, .cmd = NLBL_CIPSOV4_C_ADD,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_cipsov4_genl_policy, .policy = netlbl_cipsov4_genl_policy,
.doit = netlbl_cipsov4_add, .doit = netlbl_cipsov4_add,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_cipsov4_genl_c_remove = {
.cmd = NLBL_CIPSOV4_C_REMOVE, .cmd = NLBL_CIPSOV4_C_REMOVE,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_cipsov4_genl_policy, .policy = netlbl_cipsov4_genl_policy,
.doit = netlbl_cipsov4_remove, .doit = netlbl_cipsov4_remove,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_cipsov4_genl_c_list = {
.cmd = NLBL_CIPSOV4_C_LIST, .cmd = NLBL_CIPSOV4_C_LIST,
.flags = 0, .flags = 0,
.policy = netlbl_cipsov4_genl_policy, .policy = netlbl_cipsov4_genl_policy,
.doit = netlbl_cipsov4_list, .doit = netlbl_cipsov4_list,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_cipsov4_genl_c_listall = {
.cmd = NLBL_CIPSOV4_C_LISTALL, .cmd = NLBL_CIPSOV4_C_LISTALL,
.flags = 0, .flags = 0,
.policy = netlbl_cipsov4_genl_policy, .policy = netlbl_cipsov4_genl_policy,
.doit = NULL, .doit = NULL,
.dumpit = netlbl_cipsov4_listall, .dumpit = netlbl_cipsov4_listall,
},
}; };
/* /*
...@@ -764,28 +763,18 @@ static struct genl_ops netlbl_cipsov4_genl_c_listall = { ...@@ -764,28 +763,18 @@ static struct genl_ops netlbl_cipsov4_genl_c_listall = {
*/ */
int netlbl_cipsov4_genl_init(void) int netlbl_cipsov4_genl_init(void)
{ {
int ret_val; int ret_val, i;
ret_val = genl_register_family(&netlbl_cipsov4_gnl_family); ret_val = genl_register_family(&netlbl_cipsov4_gnl_family);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
ret_val = genl_register_ops(&netlbl_cipsov4_gnl_family, for (i = 0; i < ARRAY_SIZE(netlbl_cipsov4_ops); i++) {
&netlbl_cipsov4_genl_c_add); ret_val = genl_register_ops(&netlbl_cipsov4_gnl_family,
if (ret_val != 0) &netlbl_cipsov4_ops[i]);
return ret_val; if (ret_val != 0)
ret_val = genl_register_ops(&netlbl_cipsov4_gnl_family, return ret_val;
&netlbl_cipsov4_genl_c_remove); }
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_cipsov4_gnl_family,
&netlbl_cipsov4_genl_c_list);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_cipsov4_gnl_family,
&netlbl_cipsov4_genl_c_listall);
if (ret_val != 0)
return ret_val;
return 0; return 0;
} }
...@@ -517,68 +517,63 @@ static int netlbl_mgmt_version(struct sk_buff *skb, struct genl_info *info) ...@@ -517,68 +517,63 @@ static int netlbl_mgmt_version(struct sk_buff *skb, struct genl_info *info)
* NetLabel Generic NETLINK Command Definitions * NetLabel Generic NETLINK Command Definitions
*/ */
static struct genl_ops netlbl_mgmt_genl_c_add = { static struct genl_ops netlbl_mgmt_genl_ops[] = {
{
.cmd = NLBL_MGMT_C_ADD, .cmd = NLBL_MGMT_C_ADD,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_add, .doit = netlbl_mgmt_add,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_mgmt_genl_c_remove = {
.cmd = NLBL_MGMT_C_REMOVE, .cmd = NLBL_MGMT_C_REMOVE,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_remove, .doit = netlbl_mgmt_remove,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_mgmt_genl_c_listall = {
.cmd = NLBL_MGMT_C_LISTALL, .cmd = NLBL_MGMT_C_LISTALL,
.flags = 0, .flags = 0,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = NULL, .doit = NULL,
.dumpit = netlbl_mgmt_listall, .dumpit = netlbl_mgmt_listall,
}; },
{
static struct genl_ops netlbl_mgmt_genl_c_adddef = {
.cmd = NLBL_MGMT_C_ADDDEF, .cmd = NLBL_MGMT_C_ADDDEF,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_adddef, .doit = netlbl_mgmt_adddef,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_mgmt_genl_c_removedef = {
.cmd = NLBL_MGMT_C_REMOVEDEF, .cmd = NLBL_MGMT_C_REMOVEDEF,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_removedef, .doit = netlbl_mgmt_removedef,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_mgmt_genl_c_listdef = {
.cmd = NLBL_MGMT_C_LISTDEF, .cmd = NLBL_MGMT_C_LISTDEF,
.flags = 0, .flags = 0,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_listdef, .doit = netlbl_mgmt_listdef,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_mgmt_genl_c_protocols = {
.cmd = NLBL_MGMT_C_PROTOCOLS, .cmd = NLBL_MGMT_C_PROTOCOLS,
.flags = 0, .flags = 0,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = NULL, .doit = NULL,
.dumpit = netlbl_mgmt_protocols, .dumpit = netlbl_mgmt_protocols,
}; },
{
static struct genl_ops netlbl_mgmt_genl_c_version = {
.cmd = NLBL_MGMT_C_VERSION, .cmd = NLBL_MGMT_C_VERSION,
.flags = 0, .flags = 0,
.policy = netlbl_mgmt_genl_policy, .policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_version, .doit = netlbl_mgmt_version,
.dumpit = NULL, .dumpit = NULL,
},
}; };
/* /*
...@@ -595,44 +590,18 @@ static struct genl_ops netlbl_mgmt_genl_c_version = { ...@@ -595,44 +590,18 @@ static struct genl_ops netlbl_mgmt_genl_c_version = {
*/ */
int netlbl_mgmt_genl_init(void) int netlbl_mgmt_genl_init(void)
{ {
int ret_val; int ret_val, i;
ret_val = genl_register_family(&netlbl_mgmt_gnl_family); ret_val = genl_register_family(&netlbl_mgmt_gnl_family);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family, for (i = 0; i < ARRAY_SIZE(netlbl_mgmt_genl_ops); i++) {
&netlbl_mgmt_genl_c_add); ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
if (ret_val != 0) &netlbl_mgmt_genl_ops[i]);
return ret_val; if (ret_val != 0)
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family, return ret_val;
&netlbl_mgmt_genl_c_remove); }
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
&netlbl_mgmt_genl_c_listall);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
&netlbl_mgmt_genl_c_adddef);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
&netlbl_mgmt_genl_c_removedef);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
&netlbl_mgmt_genl_c_listdef);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
&netlbl_mgmt_genl_c_protocols);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
&netlbl_mgmt_genl_c_version);
if (ret_val != 0)
return ret_val;
return 0; return 0;
} }
...@@ -1553,68 +1553,63 @@ static int netlbl_unlabel_staticlistdef(struct sk_buff *skb, ...@@ -1553,68 +1553,63 @@ static int netlbl_unlabel_staticlistdef(struct sk_buff *skb,
* NetLabel Generic NETLINK Command Definitions * NetLabel Generic NETLINK Command Definitions
*/ */
static struct genl_ops netlbl_unlabel_genl_c_staticadd = { static struct genl_ops netlbl_unlabel_genl_ops[] = {
{
.cmd = NLBL_UNLABEL_C_STATICADD, .cmd = NLBL_UNLABEL_C_STATICADD,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = netlbl_unlabel_staticadd, .doit = netlbl_unlabel_staticadd,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_unlabel_genl_c_staticremove = {
.cmd = NLBL_UNLABEL_C_STATICREMOVE, .cmd = NLBL_UNLABEL_C_STATICREMOVE,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = netlbl_unlabel_staticremove, .doit = netlbl_unlabel_staticremove,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_unlabel_genl_c_staticlist = {
.cmd = NLBL_UNLABEL_C_STATICLIST, .cmd = NLBL_UNLABEL_C_STATICLIST,
.flags = 0, .flags = 0,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = NULL, .doit = NULL,
.dumpit = netlbl_unlabel_staticlist, .dumpit = netlbl_unlabel_staticlist,
}; },
{
static struct genl_ops netlbl_unlabel_genl_c_staticadddef = {
.cmd = NLBL_UNLABEL_C_STATICADDDEF, .cmd = NLBL_UNLABEL_C_STATICADDDEF,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = netlbl_unlabel_staticadddef, .doit = netlbl_unlabel_staticadddef,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_unlabel_genl_c_staticremovedef = {
.cmd = NLBL_UNLABEL_C_STATICREMOVEDEF, .cmd = NLBL_UNLABEL_C_STATICREMOVEDEF,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = netlbl_unlabel_staticremovedef, .doit = netlbl_unlabel_staticremovedef,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_unlabel_genl_c_staticlistdef = {
.cmd = NLBL_UNLABEL_C_STATICLISTDEF, .cmd = NLBL_UNLABEL_C_STATICLISTDEF,
.flags = 0, .flags = 0,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = NULL, .doit = NULL,
.dumpit = netlbl_unlabel_staticlistdef, .dumpit = netlbl_unlabel_staticlistdef,
}; },
{
static struct genl_ops netlbl_unlabel_genl_c_accept = {
.cmd = NLBL_UNLABEL_C_ACCEPT, .cmd = NLBL_UNLABEL_C_ACCEPT,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = netlbl_unlabel_accept, .doit = netlbl_unlabel_accept,
.dumpit = NULL, .dumpit = NULL,
}; },
{
static struct genl_ops netlbl_unlabel_genl_c_list = {
.cmd = NLBL_UNLABEL_C_LIST, .cmd = NLBL_UNLABEL_C_LIST,
.flags = 0, .flags = 0,
.policy = netlbl_unlabel_genl_policy, .policy = netlbl_unlabel_genl_policy,
.doit = netlbl_unlabel_list, .doit = netlbl_unlabel_list,
.dumpit = NULL, .dumpit = NULL,
},
}; };
/* /*
...@@ -1631,51 +1626,18 @@ static struct genl_ops netlbl_unlabel_genl_c_list = { ...@@ -1631,51 +1626,18 @@ static struct genl_ops netlbl_unlabel_genl_c_list = {
*/ */
int netlbl_unlabel_genl_init(void) int netlbl_unlabel_genl_init(void)
{ {
int ret_val; int ret_val, i;
ret_val = genl_register_family(&netlbl_unlabel_gnl_family); ret_val = genl_register_family(&netlbl_unlabel_gnl_family);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family, for (i = 0; i < ARRAY_SIZE(netlbl_unlabel_genl_ops); i++) {
&netlbl_unlabel_genl_c_staticadd); ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
if (ret_val != 0) &netlbl_unlabel_genl_ops[i]);
return ret_val; if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family, }
&netlbl_unlabel_genl_c_staticremove);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
&netlbl_unlabel_genl_c_staticlist);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
&netlbl_unlabel_genl_c_staticadddef);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
&netlbl_unlabel_genl_c_staticremovedef);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
&netlbl_unlabel_genl_c_staticlistdef);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
&netlbl_unlabel_genl_c_accept);
if (ret_val != 0)
return ret_val;
ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
&netlbl_unlabel_genl_c_list);
if (ret_val != 0)
return ret_val;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment