Skip to content

Commit 27be560

Browse files
committed
lsm: cleanup initialize_lsm() and rename to lsm_init_single()
Rename initialize_lsm() to be more consistent with the rest of the LSM initialization changes and rework the function itself to better fit with the "exit on fail" coding pattern. Reviewed-by: Kees Cook <kees@kernel.org> Reviewed-by: John Johansen <john.johansen@canonical.com> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 291271e commit 27be560

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

security/lsm_init.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static void __init lsm_order_append(struct lsm_info *lsm, const char *src)
169169
lsm_is_enabled(lsm) ? "enabled" : "disabled");
170170
}
171171

172+
172173
/**
173174
* lsm_blob_size_update - Update the LSM blob size and offset information
174175
* @sz_req: the requested additional blob size
@@ -225,16 +226,20 @@ static void __init lsm_prepare(struct lsm_info *lsm)
225226
lsm_blob_size_update(&blobs->lbs_bpf_token, &blob_sizes.lbs_bpf_token);
226227
}
227228

228-
/* Initialize a given LSM, if it is enabled. */
229-
static void __init initialize_lsm(struct lsm_info *lsm)
229+
/**
230+
* lsm_init_single - Initialize a given LSM
231+
* @lsm: LSM definition
232+
*/
233+
static void __init lsm_init_single(struct lsm_info *lsm)
230234
{
231-
if (lsm_is_enabled(lsm)) {
232-
int ret;
235+
int ret;
233236

234-
init_debug("initializing %s\n", lsm->id->name);
235-
ret = lsm->init();
236-
WARN(ret, "%s failed to initialize: %d\n", lsm->id->name, ret);
237-
}
237+
if (!lsm_is_enabled(lsm))
238+
return;
239+
240+
init_debug("initializing %s\n", lsm->id->name);
241+
ret = lsm->init();
242+
WARN(ret, "%s failed to initialize: %d\n", lsm->id->name, ret);
238243
}
239244

240245
/**
@@ -379,7 +384,7 @@ static void __init lsm_init_ordered(void)
379384
panic("%s: early task alloc failed.\n", __func__);
380385

381386
lsm_order_for_each(lsm) {
382-
initialize_lsm(*lsm);
387+
lsm_init_single(*lsm);
383388
}
384389
}
385390

@@ -429,7 +434,7 @@ int __init early_security_init(void)
429434
lsm_enabled_set(lsm, true);
430435
lsm_order_append(lsm, "early");
431436
lsm_prepare(lsm);
432-
initialize_lsm(lsm);
437+
lsm_init_single(lsm);
433438
}
434439

435440
return 0;

0 commit comments

Comments
 (0)