From: Matt Fleming
Git-commit: 7253eaba7b179db2e07e67c5b78d5f10b332291d
Patch-mainline: v3.8-rc1
Target: openSUSE 12.3
Instead of always returning 0 in efivarfs_file_read(), even when we
fail to successfully read the variable, convert the EFI status to
something meaningful and return that to the caller. This way the user
will have some hint as to why the read failed.
Acked-by: Jeremy Kerr
Signed-off-by: Matt Fleming
Acked-by: Lee, Chun-Yi
---
drivers/firmware/efivars.c | 62 ++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 26 deletions(-)
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -648,6 +648,36 @@ static int efivarfs_file_open(struct ino
return 0;
}
+static int efi_status_to_err(efi_status_t status)
+{
+ int err;
+
+ switch (status) {
+ case EFI_INVALID_PARAMETER:
+ err = -EINVAL;
+ break;
+ case EFI_OUT_OF_RESOURCES:
+ err = -ENOSPC;
+ break;
+ case EFI_DEVICE_ERROR:
+ err = -EIO;
+ break;
+ case EFI_WRITE_PROTECTED:
+ err = -EROFS;
+ break;
+ case EFI_SECURITY_VIOLATION:
+ err = -EACCES;
+ break;
+ case EFI_NOT_FOUND:
+ err = -ENOENT;
+ break;
+ default:
+ err = -EINVAL;
+ }
+
+ return err;
+}
+
static ssize_t efivarfs_file_write(struct file *file,
const char __user *userbuf, size_t count, loff_t *ppos)
{
@@ -706,29 +736,7 @@ static ssize_t efivarfs_file_write(struc
spin_unlock(&efivars->lock);
kfree(data);
- switch (status) {
- case EFI_INVALID_PARAMETER:
- count = -EINVAL;
- break;
- case EFI_OUT_OF_RESOURCES:
- count = -ENOSPC;
- break;
- case EFI_DEVICE_ERROR:
- count = -EIO;
- break;
- case EFI_WRITE_PROTECTED:
- count = -EROFS;
- break;
- case EFI_SECURITY_VIOLATION:
- count = -EACCES;
- break;
- case EFI_NOT_FOUND:
- count = -ENOENT;
- break;
- default:
- count = -EINVAL;
- }
- return count;
+ return efi_status_to_err(status);
}
/*
@@ -786,12 +794,12 @@ static ssize_t efivarfs_file_read(struct
spin_unlock(&efivars->lock);
if (status != EFI_BUFFER_TOO_SMALL)
- return 0;
+ return efi_status_to_err(status);
data = kmalloc(datasize + 4, GFP_KERNEL);
if (!data)
- return 0;
+ return -ENOMEM;
spin_lock(&efivars->lock);
status = efivars->ops->get_variable(var->var.VariableName,
@@ -800,8 +808,10 @@ static ssize_t efivarfs_file_read(struct
(data + 4));
spin_unlock(&efivars->lock);
- if (status != EFI_SUCCESS)
+ if (status != EFI_SUCCESS) {
+ size = efi_status_to_err(status);
goto out_free;
+ }
memcpy(data, &attributes, 4);
size = simple_read_from_buffer(userbuf, count, ppos,
--
To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org
To contact the owner, e-mail: opensuse-kernel+owner@opensuse.org