From: Jesper Juhl kfree(NULL) is legal. Signed-off-by: Jesper Juhl Acked-by: Stephen Smalley Signed-off-by: Andrew Morton --- security/selinux/hooks.c | 3 +-- security/selinux/selinuxfs.c | 9 +++------ security/selinux/ss/conditional.c | 9 +++------ security/selinux/ss/policydb.c | 15 +++++---------- security/selinux/ss/services.c | 6 ++---- 5 files changed, 14 insertions(+), 28 deletions(-) diff -puN security/selinux/hooks.c~dont-do-pointless-null-checks-and-casts-before-kfree security/selinux/hooks.c --- 25/security/selinux/hooks.c~dont-do-pointless-null-checks-and-casts-before-kfree 2005-05-09 20:10:20.000000000 -0700 +++ 25-akpm/security/selinux/hooks.c 2005-05-09 20:10:20.000000000 -0700 @@ -1658,9 +1658,8 @@ static int selinux_bprm_secureexec (stru static void selinux_bprm_free_security(struct linux_binprm *bprm) { - struct bprm_security_struct *bsec = bprm->security; + kfree(bprm->security); bprm->security = NULL; - kfree(bsec); } extern struct vfsmount *selinuxfs_mount; diff -puN security/selinux/selinuxfs.c~dont-do-pointless-null-checks-and-casts-before-kfree security/selinux/selinuxfs.c --- 25/security/selinux/selinuxfs.c~dont-do-pointless-null-checks-and-casts-before-kfree 2005-05-09 20:10:20.000000000 -0700 +++ 25-akpm/security/selinux/selinuxfs.c 2005-05-09 20:10:20.000000000 -0700 @@ -951,8 +951,7 @@ static int sel_make_bools(void) u32 sid; /* remove any existing files */ - if (bool_pending_values) - kfree(bool_pending_values); + kfree(bool_pending_values); sel_remove_bools(dir); @@ -997,10 +996,8 @@ static int sel_make_bools(void) out: free_page((unsigned long)page); if (names) { - for (i = 0; i < num; i++) { - if (names[i]) - kfree(names[i]); - } + for (i = 0; i < num; i++) + kfree(names[i]); kfree(names); } return ret; diff -puN security/selinux/ss/conditional.c~dont-do-pointless-null-checks-and-casts-before-kfree security/selinux/ss/conditional.c --- 25/security/selinux/ss/conditional.c~dont-do-pointless-null-checks-and-casts-before-kfree 2005-05-09 20:10:20.000000000 -0700 +++ 25-akpm/security/selinux/ss/conditional.c 2005-05-09 20:10:20.000000000 -0700 @@ -166,16 +166,14 @@ static void cond_list_destroy(struct con void cond_policydb_destroy(struct policydb *p) { - if (p->bool_val_to_struct != NULL) - kfree(p->bool_val_to_struct); + kfree(p->bool_val_to_struct); avtab_destroy(&p->te_cond_avtab); cond_list_destroy(p->cond_list); } int cond_init_bool_indexes(struct policydb *p) { - if (p->bool_val_to_struct) - kfree(p->bool_val_to_struct); + kfree(p->bool_val_to_struct); p->bool_val_to_struct = (struct cond_bool_datum**) kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum*), GFP_KERNEL); if (!p->bool_val_to_struct) @@ -185,8 +183,7 @@ int cond_init_bool_indexes(struct policy int cond_destroy_bool(void *key, void *datum, void *p) { - if (key) - kfree(key); + kfree(key); kfree(datum); return 0; } diff -puN security/selinux/ss/policydb.c~dont-do-pointless-null-checks-and-casts-before-kfree security/selinux/ss/policydb.c --- 25/security/selinux/ss/policydb.c~dont-do-pointless-null-checks-and-casts-before-kfree 2005-05-09 20:10:20.000000000 -0700 +++ 25-akpm/security/selinux/ss/policydb.c 2005-05-09 20:10:20.000000000 -0700 @@ -590,17 +590,12 @@ void policydb_destroy(struct policydb *p hashtab_destroy(p->symtab[i].table); } - for (i = 0; i < SYM_NUM; i++) { - if (p->sym_val_to_name[i]) - kfree(p->sym_val_to_name[i]); - } + for (i = 0; i < SYM_NUM; i++) + kfree(p->sym_val_to_name[i]); - if (p->class_val_to_struct) - kfree(p->class_val_to_struct); - if (p->role_val_to_struct) - kfree(p->role_val_to_struct); - if (p->user_val_to_struct) - kfree(p->user_val_to_struct); + kfree(p->class_val_to_struct); + kfree(p->role_val_to_struct); + kfree(p->user_val_to_struct); avtab_destroy(&p->te_avtab); diff -puN security/selinux/ss/services.c~dont-do-pointless-null-checks-and-casts-before-kfree security/selinux/ss/services.c --- 25/security/selinux/ss/services.c~dont-do-pointless-null-checks-and-casts-before-kfree 2005-05-09 20:10:20.000000000 -0700 +++ 25-akpm/security/selinux/ss/services.c 2005-05-09 20:10:20.000000000 -0700 @@ -1705,11 +1705,9 @@ out: err: if (*names) { for (i = 0; i < *len; i++) - if ((*names)[i]) - kfree((*names)[i]); + kfree((*names)[i]); } - if (*values) - kfree(*values); + kfree(*values); goto out; } _