Skip to content

Commit 19c1c99

Browse files
jsatterfield-linuxpcmoore
authored andcommitted
selinux: simplify avtab_insert_node() prototype
__hashtab_insert() in hashtab.h has a cleaner interface that allows the caller to specify the chain node location that the new node is being inserted into so that it can update the node that currently occupies it. Signed-off-by: Jacob Satterfield <jsatterfield.linux@gmail.com> Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 9d14088 commit 19c1c99

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

security/selinux/ss/avtab.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ static inline u32 avtab_hash(const struct avtab_key *keyp, u32 mask)
6767
}
6868

6969
static struct avtab_node*
70-
avtab_insert_node(struct avtab *h, u32 hvalue,
71-
struct avtab_node *prev,
70+
avtab_insert_node(struct avtab *h, struct avtab_node **dst,
7271
const struct avtab_key *key, const struct avtab_datum *datum)
7372
{
7473
struct avtab_node *newnode;
@@ -90,15 +89,8 @@ avtab_insert_node(struct avtab *h, u32 hvalue,
9089
newnode->datum.u.data = datum->u.data;
9190
}
9291

93-
if (prev) {
94-
newnode->next = prev->next;
95-
prev->next = newnode;
96-
} else {
97-
struct avtab_node **n = &h->htable[hvalue];
98-
99-
newnode->next = *n;
100-
*n = newnode;
101-
}
92+
newnode->next = *dst;
93+
*dst = newnode;
10294

10395
h->nel++;
10496
return newnode;
@@ -138,7 +130,8 @@ static int avtab_insert(struct avtab *h, const struct avtab_key *key,
138130
break;
139131
}
140132

141-
newnode = avtab_insert_node(h, hvalue, prev, key, datum);
133+
newnode = avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
134+
key, datum);
142135
if (!newnode)
143136
return -ENOMEM;
144137

@@ -178,7 +171,8 @@ struct avtab_node *avtab_insert_nonunique(struct avtab *h,
178171
key->target_class < cur->key.target_class)
179172
break;
180173
}
181-
return avtab_insert_node(h, hvalue, prev, key, datum);
174+
return avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
175+
key, datum);
182176
}
183177

184178
/* This search function returns a node pointer, and can be used in

0 commit comments

Comments
 (0)