if (ns_name) {
                ns = aa_prepare_ns(view, ns_name);
                if (IS_ERR(ns)) {
+                       op = OP_PROF_LOAD;
                        info = "failed to prepare namespace";
                        error = PTR_ERR(ns);
                        ns = NULL;
+                       ent = NULL;
                        goto fail;
                }
        } else
        /* audit cause of failure */
        op = (!ent->old) ? OP_PROF_LOAD : OP_PROF_REPL;
 fail:
-       audit_policy(profile, op, ns_name, ent->new->base.hname,
+       audit_policy(profile, op, ns_name, ent ? ent->new->base.hname : NULL,
                     info, error);
        /* audit status that rest of profiles in the atomic set failed too */
        info = "valid profile in failed atomic policy load";
                        /* skip entry that caused failure */
                        continue;
                }
-               op = (!ent->old) ? OP_PROF_LOAD : OP_PROF_REPL;
+               op = (!tmp->old) ? OP_PROF_LOAD : OP_PROF_REPL;
                audit_policy(profile, op, ns_name,
                             tmp->new->base.hname, info, error);
        }