nfs4: minor callback code simplification, comment
[safe/jmp/linux-2.6] / net / tipc / user_reg.c
index 64165ec..5069288 100644 (file)
@@ -1,9 +1,8 @@
 /*
  * net/tipc/user_reg.c: TIPC user registry code
- * 
- * Copyright (c) 2003-2005, Ericsson Research Canada
+ *
+ * Copyright (c) 2000-2006, Ericsson AB
  * Copyright (c) 2004-2005, Wind River Systems
- * Copyright (c) 2005-2006, Ericsson AB
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,7 +40,7 @@
 /*
  * TIPC user registry keeps track of users of the tipc_port interface.
  *
- * The registry utilizes an array of "TIPC user" entries; 
+ * The registry utilizes an array of "TIPC user" entries;
  * a user's ID is the index of their associated array entry.
  * Array entry 0 is not used, so userid 0 is not valid;
  * TIPC sometimes uses this value to denote an anonymous user.
@@ -52,7 +51,7 @@
  * struct tipc_user - registered TIPC user info
  * @next: index of next free registry entry (or -1 for an allocated entry)
  * @callback: ptr to routine to call when TIPC mode changes (NULL if none)
- * @usr_handle: user-defined value passed to callback routine 
+ * @usr_handle: user-defined value passed to callback routine
  * @ports: list of user ports owned by the user
  */
 
@@ -66,13 +65,13 @@ struct tipc_user {
 #define MAX_USERID 64
 #define USER_LIST_SIZE ((MAX_USERID + 1) * sizeof(struct tipc_user))
 
-static struct tipc_user *users = 0;
+static struct tipc_user *users = NULL;
 static u32 next_free_user = MAX_USERID + 1;
-static spinlock_t reg_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(reg_lock);
 
 /**
  * reg_init - create TIPC user registry (but don't activate it)
- * 
+ *
  * If registry has been pre-initialized it is left "as is".
  * NOTE: This routine may be called when TIPC is inactive.
  */
@@ -80,12 +79,11 @@ static spinlock_t reg_lock = SPIN_LOCK_UNLOCKED;
 static int reg_init(void)
 {
        u32 i;
-       
+
        spin_lock_bh(&reg_lock);
        if (!users) {
-               users = (struct tipc_user *)kmalloc(USER_LIST_SIZE, GFP_ATOMIC);
+               users = kzalloc(USER_LIST_SIZE, GFP_ATOMIC);
                if (users) {
-                       memset(users, 0, USER_LIST_SIZE);
                        for (i = 1; i <= MAX_USERID; i++) {
                                users[i].next = i - 1;
                        }
@@ -93,7 +91,7 @@ static int reg_init(void)
                }
        }
        spin_unlock_bh(&reg_lock);
-       return users ? TIPC_OK : -ENOMEM;
+       return users ? 0 : -ENOMEM;
 }
 
 /**
@@ -115,10 +113,10 @@ static void reg_callback(struct tipc_user *user_ptr)
 }
 
 /**
- * reg_start - activate TIPC user registry
+ * tipc_reg_start - activate TIPC user registry
  */
 
-int reg_start(void)
+int tipc_reg_start(void)
 {
        u32 u;
        int res;
@@ -128,18 +126,18 @@ int reg_start(void)
 
        for (u = 1; u <= MAX_USERID; u++) {
                if (users[u].callback)
-                       k_signal((Handler)reg_callback,
-                                (unsigned long)&users[u]);
+                       tipc_k_signal((Handler)reg_callback,
+                                     (unsigned long)&users[u]);
        }
-       return TIPC_OK;
+       return 0;
 }
 
 /**
- * reg_stop - shut down & delete TIPC user registry
+ * tipc_reg_stop - shut down & delete TIPC user registry
  */
 
-void reg_stop(void)
-{               
+void tipc_reg_stop(void)
+{
        int id;
 
        if (!users)
@@ -150,7 +148,7 @@ void reg_stop(void)
                        reg_callback(&users[id]);
        }
        kfree(users);
-       users = 0;
+       users = NULL;
 }
 
 /**
@@ -176,17 +174,17 @@ int tipc_attach(u32 *userid, tipc_mode_event cb, void *usr_handle)
        user_ptr = &users[next_free_user];
        *userid = next_free_user;
        next_free_user = user_ptr->next;
-       user_ptr->next = -1; 
+       user_ptr->next = -1;
        spin_unlock_bh(&reg_lock);
 
        user_ptr->callback = cb;
        user_ptr->usr_handle = usr_handle;
        INIT_LIST_HEAD(&user_ptr->ports);
        atomic_inc(&tipc_user_count);
-       
+
        if (cb && (tipc_mode != TIPC_NOT_RUNNING))
-               k_signal((Handler)reg_callback, (unsigned long)user_ptr);
-       return TIPC_OK;
+               tipc_k_signal((Handler)reg_callback, (unsigned long)user_ptr);
+       return 0;
 }
 
 /**
@@ -209,30 +207,30 @@ void tipc_detach(u32 userid)
        }
 
        user_ptr = &users[userid];
-        user_ptr->callback = NULL;              
+       user_ptr->callback = NULL;
        INIT_LIST_HEAD(&ports_temp);
-        list_splice(&user_ptr->ports, &ports_temp);
+       list_splice(&user_ptr->ports, &ports_temp);
        user_ptr->next = next_free_user;
        next_free_user = userid;
        spin_unlock_bh(&reg_lock);
 
        atomic_dec(&tipc_user_count);
 
-        list_for_each_entry_safe(up_ptr, temp_up_ptr, &ports_temp, uport_list) {
+       list_for_each_entry_safe(up_ptr, temp_up_ptr, &ports_temp, uport_list) {
                tipc_deleteport(up_ptr->ref);
        }
 }
 
 /**
- * reg_add_port - register a user's driver port
+ * tipc_reg_add_port - register a user's driver port
  */
 
-int reg_add_port(struct user_port *up_ptr)
+int tipc_reg_add_port(struct user_port *up_ptr)
 {
        struct tipc_user *user_ptr;
 
        if (up_ptr->user_ref == 0)
-               return TIPC_OK;
+               return 0;
        if (up_ptr->user_ref > MAX_USERID)
                return -EINVAL;
        if ((tipc_mode == TIPC_NOT_RUNNING) || !users )
@@ -242,17 +240,17 @@ int reg_add_port(struct user_port *up_ptr)
        user_ptr = &users[up_ptr->user_ref];
        list_add(&up_ptr->uport_list, &user_ptr->ports);
        spin_unlock_bh(&reg_lock);
-       return TIPC_OK;
+       return 0;
 }
 
 /**
- * reg_remove_port - deregister a user's driver port
+ * tipc_reg_remove_port - deregister a user's driver port
  */
 
-int reg_remove_port(struct user_port *up_ptr)
+int tipc_reg_remove_port(struct user_port *up_ptr)
 {
        if (up_ptr->user_ref == 0)
-               return TIPC_OK;
+               return 0;
        if (up_ptr->user_ref > MAX_USERID)
                return -EINVAL;
        if (!users )
@@ -261,6 +259,6 @@ int reg_remove_port(struct user_port *up_ptr)
        spin_lock_bh(&reg_lock);
        list_del_init(&up_ptr->uport_list);
        spin_unlock_bh(&reg_lock);
-       return TIPC_OK;
+       return 0;
 }