fscrypt: Simplify handling of errors during initcall

Since CONFIG_FS_ENCRYPTION is a bool, not a tristate, fs/crypto/ can
only be builtin or absent entirely; it can't be a loadable module.
Therefore, the error code that gets returned from the fscrypt_init()
initcall is never used.  If any part of the initcall does fail, which
should never happen, the kernel will be left in a bad state.

Following the usual convention for builtin code, just panic the kernel
if any of part of the initcall fails.  This simplifies the code.

This closely mirrors commit e77000ccc5 ("fsverity: simplify handling
of errors during initcall").

Link: https://patch.msgid.link/20260619000030.166851-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
Eric Biggers 2026-06-18 17:00:30 -07:00
parent fa1517bc99
commit 928a1e6ba3
3 changed files with 13 additions and 34 deletions

View File

@ -369,15 +369,8 @@ void fscrypt_msg(const struct inode *inode, const char *level,
va_end(args);
}
/**
* fscrypt_init() - Set up for fs encryption.
*
* Return: 0 on success; -errno on failure
*/
static int __init fscrypt_init(void)
{
int err = -ENOMEM;
/*
* Use an unbound workqueue to allow bios to be decrypted in parallel
* even when they happen to complete on the same CPU. This sacrifices
@ -390,24 +383,12 @@ static int __init fscrypt_init(void)
WQ_UNBOUND | WQ_HIGHPRI,
num_online_cpus());
if (!fscrypt_read_workqueue)
goto fail;
panic("failed to allocate fscrypt_read_queue");
fscrypt_inode_info_cachep = KMEM_CACHE(fscrypt_inode_info,
SLAB_RECLAIM_ACCOUNT);
if (!fscrypt_inode_info_cachep)
goto fail_free_queue;
err = fscrypt_init_keyring();
if (err)
goto fail_free_inode_info;
SLAB_RECLAIM_ACCOUNT |
SLAB_PANIC);
fscrypt_init_keyring();
return 0;
fail_free_inode_info:
kmem_cache_destroy(fscrypt_inode_info_cachep);
fail_free_queue:
destroy_workqueue(fscrypt_read_workqueue);
fail:
return err;
}
late_initcall(fscrypt_init)

View File

@ -715,7 +715,7 @@ int fscrypt_add_test_dummy_key(struct super_block *sb,
int fscrypt_verify_key_added(struct super_block *sb,
const u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]);
int __init fscrypt_init_keyring(void);
void __init fscrypt_init_keyring(void);
/* keysetup.c */

View File

@ -1220,21 +1220,19 @@ int fscrypt_ioctl_get_key_status(struct file *filp, void __user *uarg)
}
EXPORT_SYMBOL_GPL(fscrypt_ioctl_get_key_status);
int __init fscrypt_init_keyring(void)
void __init fscrypt_init_keyring(void)
{
int err;
/*
* Note that register_key_type() fails only if a key type with the same
* name already exists, which should never happen here.
*/
err = register_key_type(&key_type_fscrypt_user);
if (err)
return err;
panic("failed to register .fscrypt key type (%d)", err);
err = register_key_type(&key_type_fscrypt_provisioning);
if (err)
goto err_unregister_fscrypt_user;
return 0;
err_unregister_fscrypt_user:
unregister_key_type(&key_type_fscrypt_user);
return err;
panic("failed to register fscrypt-provisioning key type (%d)",
err);
}