diff options
author | Johan Hovold <johan+linaro@kernel.org> | 2023-01-19 17:42:55 +0100 |
---|---|---|
committer | Ard Biesheuvel <ardb@kernel.org> | 2023-01-26 21:32:01 +0100 |
commit | 0217a40d7ba6e71d7f3422fbe89b436e8ee7ece7 (patch) | |
tree | 26e476b53d71dddd017a86f432b94e0b4a0099f1 | |
parent | bad267f9e18f8e9e628abd1811d2899b1735a4e1 (diff) | |
download | linux-0217a40d7ba6e71d7f3422fbe89b436e8ee7ece7.tar.gz linux-0217a40d7ba6e71d7f3422fbe89b436e8ee7ece7.tar.bz2 linux-0217a40d7ba6e71d7f3422fbe89b436e8ee7ece7.zip |
efi: efivars: prevent double registration
Add the missing sanity check to efivars_register() so that it is no
longer possible to override an already registered set of efivar ops
(without first deregistering them).
This can help debug initialisation ordering issues where drivers have so
far unknowingly been relying on overriding the generic ops.
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
-rw-r--r-- | drivers/firmware/efi/vars.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c index f34e7741e0c3..bd75b87f5fc1 100644 --- a/drivers/firmware/efi/vars.c +++ b/drivers/firmware/efi/vars.c @@ -62,18 +62,27 @@ EXPORT_SYMBOL_GPL(efivar_is_available); int efivars_register(struct efivars *efivars, const struct efivar_operations *ops) { + int rv; + if (down_interruptible(&efivars_lock)) return -EINTR; + if (__efivars) { + pr_warn("efivars already registered\n"); + rv = -EBUSY; + goto out; + } + efivars->ops = ops; __efivars = efivars; pr_info("Registered efivars operations\n"); - + rv = 0; +out: up(&efivars_lock); - return 0; + return rv; } EXPORT_SYMBOL_GPL(efivars_register); |