diff mbox series

selinux: replace kmem_cache_create() with KMEM_CACHE()

Message ID 20240827174003.52690-1-ericsu@linux.microsoft.com (mailing list archive)
State Accepted
Delegated to: Paul Moore
Headers show
Series selinux: replace kmem_cache_create() with KMEM_CACHE() | expand

Commit Message

ericsu@linux.microsoft.com Aug. 27, 2024, 5:40 p.m. UTC
From: Eric Suen <ericsu@linux.microsoft.com>

Based on guidance in include/linux/slab.h, replace kmem_cache_create()
with KMEM_CACHE() for sources under security/selinux, to simply creation
of SLAB caches.

Signed-off-by: Eric Suen <ericsu@linux.microsoft.com>
---
 security/selinux/avc.c        | 16 ++++------------
 security/selinux/ss/avtab.c   |  7 ++-----
 security/selinux/ss/ebitmap.c |  4 +---
 security/selinux/ss/hashtab.c |  4 +---
 4 files changed, 8 insertions(+), 23 deletions(-)

Comments

Paul Moore Aug. 27, 2024, 10:42 p.m. UTC | #1
On Aug 27, 2024 ericsu@linux.microsoft.com wrote:
> 
> Based on guidance in include/linux/slab.h, replace kmem_cache_create()
> with KMEM_CACHE() for sources under security/selinux, to simply creation
> of SLAB caches.
> 
> Signed-off-by: Eric Suen <ericsu@linux.microsoft.com>
> ---
>  security/selinux/avc.c        | 16 ++++------------
>  security/selinux/ss/avtab.c   |  7 ++-----
>  security/selinux/ss/ebitmap.c |  4 +---
>  security/selinux/ss/hashtab.c |  4 +---
>  4 files changed, 8 insertions(+), 23 deletions(-)

Looks good to me, merged into selinux/dev, thanks Eric!

--
paul-moore.com
diff mbox series

Patch

diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 32eb67fb3e42..1ec377ce6d22 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -134,18 +134,10 @@  static inline u32 avc_hash(u32 ssid, u32 tsid, u16 tclass)
  */
 void __init avc_init(void)
 {
-	avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
-					0, SLAB_PANIC, NULL);
-	avc_xperms_cachep = kmem_cache_create("avc_xperms_node",
-					sizeof(struct avc_xperms_node),
-					0, SLAB_PANIC, NULL);
-	avc_xperms_decision_cachep = kmem_cache_create(
-					"avc_xperms_decision_node",
-					sizeof(struct avc_xperms_decision_node),
-					0, SLAB_PANIC, NULL);
-	avc_xperms_data_cachep = kmem_cache_create("avc_xperms_data",
-					sizeof(struct extended_perms_data),
-					0, SLAB_PANIC, NULL);
+	avc_node_cachep = KMEM_CACHE(avc_node, SLAB_PANIC);
+	avc_xperms_cachep = KMEM_CACHE(avc_xperms_node, SLAB_PANIC);
+	avc_xperms_decision_cachep = KMEM_CACHE(avc_xperms_decision_node, SLAB_PANIC);
+	avc_xperms_data_cachep = KMEM_CACHE(extended_perms_data, SLAB_PANIC);
 }
 
 int avc_get_hash_stats(char *page)
diff --git a/security/selinux/ss/avtab.c b/security/selinux/ss/avtab.c
index 2ad98732d052..8e400dd736b7 100644
--- a/security/selinux/ss/avtab.c
+++ b/security/selinux/ss/avtab.c
@@ -604,9 +604,6 @@  int avtab_write(struct policydb *p, struct avtab *a, void *fp)
 
 void __init avtab_cache_init(void)
 {
-	avtab_node_cachep = kmem_cache_create(
-		"avtab_node", sizeof(struct avtab_node), 0, SLAB_PANIC, NULL);
-	avtab_xperms_cachep = kmem_cache_create(
-		"avtab_extended_perms", sizeof(struct avtab_extended_perms), 0,
-		SLAB_PANIC, NULL);
+	avtab_node_cachep = KMEM_CACHE(avtab_node, SLAB_PANIC);
+	avtab_xperms_cachep = KMEM_CACHE(avtab_extended_perms, SLAB_PANIC);
 }
diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c
index 04d7f4907a06..99c01be15115 100644
--- a/security/selinux/ss/ebitmap.c
+++ b/security/selinux/ss/ebitmap.c
@@ -572,7 +572,5 @@  u32 ebitmap_hash(const struct ebitmap *e, u32 hash)
 
 void __init ebitmap_cache_init(void)
 {
-	ebitmap_node_cachep = kmem_cache_create("ebitmap_node",
-						sizeof(struct ebitmap_node), 0,
-						SLAB_PANIC, NULL);
+	ebitmap_node_cachep = KMEM_CACHE(ebitmap_node, SLAB_PANIC);
 }
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
index 32c4cb37f3d2..383fd2d70878 100644
--- a/security/selinux/ss/hashtab.c
+++ b/security/selinux/ss/hashtab.c
@@ -194,7 +194,5 @@  int hashtab_duplicate(struct hashtab *new, const struct hashtab *orig,
 
 void __init hashtab_cache_init(void)
 {
-	hashtab_node_cachep = kmem_cache_create("hashtab_node",
-						sizeof(struct hashtab_node), 0,
-						SLAB_PANIC, NULL);
+	hashtab_node_cachep = KMEM_CACHE(hashtab_node, SLAB_PANIC);
 }