+/**
+ * persona_init_end
+ *
+ * This function finalizes the persona initialization by marking it valid and
+ * adding it to the global list of personas. After unlocking the global list,
+ * the persona will be visible to the reset of the system. The function will
+ * only mark the persona valid if the input parameter 'error' is 0.
+ *
+ * Conditions:
+ * persona is initialized via persona_init_begin()
+ * global persona list is locked via lock_personas()
+ *
+ * Returns:
+ * global persona list is unlocked
+ */
+void
+persona_init_end(struct persona *persona, int error)
+{
+ if (persona == NULL) {
+ return;
+ }
+
+ /*
+ * If the pna_valid member is set to the INIT_TOKEN value, then it has
+ * successfully gone through persona_init_begin(), and we can mark it
+ * valid and make it visible to the rest of the system. However, if
+ * there was an error either during initialization or otherwise, we
+ * need to decrement the global count of personas because this one
+ * will be disposed-of by the callers invocation of persona_put().
+ */
+ if (error != 0 || persona->pna_valid == PERSONA_ALLOC_TOKEN) {
+ persona_dbg("ERROR:%d after initialization of %d (%s)", error, persona->pna_id, persona->pna_login);
+ /* remove this persona from the global count */
+ os_atomic_dec(&g_total_personas, relaxed);
+ } else if (error == 0 &&
+ persona->pna_valid == PERSONA_INIT_TOKEN) {
+ persona->pna_valid = PERSONA_MAGIC;
+ LIST_INSERT_HEAD(&all_personas, persona, pna_list);
+ persona_dbg("Initialization of %d (%s) Complete.", persona->pna_id, persona->pna_login);
+ }
+
+ unlock_personas();