staging: rt2860: use new hex_to_bin() method
[safe/jmp/linux-2.6] / net / tipc / user_reg.c
index 106200d..5069288 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * net/tipc/user_reg.c: TIPC user registry code
- * 
+ *
  * Copyright (c) 2000-2006, Ericsson AB
  * Copyright (c) 2004-2005, Wind River Systems
  * All rights reserved.
@@ -40,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.
@@ -51,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
  */
 
@@ -65,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.
  */
@@ -79,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;
                        }
@@ -92,7 +91,7 @@ static int reg_init(void)
                }
        }
        spin_unlock_bh(&reg_lock);
-       return users ? TIPC_OK : -ENOMEM;
+       return users ? 0 : -ENOMEM;
 }
 
 /**
@@ -130,7 +129,7 @@ int tipc_reg_start(void)
                        tipc_k_signal((Handler)reg_callback,
                                      (unsigned long)&users[u]);
        }
-       return TIPC_OK;
+       return 0;
 }
 
 /**
@@ -138,7 +137,7 @@ int tipc_reg_start(void)
  */
 
 void tipc_reg_stop(void)
-{               
+{
        int id;
 
        if (!users)
@@ -149,7 +148,7 @@ void tipc_reg_stop(void)
                        reg_callback(&users[id]);
        }
        kfree(users);
-       users = 0;
+       users = NULL;
 }
 
 /**
@@ -175,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))
                tipc_k_signal((Handler)reg_callback, (unsigned long)user_ptr);
-       return TIPC_OK;
+       return 0;
 }
 
 /**
@@ -208,16 +207,16 @@ 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);
        }
 }
@@ -231,7 +230,7 @@ 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 )
@@ -241,7 +240,7 @@ int tipc_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;
 }
 
 /**
@@ -251,7 +250,7 @@ int tipc_reg_add_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 )
@@ -260,6 +259,6 @@ int tipc_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;
 }