Skip to content

Commit 0217a40

Browse files
jhovoldardbiesheuvel
authored andcommitted
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 <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent bad267f commit 0217a40

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/firmware/efi/vars.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,27 @@ EXPORT_SYMBOL_GPL(efivar_is_available);
6262
int efivars_register(struct efivars *efivars,
6363
const struct efivar_operations *ops)
6464
{
65+
int rv;
66+
6567
if (down_interruptible(&efivars_lock))
6668
return -EINTR;
6769

70+
if (__efivars) {
71+
pr_warn("efivars already registered\n");
72+
rv = -EBUSY;
73+
goto out;
74+
}
75+
6876
efivars->ops = ops;
6977

7078
__efivars = efivars;
7179

7280
pr_info("Registered efivars operations\n");
73-
81+
rv = 0;
82+
out:
7483
up(&efivars_lock);
7584

76-
return 0;
85+
return rv;
7786
}
7887
EXPORT_SYMBOL_GPL(efivars_register);
7988

0 commit comments

Comments
 (0)