Commit dbc74c65 authored by Vesa-Matti Kari's avatar Vesa-Matti Kari Committed by James Morris

selinux: Unify for- and while-loop style

Replace "thing != NULL" comparisons with just "thing" to make
the code look more uniform (mixed styles were used even in the
same source file).
Signed-off-by: default avatarVesa-Matti Kari <vmkari@cc.helsinki.fi>
Acked-by: default avatarStephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 421fae06
...@@ -229,7 +229,7 @@ void avtab_destroy(struct avtab *h) ...@@ -229,7 +229,7 @@ void avtab_destroy(struct avtab *h)
for (i = 0; i < h->nslot; i++) { for (i = 0; i < h->nslot; i++) {
cur = h->htable[i]; cur = h->htable[i];
while (cur != NULL) { while (cur) {
temp = cur; temp = cur;
cur = cur->next; cur = cur->next;
kmem_cache_free(avtab_node_cachep, temp); kmem_cache_free(avtab_node_cachep, temp);
......
...@@ -29,7 +29,7 @@ static int cond_evaluate_expr(struct policydb *p, struct cond_expr *expr) ...@@ -29,7 +29,7 @@ static int cond_evaluate_expr(struct policydb *p, struct cond_expr *expr)
int s[COND_EXPR_MAXDEPTH]; int s[COND_EXPR_MAXDEPTH];
int sp = -1; int sp = -1;
for (cur = expr; cur != NULL; cur = cur->next) { for (cur = expr; cur; cur = cur->next) {
switch (cur->expr_type) { switch (cur->expr_type) {
case COND_BOOL: case COND_BOOL:
if (sp == (COND_EXPR_MAXDEPTH - 1)) if (sp == (COND_EXPR_MAXDEPTH - 1))
...@@ -97,14 +97,14 @@ int evaluate_cond_node(struct policydb *p, struct cond_node *node) ...@@ -97,14 +97,14 @@ int evaluate_cond_node(struct policydb *p, struct cond_node *node)
if (new_state == -1) if (new_state == -1)
printk(KERN_ERR "SELinux: expression result was undefined - disabling all rules.\n"); printk(KERN_ERR "SELinux: expression result was undefined - disabling all rules.\n");
/* turn the rules on or off */ /* turn the rules on or off */
for (cur = node->true_list; cur != NULL; cur = cur->next) { for (cur = node->true_list; cur; cur = cur->next) {
if (new_state <= 0) if (new_state <= 0)
cur->node->key.specified &= ~AVTAB_ENABLED; cur->node->key.specified &= ~AVTAB_ENABLED;
else else
cur->node->key.specified |= AVTAB_ENABLED; cur->node->key.specified |= AVTAB_ENABLED;
} }
for (cur = node->false_list; cur != NULL; cur = cur->next) { for (cur = node->false_list; cur; cur = cur->next) {
/* -1 or 1 */ /* -1 or 1 */
if (new_state) if (new_state)
cur->node->key.specified &= ~AVTAB_ENABLED; cur->node->key.specified &= ~AVTAB_ENABLED;
...@@ -128,7 +128,7 @@ int cond_policydb_init(struct policydb *p) ...@@ -128,7 +128,7 @@ int cond_policydb_init(struct policydb *p)
static void cond_av_list_destroy(struct cond_av_list *list) static void cond_av_list_destroy(struct cond_av_list *list)
{ {
struct cond_av_list *cur, *next; struct cond_av_list *cur, *next;
for (cur = list; cur != NULL; cur = next) { for (cur = list; cur; cur = next) {
next = cur->next; next = cur->next;
/* the avtab_ptr_t node is destroy by the avtab */ /* the avtab_ptr_t node is destroy by the avtab */
kfree(cur); kfree(cur);
...@@ -139,7 +139,7 @@ static void cond_node_destroy(struct cond_node *node) ...@@ -139,7 +139,7 @@ static void cond_node_destroy(struct cond_node *node)
{ {
struct cond_expr *cur_expr, *next_expr; struct cond_expr *cur_expr, *next_expr;
for (cur_expr = node->expr; cur_expr != NULL; cur_expr = next_expr) { for (cur_expr = node->expr; cur_expr; cur_expr = next_expr) {
next_expr = cur_expr->next; next_expr = cur_expr->next;
kfree(cur_expr); kfree(cur_expr);
} }
...@@ -155,7 +155,7 @@ static void cond_list_destroy(struct cond_node *list) ...@@ -155,7 +155,7 @@ static void cond_list_destroy(struct cond_node *list)
if (list == NULL) if (list == NULL)
return; return;
for (cur = list; cur != NULL; cur = next) { for (cur = list; cur; cur = next) {
next = cur->next; next = cur->next;
cond_node_destroy(cur); cond_node_destroy(cur);
} }
...@@ -291,7 +291,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum ...@@ -291,7 +291,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
goto err; goto err;
} }
found = 0; found = 0;
for (cur = other; cur != NULL; cur = cur->next) { for (cur = other; cur; cur = cur->next) {
if (cur->node == node_ptr) { if (cur->node == node_ptr) {
found = 1; found = 1;
break; break;
...@@ -485,7 +485,7 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, struct av_decisi ...@@ -485,7 +485,7 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, struct av_decisi
if (!ctab || !key || !avd) if (!ctab || !key || !avd)
return; return;
for (node = avtab_search_node(ctab, key); node != NULL; for (node = avtab_search_node(ctab, key); node;
node = avtab_search_node_next(node, key->specified)) { node = avtab_search_node_next(node, key->specified)) {
if ((u16)(AVTAB_ALLOWED|AVTAB_ENABLED) == if ((u16)(AVTAB_ALLOWED|AVTAB_ENABLED) ==
(node->key.specified & (AVTAB_ALLOWED|AVTAB_ENABLED))) (node->key.specified & (AVTAB_ALLOWED|AVTAB_ENABLED)))
......
...@@ -109,7 +109,7 @@ int ebitmap_netlbl_export(struct ebitmap *ebmap, ...@@ -109,7 +109,7 @@ int ebitmap_netlbl_export(struct ebitmap *ebmap,
*catmap = c_iter; *catmap = c_iter;
c_iter->startbit = e_iter->startbit & ~(NETLBL_CATMAP_SIZE - 1); c_iter->startbit = e_iter->startbit & ~(NETLBL_CATMAP_SIZE - 1);
while (e_iter != NULL) { while (e_iter) {
for (i = 0; i < EBITMAP_UNIT_NUMS; i++) { for (i = 0; i < EBITMAP_UNIT_NUMS; i++) {
unsigned int delta, e_startbit, c_endbit; unsigned int delta, e_startbit, c_endbit;
...@@ -197,7 +197,7 @@ int ebitmap_netlbl_import(struct ebitmap *ebmap, ...@@ -197,7 +197,7 @@ int ebitmap_netlbl_import(struct ebitmap *ebmap,
} }
} }
c_iter = c_iter->next; c_iter = c_iter->next;
} while (c_iter != NULL); } while (c_iter);
if (e_iter != NULL) if (e_iter != NULL)
ebmap->highbit = e_iter->startbit + EBITMAP_SIZE; ebmap->highbit = e_iter->startbit + EBITMAP_SIZE;
else else
......
...@@ -81,7 +81,7 @@ void *hashtab_search(struct hashtab *h, const void *key) ...@@ -81,7 +81,7 @@ void *hashtab_search(struct hashtab *h, const void *key)
hvalue = h->hash_value(h, key); hvalue = h->hash_value(h, key);
cur = h->htable[hvalue]; cur = h->htable[hvalue];
while (cur != NULL && h->keycmp(h, key, cur->key) > 0) while (cur && h->keycmp(h, key, cur->key) > 0)
cur = cur->next; cur = cur->next;
if (cur == NULL || (h->keycmp(h, key, cur->key) != 0)) if (cur == NULL || (h->keycmp(h, key, cur->key) != 0))
...@@ -100,7 +100,7 @@ void hashtab_destroy(struct hashtab *h) ...@@ -100,7 +100,7 @@ void hashtab_destroy(struct hashtab *h)
for (i = 0; i < h->size; i++) { for (i = 0; i < h->size; i++) {
cur = h->htable[i]; cur = h->htable[i];
while (cur != NULL) { while (cur) {
temp = cur; temp = cur;
cur = cur->next; cur = cur->next;
kfree(temp); kfree(temp);
...@@ -127,7 +127,7 @@ int hashtab_map(struct hashtab *h, ...@@ -127,7 +127,7 @@ int hashtab_map(struct hashtab *h,
for (i = 0; i < h->size; i++) { for (i = 0; i < h->size; i++) {
cur = h->htable[i]; cur = h->htable[i];
while (cur != NULL) { while (cur) {
ret = apply(cur->key, cur->datum, args); ret = apply(cur->key, cur->datum, args);
if (ret) if (ret)
return ret; return ret;
......
...@@ -356,7 +356,7 @@ static int context_struct_compute_av(struct context *scontext, ...@@ -356,7 +356,7 @@ static int context_struct_compute_av(struct context *scontext,
avkey.source_type = i + 1; avkey.source_type = i + 1;
avkey.target_type = j + 1; avkey.target_type = j + 1;
for (node = avtab_search_node(&policydb.te_avtab, &avkey); for (node = avtab_search_node(&policydb.te_avtab, &avkey);
node != NULL; node;
node = avtab_search_node_next(node, avkey.specified)) { node = avtab_search_node_next(node, avkey.specified)) {
if (node->key.specified == AVTAB_ALLOWED) if (node->key.specified == AVTAB_ALLOWED)
avd->allowed |= node->datum.data; avd->allowed |= node->datum.data;
...@@ -1037,7 +1037,7 @@ static int security_compute_sid(u32 ssid, ...@@ -1037,7 +1037,7 @@ static int security_compute_sid(u32 ssid,
/* If no permanent rule, also check for enabled conditional rules */ /* If no permanent rule, also check for enabled conditional rules */
if (!avdatum) { if (!avdatum) {
node = avtab_search_node(&policydb.te_cond_avtab, &avkey); node = avtab_search_node(&policydb.te_cond_avtab, &avkey);
for (; node != NULL; node = avtab_search_node_next(node, specified)) { for (; node; node = avtab_search_node_next(node, specified)) {
if (node->key.specified & AVTAB_ENABLED) { if (node->key.specified & AVTAB_ENABLED) {
avdatum = &node->datum; avdatum = &node->datum;
break; break;
...@@ -2050,7 +2050,7 @@ int security_set_bools(int len, int *values) ...@@ -2050,7 +2050,7 @@ int security_set_bools(int len, int *values)
policydb.bool_val_to_struct[i]->state = 0; policydb.bool_val_to_struct[i]->state = 0;
} }
for (cur = policydb.cond_list; cur != NULL; cur = cur->next) { for (cur = policydb.cond_list; cur; cur = cur->next) {
rc = evaluate_cond_node(&policydb, cur); rc = evaluate_cond_node(&policydb, cur);
if (rc) if (rc)
goto out; goto out;
...@@ -2102,7 +2102,7 @@ static int security_preserve_bools(struct policydb *p) ...@@ -2102,7 +2102,7 @@ static int security_preserve_bools(struct policydb *p)
if (booldatum) if (booldatum)
booldatum->state = bvalues[i]; booldatum->state = bvalues[i];
} }
for (cur = p->cond_list; cur != NULL; cur = cur->next) { for (cur = p->cond_list; cur; cur = cur->next) {
rc = evaluate_cond_node(p, cur); rc = evaluate_cond_node(p, cur);
if (rc) if (rc)
goto out; goto out;
......
...@@ -43,7 +43,7 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) ...@@ -43,7 +43,7 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context)
hvalue = SIDTAB_HASH(sid); hvalue = SIDTAB_HASH(sid);
prev = NULL; prev = NULL;
cur = s->htable[hvalue]; cur = s->htable[hvalue];
while (cur != NULL && sid > cur->sid) { while (cur && sid > cur->sid) {
prev = cur; prev = cur;
cur = cur->next; cur = cur->next;
} }
...@@ -92,7 +92,7 @@ static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force) ...@@ -92,7 +92,7 @@ static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)
hvalue = SIDTAB_HASH(sid); hvalue = SIDTAB_HASH(sid);
cur = s->htable[hvalue]; cur = s->htable[hvalue];
while (cur != NULL && sid > cur->sid) while (cur && sid > cur->sid)
cur = cur->next; cur = cur->next;
if (force && cur && sid == cur->sid && cur->context.len) if (force && cur && sid == cur->sid && cur->context.len)
...@@ -103,7 +103,7 @@ static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force) ...@@ -103,7 +103,7 @@ static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)
sid = SECINITSID_UNLABELED; sid = SECINITSID_UNLABELED;
hvalue = SIDTAB_HASH(sid); hvalue = SIDTAB_HASH(sid);
cur = s->htable[hvalue]; cur = s->htable[hvalue];
while (cur != NULL && sid > cur->sid) while (cur && sid > cur->sid)
cur = cur->next; cur = cur->next;
if (!cur || sid != cur->sid) if (!cur || sid != cur->sid)
return NULL; return NULL;
...@@ -136,7 +136,7 @@ int sidtab_map(struct sidtab *s, ...@@ -136,7 +136,7 @@ int sidtab_map(struct sidtab *s,
for (i = 0; i < SIDTAB_SIZE; i++) { for (i = 0; i < SIDTAB_SIZE; i++) {
cur = s->htable[i]; cur = s->htable[i];
while (cur != NULL) { while (cur) {
rc = apply(cur->sid, &cur->context, args); rc = apply(cur->sid, &cur->context, args);
if (rc) if (rc)
goto out; goto out;
...@@ -155,7 +155,7 @@ static inline u32 sidtab_search_context(struct sidtab *s, ...@@ -155,7 +155,7 @@ static inline u32 sidtab_search_context(struct sidtab *s,
for (i = 0; i < SIDTAB_SIZE; i++) { for (i = 0; i < SIDTAB_SIZE; i++) {
cur = s->htable[i]; cur = s->htable[i];
while (cur != NULL) { while (cur) {
if (context_cmp(&cur->context, context)) if (context_cmp(&cur->context, context))
return cur->sid; return cur->sid;
cur = cur->next; cur = cur->next;
...@@ -242,7 +242,7 @@ void sidtab_destroy(struct sidtab *s) ...@@ -242,7 +242,7 @@ void sidtab_destroy(struct sidtab *s)
for (i = 0; i < SIDTAB_SIZE; i++) { for (i = 0; i < SIDTAB_SIZE; i++) {
cur = s->htable[i]; cur = s->htable[i];
while (cur != NULL) { while (cur) {
temp = cur; temp = cur;
cur = cur->next; cur = cur->next;
context_destroy(&temp->context); context_destroy(&temp->context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment