24
24
25
25
#define BITS_PER_U64 (sizeof(u64) * 8)
26
26
27
+ static struct kmem_cache * ebitmap_node_cachep ;
28
+
27
29
int ebitmap_cmp (struct ebitmap * e1 , struct ebitmap * e2 )
28
30
{
29
31
struct ebitmap_node * n1 , * n2 ;
@@ -54,7 +56,7 @@ int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src)
54
56
n = src -> node ;
55
57
prev = NULL ;
56
58
while (n ) {
57
- new = kzalloc ( sizeof ( * new ) , GFP_ATOMIC );
59
+ new = kmem_cache_zalloc ( ebitmap_node_cachep , GFP_ATOMIC );
58
60
if (!new ) {
59
61
ebitmap_destroy (dst );
60
62
return - ENOMEM ;
@@ -162,7 +164,7 @@ int ebitmap_netlbl_import(struct ebitmap *ebmap,
162
164
if (e_iter == NULL ||
163
165
offset >= e_iter -> startbit + EBITMAP_SIZE ) {
164
166
e_prev = e_iter ;
165
- e_iter = kzalloc ( sizeof ( * e_iter ) , GFP_ATOMIC );
167
+ e_iter = kmem_cache_zalloc ( ebitmap_node_cachep , GFP_ATOMIC );
166
168
if (e_iter == NULL )
167
169
goto netlbl_import_failure ;
168
170
e_iter -> startbit = offset - (offset % EBITMAP_SIZE );
@@ -288,7 +290,7 @@ int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value)
288
290
prev -> next = n -> next ;
289
291
else
290
292
e -> node = n -> next ;
291
- kfree ( n );
293
+ kmem_cache_free ( ebitmap_node_cachep , n );
292
294
}
293
295
return 0 ;
294
296
}
@@ -299,7 +301,7 @@ int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value)
299
301
if (!value )
300
302
return 0 ;
301
303
302
- new = kzalloc ( sizeof ( * new ) , GFP_ATOMIC );
304
+ new = kmem_cache_zalloc ( ebitmap_node_cachep , GFP_ATOMIC );
303
305
if (!new )
304
306
return - ENOMEM ;
305
307
@@ -332,7 +334,7 @@ void ebitmap_destroy(struct ebitmap *e)
332
334
while (n ) {
333
335
temp = n ;
334
336
n = n -> next ;
335
- kfree ( temp );
337
+ kmem_cache_free ( ebitmap_node_cachep , temp );
336
338
}
337
339
338
340
e -> highbit = 0 ;
@@ -400,7 +402,7 @@ int ebitmap_read(struct ebitmap *e, void *fp)
400
402
401
403
if (!n || startbit >= n -> startbit + EBITMAP_SIZE ) {
402
404
struct ebitmap_node * tmp ;
403
- tmp = kzalloc ( sizeof ( * tmp ) , GFP_KERNEL );
405
+ tmp = kmem_cache_zalloc ( ebitmap_node_cachep , GFP_KERNEL );
404
406
if (!tmp ) {
405
407
printk (KERN_ERR
406
408
"SELinux: ebitmap: out of memory\n" );
@@ -519,3 +521,15 @@ int ebitmap_write(struct ebitmap *e, void *fp)
519
521
}
520
522
return 0 ;
521
523
}
524
+
525
+ void ebitmap_cache_init (void )
526
+ {
527
+ ebitmap_node_cachep = kmem_cache_create ("ebitmap_node" ,
528
+ sizeof (struct ebitmap_node ),
529
+ 0 , SLAB_PANIC , NULL );
530
+ }
531
+
532
+ void ebitmap_cache_destroy (void )
533
+ {
534
+ kmem_cache_destroy (ebitmap_node_cachep );
535
+ }
0 commit comments