Skip to content

Commit 0eb2f29

Browse files
committed
selinux: shuffle around policydb.c to get rid of forward declarations
No code changes, but move a lot of the policydb destructors higher up so we can get rid of a forward declaration. This patch does expose a few old checkpatch.pl errors, but those will be dealt with in a separate (set of) patches. Signed-off-by: Paul Moore <[email protected]>
1 parent 4538523 commit 0eb2f29

File tree

1 file changed

+187
-189
lines changed

1 file changed

+187
-189
lines changed

security/selinux/ss/policydb.c

Lines changed: 187 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,193 @@ static struct policydb_compat_info *policydb_lookup_compat(int version)
178178
return info;
179179
}
180180

181+
/*
182+
* The following *_destroy functions are used to
183+
* free any memory allocated for each kind of
184+
* symbol data in the policy database.
185+
*/
186+
187+
static int perm_destroy(void *key, void *datum, void *p)
188+
{
189+
kfree(key);
190+
kfree(datum);
191+
return 0;
192+
}
193+
194+
static int common_destroy(void *key, void *datum, void *p)
195+
{
196+
struct common_datum *comdatum;
197+
198+
kfree(key);
199+
if (datum) {
200+
comdatum = datum;
201+
hashtab_map(comdatum->permissions.table, perm_destroy, NULL);
202+
hashtab_destroy(comdatum->permissions.table);
203+
}
204+
kfree(datum);
205+
return 0;
206+
}
207+
208+
static void constraint_expr_destroy(struct constraint_expr *expr)
209+
{
210+
if (expr) {
211+
ebitmap_destroy(&expr->names);
212+
if (expr->type_names) {
213+
ebitmap_destroy(&expr->type_names->types);
214+
ebitmap_destroy(&expr->type_names->negset);
215+
kfree(expr->type_names);
216+
}
217+
kfree(expr);
218+
}
219+
}
220+
221+
static int cls_destroy(void *key, void *datum, void *p)
222+
{
223+
struct class_datum *cladatum;
224+
struct constraint_node *constraint, *ctemp;
225+
struct constraint_expr *e, *etmp;
226+
227+
kfree(key);
228+
if (datum) {
229+
cladatum = datum;
230+
hashtab_map(cladatum->permissions.table, perm_destroy, NULL);
231+
hashtab_destroy(cladatum->permissions.table);
232+
constraint = cladatum->constraints;
233+
while (constraint) {
234+
e = constraint->expr;
235+
while (e) {
236+
etmp = e;
237+
e = e->next;
238+
constraint_expr_destroy(etmp);
239+
}
240+
ctemp = constraint;
241+
constraint = constraint->next;
242+
kfree(ctemp);
243+
}
244+
245+
constraint = cladatum->validatetrans;
246+
while (constraint) {
247+
e = constraint->expr;
248+
while (e) {
249+
etmp = e;
250+
e = e->next;
251+
constraint_expr_destroy(etmp);
252+
}
253+
ctemp = constraint;
254+
constraint = constraint->next;
255+
kfree(ctemp);
256+
}
257+
kfree(cladatum->comkey);
258+
}
259+
kfree(datum);
260+
return 0;
261+
}
262+
263+
static int role_destroy(void *key, void *datum, void *p)
264+
{
265+
struct role_datum *role;
266+
267+
kfree(key);
268+
if (datum) {
269+
role = datum;
270+
ebitmap_destroy(&role->dominates);
271+
ebitmap_destroy(&role->types);
272+
}
273+
kfree(datum);
274+
return 0;
275+
}
276+
277+
static int type_destroy(void *key, void *datum, void *p)
278+
{
279+
kfree(key);
280+
kfree(datum);
281+
return 0;
282+
}
283+
284+
static int user_destroy(void *key, void *datum, void *p)
285+
{
286+
struct user_datum *usrdatum;
287+
288+
kfree(key);
289+
if (datum) {
290+
usrdatum = datum;
291+
ebitmap_destroy(&usrdatum->roles);
292+
ebitmap_destroy(&usrdatum->range.level[0].cat);
293+
ebitmap_destroy(&usrdatum->range.level[1].cat);
294+
ebitmap_destroy(&usrdatum->dfltlevel.cat);
295+
}
296+
kfree(datum);
297+
return 0;
298+
}
299+
300+
static int sens_destroy(void *key, void *datum, void *p)
301+
{
302+
struct level_datum *levdatum;
303+
304+
kfree(key);
305+
if (datum) {
306+
levdatum = datum;
307+
if (levdatum->level)
308+
ebitmap_destroy(&levdatum->level->cat);
309+
kfree(levdatum->level);
310+
}
311+
kfree(datum);
312+
return 0;
313+
}
314+
315+
static int cat_destroy(void *key, void *datum, void *p)
316+
{
317+
kfree(key);
318+
kfree(datum);
319+
return 0;
320+
}
321+
322+
static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) =
323+
{
324+
common_destroy,
325+
cls_destroy,
326+
role_destroy,
327+
type_destroy,
328+
user_destroy,
329+
cond_destroy_bool,
330+
sens_destroy,
331+
cat_destroy,
332+
};
333+
334+
static int filenametr_destroy(void *key, void *datum, void *p)
335+
{
336+
struct filename_trans *ft = key;
337+
kfree(ft->name);
338+
kfree(key);
339+
kfree(datum);
340+
cond_resched();
341+
return 0;
342+
}
343+
344+
static int range_tr_destroy(void *key, void *datum, void *p)
345+
{
346+
struct mls_range *rt = datum;
347+
kfree(key);
348+
ebitmap_destroy(&rt->level[0].cat);
349+
ebitmap_destroy(&rt->level[1].cat);
350+
kfree(datum);
351+
cond_resched();
352+
return 0;
353+
}
354+
355+
static void ocontext_destroy(struct ocontext *c, int i)
356+
{
357+
if (!c)
358+
return;
359+
360+
context_destroy(&c->context[0]);
361+
context_destroy(&c->context[1]);
362+
if (i == OCON_ISID || i == OCON_FS ||
363+
i == OCON_NETIF || i == OCON_FSUSE)
364+
kfree(c->u.name);
365+
kfree(c);
366+
}
367+
181368
/*
182369
* Initialize the role table.
183370
*/
@@ -274,8 +461,6 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)
274461
return v;
275462
}
276463

277-
static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap);
278-
279464
/*
280465
* Initialize a policy database structure.
281466
*/
@@ -569,193 +754,6 @@ static int policydb_index(struct policydb *p)
569754
return rc;
570755
}
571756

572-
/*
573-
* The following *_destroy functions are used to
574-
* free any memory allocated for each kind of
575-
* symbol data in the policy database.
576-
*/
577-
578-
static int perm_destroy(void *key, void *datum, void *p)
579-
{
580-
kfree(key);
581-
kfree(datum);
582-
return 0;
583-
}
584-
585-
static int common_destroy(void *key, void *datum, void *p)
586-
{
587-
struct common_datum *comdatum;
588-
589-
kfree(key);
590-
if (datum) {
591-
comdatum = datum;
592-
hashtab_map(comdatum->permissions.table, perm_destroy, NULL);
593-
hashtab_destroy(comdatum->permissions.table);
594-
}
595-
kfree(datum);
596-
return 0;
597-
}
598-
599-
static void constraint_expr_destroy(struct constraint_expr *expr)
600-
{
601-
if (expr) {
602-
ebitmap_destroy(&expr->names);
603-
if (expr->type_names) {
604-
ebitmap_destroy(&expr->type_names->types);
605-
ebitmap_destroy(&expr->type_names->negset);
606-
kfree(expr->type_names);
607-
}
608-
kfree(expr);
609-
}
610-
}
611-
612-
static int cls_destroy(void *key, void *datum, void *p)
613-
{
614-
struct class_datum *cladatum;
615-
struct constraint_node *constraint, *ctemp;
616-
struct constraint_expr *e, *etmp;
617-
618-
kfree(key);
619-
if (datum) {
620-
cladatum = datum;
621-
hashtab_map(cladatum->permissions.table, perm_destroy, NULL);
622-
hashtab_destroy(cladatum->permissions.table);
623-
constraint = cladatum->constraints;
624-
while (constraint) {
625-
e = constraint->expr;
626-
while (e) {
627-
etmp = e;
628-
e = e->next;
629-
constraint_expr_destroy(etmp);
630-
}
631-
ctemp = constraint;
632-
constraint = constraint->next;
633-
kfree(ctemp);
634-
}
635-
636-
constraint = cladatum->validatetrans;
637-
while (constraint) {
638-
e = constraint->expr;
639-
while (e) {
640-
etmp = e;
641-
e = e->next;
642-
constraint_expr_destroy(etmp);
643-
}
644-
ctemp = constraint;
645-
constraint = constraint->next;
646-
kfree(ctemp);
647-
}
648-
kfree(cladatum->comkey);
649-
}
650-
kfree(datum);
651-
return 0;
652-
}
653-
654-
static int role_destroy(void *key, void *datum, void *p)
655-
{
656-
struct role_datum *role;
657-
658-
kfree(key);
659-
if (datum) {
660-
role = datum;
661-
ebitmap_destroy(&role->dominates);
662-
ebitmap_destroy(&role->types);
663-
}
664-
kfree(datum);
665-
return 0;
666-
}
667-
668-
static int type_destroy(void *key, void *datum, void *p)
669-
{
670-
kfree(key);
671-
kfree(datum);
672-
return 0;
673-
}
674-
675-
static int user_destroy(void *key, void *datum, void *p)
676-
{
677-
struct user_datum *usrdatum;
678-
679-
kfree(key);
680-
if (datum) {
681-
usrdatum = datum;
682-
ebitmap_destroy(&usrdatum->roles);
683-
ebitmap_destroy(&usrdatum->range.level[0].cat);
684-
ebitmap_destroy(&usrdatum->range.level[1].cat);
685-
ebitmap_destroy(&usrdatum->dfltlevel.cat);
686-
}
687-
kfree(datum);
688-
return 0;
689-
}
690-
691-
static int sens_destroy(void *key, void *datum, void *p)
692-
{
693-
struct level_datum *levdatum;
694-
695-
kfree(key);
696-
if (datum) {
697-
levdatum = datum;
698-
if (levdatum->level)
699-
ebitmap_destroy(&levdatum->level->cat);
700-
kfree(levdatum->level);
701-
}
702-
kfree(datum);
703-
return 0;
704-
}
705-
706-
static int cat_destroy(void *key, void *datum, void *p)
707-
{
708-
kfree(key);
709-
kfree(datum);
710-
return 0;
711-
}
712-
713-
static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) =
714-
{
715-
common_destroy,
716-
cls_destroy,
717-
role_destroy,
718-
type_destroy,
719-
user_destroy,
720-
cond_destroy_bool,
721-
sens_destroy,
722-
cat_destroy,
723-
};
724-
725-
static int filenametr_destroy(void *key, void *datum, void *p)
726-
{
727-
struct filename_trans *ft = key;
728-
kfree(ft->name);
729-
kfree(key);
730-
kfree(datum);
731-
cond_resched();
732-
return 0;
733-
}
734-
735-
static int range_tr_destroy(void *key, void *datum, void *p)
736-
{
737-
struct mls_range *rt = datum;
738-
kfree(key);
739-
ebitmap_destroy(&rt->level[0].cat);
740-
ebitmap_destroy(&rt->level[1].cat);
741-
kfree(datum);
742-
cond_resched();
743-
return 0;
744-
}
745-
746-
static void ocontext_destroy(struct ocontext *c, int i)
747-
{
748-
if (!c)
749-
return;
750-
751-
context_destroy(&c->context[0]);
752-
context_destroy(&c->context[1]);
753-
if (i == OCON_ISID || i == OCON_FS ||
754-
i == OCON_NETIF || i == OCON_FSUSE)
755-
kfree(c->u.name);
756-
kfree(c);
757-
}
758-
759757
/*
760758
* Free any memory allocated by a policy database structure.
761759
*/

0 commit comments

Comments
 (0)