Commit bbc6d2c6 authored by Ard Biesheuvel's avatar Ard Biesheuvel

efi: vars: Switch to new wrapper layer

Switch the caching linked-list efivars layer implementation to the newly
introduced efivar get/set variable wrappers, instead of accessing the
lock and the ops pointer directly. This will permit us to move this code
out of the public efivars API, and into efivarfs once the obsolete sysfs
access method is finally removed.
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
parent 0f5b2c69
...@@ -408,28 +408,21 @@ static void dup_variable_bug(efi_char16_t *str16, efi_guid_t *vendor_guid, ...@@ -408,28 +408,21 @@ static void dup_variable_bug(efi_char16_t *str16, efi_guid_t *vendor_guid,
int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *), int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
void *data, bool duplicates, struct list_head *head) void *data, bool duplicates, struct list_head *head)
{ {
const struct efivar_operations *ops;
unsigned long variable_name_size = 1024; unsigned long variable_name_size = 1024;
efi_char16_t *variable_name; efi_char16_t *variable_name;
efi_status_t status; efi_status_t status;
efi_guid_t vendor_guid; efi_guid_t vendor_guid;
int err = 0; int err = 0;
if (!__efivars)
return -EFAULT;
ops = __efivars->ops;
variable_name = kzalloc(variable_name_size, GFP_KERNEL); variable_name = kzalloc(variable_name_size, GFP_KERNEL);
if (!variable_name) { if (!variable_name) {
printk(KERN_ERR "efivars: Memory allocation failed.\n"); printk(KERN_ERR "efivars: Memory allocation failed.\n");
return -ENOMEM; return -ENOMEM;
} }
if (down_interruptible(&efivars_lock)) { err = efivar_lock();
err = -EINTR; if (err)
goto free; goto free;
}
/* /*
* Per EFI spec, the maximum storage allocated for both * Per EFI spec, the maximum storage allocated for both
...@@ -439,9 +432,9 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *), ...@@ -439,9 +432,9 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
do { do {
variable_name_size = 1024; variable_name_size = 1024;
status = ops->get_next_variable(&variable_name_size, status = efivar_get_next_variable(&variable_name_size,
variable_name, variable_name,
&vendor_guid); &vendor_guid);
switch (status) { switch (status) {
case EFI_SUCCESS: case EFI_SUCCESS:
variable_name_size = var_name_strnsize(variable_name, variable_name_size = var_name_strnsize(variable_name,
...@@ -483,7 +476,7 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *), ...@@ -483,7 +476,7 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
} while (status != EFI_NOT_FOUND); } while (status != EFI_NOT_FOUND);
up(&efivars_lock); efivar_unlock();
free: free:
kfree(variable_name); kfree(variable_name);
...@@ -500,10 +493,13 @@ EXPORT_SYMBOL_GPL(efivar_init); ...@@ -500,10 +493,13 @@ EXPORT_SYMBOL_GPL(efivar_init);
*/ */
int efivar_entry_add(struct efivar_entry *entry, struct list_head *head) int efivar_entry_add(struct efivar_entry *entry, struct list_head *head)
{ {
if (down_interruptible(&efivars_lock)) int err;
return -EINTR;
err = efivar_lock();
if (err)
return err;
list_add(&entry->list, head); list_add(&entry->list, head);
up(&efivars_lock); efivar_unlock();
return 0; return 0;
} }
...@@ -544,7 +540,7 @@ EXPORT_SYMBOL_GPL(efivar_entry_remove); ...@@ -544,7 +540,7 @@ EXPORT_SYMBOL_GPL(efivar_entry_remove);
static void efivar_entry_list_del_unlock(struct efivar_entry *entry) static void efivar_entry_list_del_unlock(struct efivar_entry *entry)
{ {
list_del(&entry->list); list_del(&entry->list);
up(&efivars_lock); efivar_unlock();
} }
/** /**
...@@ -560,22 +556,18 @@ static void efivar_entry_list_del_unlock(struct efivar_entry *entry) ...@@ -560,22 +556,18 @@ static void efivar_entry_list_del_unlock(struct efivar_entry *entry)
*/ */
int efivar_entry_delete(struct efivar_entry *entry) int efivar_entry_delete(struct efivar_entry *entry)
{ {
const struct efivar_operations *ops;
efi_status_t status; efi_status_t status;
int err;
if (down_interruptible(&efivars_lock)) err = efivar_lock();
return -EINTR; if (err)
return err;
if (!__efivars) { status = efivar_set_variable_locked(entry->var.VariableName,
up(&efivars_lock); &entry->var.VendorGuid,
return -EINVAL; 0, 0, NULL, false);
}
ops = __efivars->ops;
status = ops->set_variable(entry->var.VariableName,
&entry->var.VendorGuid,
0, 0, NULL);
if (!(status == EFI_SUCCESS || status == EFI_NOT_FOUND)) { if (!(status == EFI_SUCCESS || status == EFI_NOT_FOUND)) {
up(&efivars_lock); efivar_unlock();
return efi_status_to_err(status); return efi_status_to_err(status);
} }
...@@ -591,21 +583,18 @@ EXPORT_SYMBOL_GPL(efivar_entry_delete); ...@@ -591,21 +583,18 @@ EXPORT_SYMBOL_GPL(efivar_entry_delete);
*/ */
int efivar_entry_size(struct efivar_entry *entry, unsigned long *size) int efivar_entry_size(struct efivar_entry *entry, unsigned long *size)
{ {
const struct efivar_operations *ops;
efi_status_t status; efi_status_t status;
int err;
*size = 0; *size = 0;
if (down_interruptible(&efivars_lock)) err = efivar_lock();
return -EINTR; if (err)
if (!__efivars) { return err;
up(&efivars_lock);
return -EINVAL; status = efivar_get_variable(entry->var.VariableName,
} &entry->var.VendorGuid, NULL, size, NULL);
ops = __efivars->ops; efivar_unlock();
status = ops->get_variable(entry->var.VariableName,
&entry->var.VendorGuid, NULL, size, NULL);
up(&efivars_lock);
if (status != EFI_BUFFER_TOO_SMALL) if (status != EFI_BUFFER_TOO_SMALL)
return efi_status_to_err(status); return efi_status_to_err(status);
...@@ -621,21 +610,16 @@ EXPORT_SYMBOL_GPL(efivar_entry_size); ...@@ -621,21 +610,16 @@ EXPORT_SYMBOL_GPL(efivar_entry_size);
* @size: size of @data buffer * @size: size of @data buffer
* @data: buffer to store variable data * @data: buffer to store variable data
* *
* The caller MUST call efivar_entry_iter_begin() and * The caller MUST hold the efivar lock when calling this function.
* efivar_entry_iter_end() before and after the invocation of this
* function, respectively.
*/ */
int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes, int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
unsigned long *size, void *data) unsigned long *size, void *data)
{ {
efi_status_t status; efi_status_t status;
if (!__efivars) status = efivar_get_variable(entry->var.VariableName,
return -EINVAL; &entry->var.VendorGuid,
attributes, size, data);
status = __efivars->ops->get_variable(entry->var.VariableName,
&entry->var.VendorGuid,
attributes, size, data);
return efi_status_to_err(status); return efi_status_to_err(status);
} }
...@@ -651,22 +635,15 @@ EXPORT_SYMBOL_GPL(__efivar_entry_get); ...@@ -651,22 +635,15 @@ EXPORT_SYMBOL_GPL(__efivar_entry_get);
int efivar_entry_get(struct efivar_entry *entry, u32 *attributes, int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
unsigned long *size, void *data) unsigned long *size, void *data)
{ {
efi_status_t status; int err;
if (down_interruptible(&efivars_lock))
return -EINTR;
if (!__efivars) {
up(&efivars_lock);
return -EINVAL;
}
status = __efivars->ops->get_variable(entry->var.VariableName, err = efivar_lock();
&entry->var.VendorGuid, if (err)
attributes, size, data); return err;
up(&efivars_lock); err = __efivar_entry_get(entry, attributes, size, data);
efivar_unlock();
return efi_status_to_err(status); return err;
} }
EXPORT_SYMBOL_GPL(efivar_entry_get); EXPORT_SYMBOL_GPL(efivar_entry_get);
...@@ -695,7 +672,6 @@ EXPORT_SYMBOL_GPL(efivar_entry_get); ...@@ -695,7 +672,6 @@ EXPORT_SYMBOL_GPL(efivar_entry_get);
int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes, int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
unsigned long *size, void *data, bool *set) unsigned long *size, void *data, bool *set)
{ {
const struct efivar_operations *ops;
efi_char16_t *name = entry->var.VariableName; efi_char16_t *name = entry->var.VariableName;
efi_guid_t *vendor = &entry->var.VendorGuid; efi_guid_t *vendor = &entry->var.VendorGuid;
efi_status_t status; efi_status_t status;
...@@ -711,13 +687,9 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes, ...@@ -711,13 +687,9 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
* set_variable call, and removal of the variable from the efivars * set_variable call, and removal of the variable from the efivars
* list (in the case of an authenticated delete). * list (in the case of an authenticated delete).
*/ */
if (down_interruptible(&efivars_lock)) err = efivar_lock();
return -EINTR; if (err)
return err;
if (!__efivars) {
err = -EINVAL;
goto out;
}
/* /*
* Ensure that the available space hasn't shrunk below the safe level * Ensure that the available space hasn't shrunk below the safe level
...@@ -735,9 +707,8 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes, ...@@ -735,9 +707,8 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
} }
} }
ops = __efivars->ops; status = efivar_set_variable_locked(name, vendor, attributes, *size,
data, false);
status = ops->set_variable(name, vendor, attributes, *size, data);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
err = efi_status_to_err(status); err = efi_status_to_err(status);
goto out; goto out;
...@@ -752,14 +723,14 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes, ...@@ -752,14 +723,14 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
* happened. * happened.
*/ */
*size = 0; *size = 0;
status = ops->get_variable(entry->var.VariableName, status = efivar_get_variable(entry->var.VariableName,
&entry->var.VendorGuid, &entry->var.VendorGuid,
NULL, size, NULL); NULL, size, NULL);
if (status == EFI_NOT_FOUND) if (status == EFI_NOT_FOUND)
efivar_entry_list_del_unlock(entry); efivar_entry_list_del_unlock(entry);
else else
up(&efivars_lock); efivar_unlock();
if (status && status != EFI_BUFFER_TOO_SMALL) if (status && status != EFI_BUFFER_TOO_SMALL)
return efi_status_to_err(status); return efi_status_to_err(status);
...@@ -767,7 +738,7 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes, ...@@ -767,7 +738,7 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
return 0; return 0;
out: out:
up(&efivars_lock); efivar_unlock();
return err; return err;
} }
...@@ -793,7 +764,7 @@ int efivar_entry_iter(int (*func)(struct efivar_entry *, void *), ...@@ -793,7 +764,7 @@ int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
struct efivar_entry *entry, *n; struct efivar_entry *entry, *n;
int err = 0; int err = 0;
err = down_interruptible(&efivars_lock); err = efivar_lock();
if (err) if (err)
return err; return err;
...@@ -802,7 +773,7 @@ int efivar_entry_iter(int (*func)(struct efivar_entry *, void *), ...@@ -802,7 +773,7 @@ int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
if (err) if (err)
break; break;
} }
up(&efivars_lock); efivar_unlock();
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment