diff mbox series

[1/4] selinux: simplify avtab_insert_node() prototype

Message ID 20230929195617.65120-2-jsatterfield.linux@gmail.com (mailing list archive)
State Accepted
Delegated to: Paul Moore
Headers show
Series selinux: avtab arrays and refactors | expand

Commit Message

Jacob Satterfield Sept. 29, 2023, 7:56 p.m. UTC
__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>
---
 security/selinux/ss/avtab.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

Comments

Stephen Smalley Oct. 2, 2023, 4:05 p.m. UTC | #1
On Fri, Sep 29, 2023 at 3:56 PM Jacob Satterfield
<jsatterfield.linux@gmail.com> wrote:
>
> __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>
Paul Moore Oct. 3, 2023, 9:07 p.m. UTC | #2
On Sep 29, 2023 Stephen Smalley <stephen.smalley.work@gmail.com> wrote:
> 
> __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>
> ---
>  security/selinux/ss/avtab.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)

Merged into selinux/next, thanks!

--
paul-moore.com
diff mbox series

Patch

diff --git a/security/selinux/ss/avtab.c b/security/selinux/ss/avtab.c
index 095b8cd24806..8751a602ead2 100644
--- a/security/selinux/ss/avtab.c
+++ b/security/selinux/ss/avtab.c
@@ -67,8 +67,7 @@  static inline u32 avtab_hash(const struct avtab_key *keyp, u32 mask)
 }
 
 static struct avtab_node*
-avtab_insert_node(struct avtab *h, u32 hvalue,
-		  struct avtab_node *prev,
+avtab_insert_node(struct avtab *h, struct avtab_node **dst,
 		  const struct avtab_key *key, const struct avtab_datum *datum)
 {
 	struct avtab_node *newnode;
@@ -90,15 +89,8 @@  avtab_insert_node(struct avtab *h, u32 hvalue,
 		newnode->datum.u.data = datum->u.data;
 	}
 
-	if (prev) {
-		newnode->next = prev->next;
-		prev->next = newnode;
-	} else {
-		struct avtab_node **n = &h->htable[hvalue];
-
-		newnode->next = *n;
-		*n = newnode;
-	}
+	newnode->next = *dst;
+	*dst = newnode;
 
 	h->nel++;
 	return newnode;
@@ -138,7 +130,8 @@  static int avtab_insert(struct avtab *h, const struct avtab_key *key,
 			break;
 	}
 
-	newnode = avtab_insert_node(h, hvalue, prev, key, datum);
+	newnode = avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
+				    key, datum);
 	if (!newnode)
 		return -ENOMEM;
 
@@ -178,7 +171,8 @@  struct avtab_node *avtab_insert_nonunique(struct avtab *h,
 		    key->target_class < cur->key.target_class)
 			break;
 	}
-	return avtab_insert_node(h, hvalue, prev, key, datum);
+	return avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
+				 key, datum);
 }
 
 /* This search function returns a node pointer, and can be used in