Re: [PATCH 1/2][NETLABEL]: Shrink the genl-ops registration code.

2008-02-17 Thread David Miller
From: Paul Moore [EMAIL PROTECTED]
Date: Wed, 13 Feb 2008 08:33:08 -0500

 On Wednesday 13 February 2008 6:09:44 am Pavel Emelyanov wrote:
  Turning them to array and registration in a loop saves
  80 lines of code and ~300 bytes from text section.
 
  Signed-off-by: Pavel Emelyanov [EMAIL PROTECTED]
 
 Definitely an improvement, thank you.
 
 Acked-by: Paul Moore [EMAIL PROTECTED]

Applied.
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2][NETLABEL]: Shrink the genl-ops registration code.

2008-02-13 Thread Pavel Emelyanov
Turning them to array and registration in a loop saves
80 lines of code and ~300 bytes from text section.

Signed-off-by: Pavel Emelyanov [EMAIL PROTECTED]

---
 net/netlabel/netlabel_cipso_v4.c  |   43 +++
 net/netlabel/netlabel_mgmt.c  |   79 ++---
 net/netlabel/netlabel_unlabeled.c |   86 ++--
 3 files changed, 64 insertions(+), 144 deletions(-)

diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c
index c7ad64d..283ff4a 100644
--- a/net/netlabel/netlabel_cipso_v4.c
+++ b/net/netlabel/netlabel_cipso_v4.c
@@ -718,36 +718,35 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, 
struct genl_info *info)
  * 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,
.flags = GENL_ADMIN_PERM,
.policy = netlbl_cipsov4_genl_policy,
.doit = netlbl_cipsov4_add,
.dumpit = NULL,
-};
-
-static struct genl_ops netlbl_cipsov4_genl_c_remove = {
+   },
+   {
.cmd = NLBL_CIPSOV4_C_REMOVE,
.flags = GENL_ADMIN_PERM,
.policy = netlbl_cipsov4_genl_policy,
.doit = netlbl_cipsov4_remove,
.dumpit = NULL,
-};
-
-static struct genl_ops netlbl_cipsov4_genl_c_list = {
+   },
+   {
.cmd = NLBL_CIPSOV4_C_LIST,
.flags = 0,
.policy = netlbl_cipsov4_genl_policy,
.doit = netlbl_cipsov4_list,
.dumpit = NULL,
-};
-
-static struct genl_ops netlbl_cipsov4_genl_c_listall = {
+   },
+   {
.cmd = NLBL_CIPSOV4_C_LISTALL,
.flags = 0,
.policy = netlbl_cipsov4_genl_policy,
.doit = NULL,
.dumpit = netlbl_cipsov4_listall,
+   },
 };
 
 /*
@@ -764,28 +763,18 @@ static struct genl_ops netlbl_cipsov4_genl_c_listall = {
  */
 int netlbl_cipsov4_genl_init(void)
 {
-   int ret_val;
+   int ret_val, i;
 
ret_val = genl_register_family(netlbl_cipsov4_gnl_family);
if (ret_val != 0)
return ret_val;
 
-   ret_val = genl_register_ops(netlbl_cipsov4_gnl_family,
-   netlbl_cipsov4_genl_c_add);
-   if (ret_val != 0)
-   return ret_val;
-   ret_val = genl_register_ops(netlbl_cipsov4_gnl_family,
-   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;
+   for (i = 0; i  ARRAY_SIZE(netlbl_cipsov4_ops); i++) {
+   ret_val = genl_register_ops(netlbl_cipsov4_gnl_family,
+   netlbl_cipsov4_ops[i]);
+   if (ret_val != 0)
+   return ret_val;
+   }
 
return 0;
 }
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c
index e2258dc..05d9886 100644
--- a/net/netlabel/netlabel_mgmt.c
+++ b/net/netlabel/netlabel_mgmt.c
@@ -517,68 +517,63 @@ version_failure:
  * 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,
.flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_add,
.dumpit = NULL,
-};
-
-static struct genl_ops netlbl_mgmt_genl_c_remove = {
+   },
+   {
.cmd = NLBL_MGMT_C_REMOVE,
.flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_remove,
.dumpit = NULL,
-};
-
-static struct genl_ops netlbl_mgmt_genl_c_listall = {
+   },
+   {
.cmd = NLBL_MGMT_C_LISTALL,
.flags = 0,
.policy = netlbl_mgmt_genl_policy,
.doit = NULL,
.dumpit = netlbl_mgmt_listall,
-};
-
-static struct genl_ops netlbl_mgmt_genl_c_adddef = {
+   },
+   {
.cmd = NLBL_MGMT_C_ADDDEF,
.flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_adddef,
.dumpit = NULL,
-};
-
-static struct genl_ops netlbl_mgmt_genl_c_removedef = {
+   },
+   {
.cmd = NLBL_MGMT_C_REMOVEDEF,
.flags = GENL_ADMIN_PERM,
.policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_removedef,
.dumpit = NULL,
-};
-
-static struct genl_ops netlbl_mgmt_genl_c_listdef = {
+   },
+   {
.cmd = NLBL_MGMT_C_LISTDEF,
.flags = 0,
.policy = netlbl_mgmt_genl_policy,
.doit = netlbl_mgmt_listdef,
.dumpit = NULL,
-};
-

Re: [PATCH 1/2][NETLABEL]: Shrink the genl-ops registration code.

2008-02-13 Thread Paul Moore
On Wednesday 13 February 2008 6:09:44 am Pavel Emelyanov wrote:
 Turning them to array and registration in a loop saves
 80 lines of code and ~300 bytes from text section.

 Signed-off-by: Pavel Emelyanov [EMAIL PROTECTED]

Definitely an improvement, thank you.

Acked-by: Paul Moore [EMAIL PROTECTED]

 ---
  net/netlabel/netlabel_cipso_v4.c  |   43 +++
  net/netlabel/netlabel_mgmt.c  |   79 ++---
  net/netlabel/netlabel_unlabeled.c |   86
 ++-- 3 files changed, 64 insertions(+), 144
 deletions(-)

 diff --git a/net/netlabel/netlabel_cipso_v4.c
 b/net/netlabel/netlabel_cipso_v4.c index c7ad64d..283ff4a 100644
 --- a/net/netlabel/netlabel_cipso_v4.c
 +++ b/net/netlabel/netlabel_cipso_v4.c
 @@ -718,36 +718,35 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb,
 struct genl_info *info) * 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,
   .flags = GENL_ADMIN_PERM,
   .policy = netlbl_cipsov4_genl_policy,
   .doit = netlbl_cipsov4_add,
   .dumpit = NULL,
 -};
 -
 -static struct genl_ops netlbl_cipsov4_genl_c_remove = {
 + },
 + {
   .cmd = NLBL_CIPSOV4_C_REMOVE,
   .flags = GENL_ADMIN_PERM,
   .policy = netlbl_cipsov4_genl_policy,
   .doit = netlbl_cipsov4_remove,
   .dumpit = NULL,
 -};
 -
 -static struct genl_ops netlbl_cipsov4_genl_c_list = {
 + },
 + {
   .cmd = NLBL_CIPSOV4_C_LIST,
   .flags = 0,
   .policy = netlbl_cipsov4_genl_policy,
   .doit = netlbl_cipsov4_list,
   .dumpit = NULL,
 -};
 -
 -static struct genl_ops netlbl_cipsov4_genl_c_listall = {
 + },
 + {
   .cmd = NLBL_CIPSOV4_C_LISTALL,
   .flags = 0,
   .policy = netlbl_cipsov4_genl_policy,
   .doit = NULL,
   .dumpit = netlbl_cipsov4_listall,
 + },
  };

  /*
 @@ -764,28 +763,18 @@ static struct genl_ops netlbl_cipsov4_genl_c_listall
 = { */
  int netlbl_cipsov4_genl_init(void)
  {
 - int ret_val;
 + int ret_val, i;

   ret_val = genl_register_family(netlbl_cipsov4_gnl_family);
   if (ret_val != 0)
   return ret_val;

 - ret_val = genl_register_ops(netlbl_cipsov4_gnl_family,
 - netlbl_cipsov4_genl_c_add);
 - if (ret_val != 0)
 - return ret_val;
 - ret_val = genl_register_ops(netlbl_cipsov4_gnl_family,
 - 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;
 + for (i = 0; i  ARRAY_SIZE(netlbl_cipsov4_ops); i++) {
 + ret_val = genl_register_ops(netlbl_cipsov4_gnl_family,
 + netlbl_cipsov4_ops[i]);
 + if (ret_val != 0)
 + return ret_val;
 + }

   return 0;
  }
 diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c
 index e2258dc..05d9886 100644
 --- a/net/netlabel/netlabel_mgmt.c
 +++ b/net/netlabel/netlabel_mgmt.c
 @@ -517,68 +517,63 @@ version_failure:
   * 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,
   .flags = GENL_ADMIN_PERM,
   .policy = netlbl_mgmt_genl_policy,
   .doit = netlbl_mgmt_add,
   .dumpit = NULL,
 -};
 -
 -static struct genl_ops netlbl_mgmt_genl_c_remove = {
 + },
 + {
   .cmd = NLBL_MGMT_C_REMOVE,
   .flags = GENL_ADMIN_PERM,
   .policy = netlbl_mgmt_genl_policy,
   .doit = netlbl_mgmt_remove,
   .dumpit = NULL,
 -};
 -
 -static struct genl_ops netlbl_mgmt_genl_c_listall = {
 + },
 + {
   .cmd = NLBL_MGMT_C_LISTALL,
   .flags = 0,
   .policy = netlbl_mgmt_genl_policy,
   .doit = NULL,
   .dumpit = netlbl_mgmt_listall,
 -};
 -
 -static struct genl_ops netlbl_mgmt_genl_c_adddef = {
 + },
 + {
   .cmd = NLBL_MGMT_C_ADDDEF,
   .flags = GENL_ADMIN_PERM,
   .policy = netlbl_mgmt_genl_policy,
   .doit = netlbl_mgmt_adddef,
   .dumpit = NULL,
 -};
 -
 -static struct genl_ops netlbl_mgmt_genl_c_removedef = {
 + },
 + {
   .cmd = NLBL_MGMT_C_REMOVEDEF,
   .flags = GENL_ADMIN_PERM,
   .policy = netlbl_mgmt_genl_policy,
   .doit = netlbl_mgmt_removedef,
   .dumpit = NULL,
 -};
 -
 -static struct genl_ops netlbl_mgmt_genl_c_listdef = {
 + },
 + {
   .cmd = NLBL_MGMT_C_LISTDEF,
   .flags = 0,
   .policy =