1
- // SPDX-License-Identifier: GPL-2.0
1
+ /* SPDX-License-Identifier: GPL-2.0 */
2
2
/*
3
3
* Implementation of the extensible bitmap type.
4
4
*
5
5
* Author : Stephen Smalley, <[email protected] >
6
6
*/
7
7
/*
8
8
* Updated: Hewlett-Packard <[email protected] >
9
+ * Added support to import/export the NetLabel category bitmap
10
+ * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
9
11
*
10
- * Added support to import/export the NetLabel category bitmap
11
- *
12
- * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
13
- */
14
- /*
15
12
* Updated: KaiGai Kohei <[email protected] >
16
- * Applied standard bit operations to improve bitmap scanning.
13
+ * Applied standard bit operations to improve bitmap scanning.
17
14
*/
18
15
19
16
#include <linux/kernel.h>
24
21
#include "ebitmap.h"
25
22
#include "policydb.h"
26
23
27
- #define BITS_PER_U64 (sizeof(u64) * 8)
24
+ #define BITS_PER_U64 (sizeof(u64) * 8)
28
25
29
26
static struct kmem_cache * ebitmap_node_cachep __ro_after_init ;
30
27
@@ -37,8 +34,7 @@ int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
37
34
38
35
n1 = e1 -> node ;
39
36
n2 = e2 -> node ;
40
- while (n1 && n2 &&
41
- (n1 -> startbit == n2 -> startbit ) &&
37
+ while (n1 && n2 && (n1 -> startbit == n2 -> startbit ) &&
42
38
!memcmp (n1 -> maps , n2 -> maps , EBITMAP_SIZE / 8 )) {
43
39
n1 = n1 -> next ;
44
40
n2 = n2 -> next ;
@@ -79,14 +75,16 @@ int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src)
79
75
return 0 ;
80
76
}
81
77
82
- int ebitmap_and (struct ebitmap * dst , const struct ebitmap * e1 , const struct ebitmap * e2 )
78
+ int ebitmap_and (struct ebitmap * dst , const struct ebitmap * e1 ,
79
+ const struct ebitmap * e2 )
83
80
{
84
81
struct ebitmap_node * n ;
85
82
int bit , rc ;
86
83
87
84
ebitmap_init (dst );
88
85
89
- ebitmap_for_each_positive_bit (e1 , n , bit ) {
86
+ ebitmap_for_each_positive_bit (e1 , n , bit )
87
+ {
90
88
if (ebitmap_get_bit (e2 , bit )) {
91
89
rc = ebitmap_set_bit (dst , bit , 1 );
92
90
if (rc < 0 )
@@ -96,7 +94,6 @@ int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1, const struct ebit
96
94
return 0 ;
97
95
}
98
96
99
-
100
97
#ifdef CONFIG_NETLABEL
101
98
/**
102
99
* ebitmap_netlbl_export - Export an ebitmap into a NetLabel category bitmap
@@ -131,10 +128,8 @@ int ebitmap_netlbl_export(struct ebitmap *ebmap,
131
128
for (iter = 0 ; iter < EBITMAP_UNIT_NUMS ; iter ++ ) {
132
129
e_map = e_iter -> maps [iter ];
133
130
if (e_map != 0 ) {
134
- rc = netlbl_catmap_setlong (catmap ,
135
- offset ,
136
- e_map ,
137
- GFP_ATOMIC );
131
+ rc = netlbl_catmap_setlong (catmap , offset ,
132
+ e_map , GFP_ATOMIC );
138
133
if (rc != 0 )
139
134
goto netlbl_export_failure ;
140
135
}
@@ -185,7 +180,8 @@ int ebitmap_netlbl_import(struct ebitmap *ebmap,
185
180
if (e_iter == NULL ||
186
181
offset >= e_iter -> startbit + EBITMAP_SIZE ) {
187
182
e_prev = e_iter ;
188
- e_iter = kmem_cache_zalloc (ebitmap_node_cachep , GFP_ATOMIC );
183
+ e_iter = kmem_cache_zalloc (ebitmap_node_cachep ,
184
+ GFP_ATOMIC );
189
185
if (e_iter == NULL )
190
186
goto netlbl_import_failure ;
191
187
e_iter -> startbit = offset - (offset % EBITMAP_SIZE );
@@ -218,7 +214,8 @@ int ebitmap_netlbl_import(struct ebitmap *ebmap,
218
214
* if last_e2bit is non-zero, the highest set bit in e2 cannot exceed
219
215
* last_e2bit.
220
216
*/
221
- int ebitmap_contains (const struct ebitmap * e1 , const struct ebitmap * e2 , u32 last_e2bit )
217
+ int ebitmap_contains (const struct ebitmap * e1 , const struct ebitmap * e2 ,
218
+ u32 last_e2bit )
222
219
{
223
220
const struct ebitmap_node * n1 , * n2 ;
224
221
int i ;
@@ -234,8 +231,8 @@ int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2, u32 las
234
231
n1 = n1 -> next ;
235
232
continue ;
236
233
}
237
- for (i = EBITMAP_UNIT_NUMS - 1 ; (i >= 0 ) && !n2 -> maps [i ]; )
238
- i -- ; /* Skip trailing NULL map entries */
234
+ for (i = EBITMAP_UNIT_NUMS - 1 ; (i >= 0 ) && !n2 -> maps [i ];)
235
+ i -- ; /* Skip trailing NULL map entries */
239
236
if (last_e2bit && (i >= 0 )) {
240
237
u32 lastsetbit = n2 -> startbit + i * EBITMAP_UNIT_SIZE +
241
238
__fls (n2 -> maps [i ]);
@@ -302,8 +299,8 @@ int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value)
302
299
* within the bitmap
303
300
*/
304
301
if (prev )
305
- e -> highbit = prev -> startbit
306
- + EBITMAP_SIZE ;
302
+ e -> highbit = prev -> startbit +
303
+ EBITMAP_SIZE ;
307
304
else
308
305
e -> highbit = 0 ;
309
306
}
@@ -424,7 +421,8 @@ int ebitmap_read(struct ebitmap *e, void *fp)
424
421
425
422
if (!n || startbit >= n -> startbit + EBITMAP_SIZE ) {
426
423
struct ebitmap_node * tmp ;
427
- tmp = kmem_cache_zalloc (ebitmap_node_cachep , GFP_KERNEL );
424
+ tmp = kmem_cache_zalloc (ebitmap_node_cachep ,
425
+ GFP_KERNEL );
428
426
if (!tmp ) {
429
427
pr_err ("SELinux: ebitmap: out of memory\n" );
430
428
rc = - ENOMEM ;
@@ -481,7 +479,8 @@ int ebitmap_write(const struct ebitmap *e, void *fp)
481
479
count = 0 ;
482
480
last_bit = 0 ;
483
481
last_startbit = -1 ;
484
- ebitmap_for_each_positive_bit (e , n , bit ) {
482
+ ebitmap_for_each_positive_bit (e , n , bit )
483
+ {
485
484
if (rounddown (bit , (int )BITS_PER_U64 ) > last_startbit ) {
486
485
count ++ ;
487
486
last_startbit = rounddown (bit , BITS_PER_U64 );
@@ -497,7 +496,8 @@ int ebitmap_write(const struct ebitmap *e, void *fp)
497
496
498
497
map = 0 ;
499
498
last_startbit = INT_MIN ;
500
- ebitmap_for_each_positive_bit (e , n , bit ) {
499
+ ebitmap_for_each_positive_bit (e , n , bit )
500
+ {
501
501
if (rounddown (bit , (int )BITS_PER_U64 ) > last_startbit ) {
502
502
__le64 buf64 [1 ];
503
503
@@ -559,6 +559,6 @@ u32 ebitmap_hash(const struct ebitmap *e, u32 hash)
559
559
void __init ebitmap_cache_init (void )
560
560
{
561
561
ebitmap_node_cachep = kmem_cache_create ("ebitmap_node" ,
562
- sizeof (struct ebitmap_node ),
563
- 0 , SLAB_PANIC , NULL );
562
+ sizeof (struct ebitmap_node ), 0 ,
563
+ SLAB_PANIC , NULL );
564
564
}
0 commit comments