提交 d5abc7c1 编写于 作者: M Matt Fleming

efi: move utf16 string functions to efi.h

There are currently two implementations of the utf16 string functions.
Somewhat confusingly, they've got different names.

Centralise the functions in efi.h.
Reviewed-by: NTom Gundersen <teg@jklm.no>
Tested-by: NTom Gundersen <teg@jklm.no>
Reviewed-by: NMike Waychison <mikew@google.com>
Signed-off-by: NMatt Fleming <matt.fleming@intel.com>
上级 07961ac7
...@@ -172,23 +172,6 @@ static void efivar_update_sysfs_entries(struct work_struct *); ...@@ -172,23 +172,6 @@ static void efivar_update_sysfs_entries(struct work_struct *);
static DECLARE_WORK(efivar_work, efivar_update_sysfs_entries); static DECLARE_WORK(efivar_work, efivar_update_sysfs_entries);
static bool efivar_wq_enabled = true; static bool efivar_wq_enabled = true;
/* Return the number of unicode characters in data */
static unsigned long
utf16_strnlen(efi_char16_t *s, size_t maxlength)
{
unsigned long length = 0;
while (*s++ != 0 && length < maxlength)
length++;
return length;
}
static inline unsigned long
utf16_strlen(efi_char16_t *s)
{
return utf16_strnlen(s, ~0UL);
}
/* /*
* Return the number of bytes is the length of this string * Return the number of bytes is the length of this string
* Note: this is NOT the same as the number of unicode characters * Note: this is NOT the same as the number of unicode characters
......
...@@ -288,17 +288,6 @@ static int gsmi_exec(u8 func, u8 sub) ...@@ -288,17 +288,6 @@ static int gsmi_exec(u8 func, u8 sub)
return rc; return rc;
} }
/* Return the number of unicode characters in data */
static size_t
utf16_strlen(efi_char16_t *data, unsigned long maxlength)
{
unsigned long length = 0;
while (*data++ != 0 && length < maxlength)
length++;
return length;
}
static efi_status_t gsmi_get_variable(efi_char16_t *name, static efi_status_t gsmi_get_variable(efi_char16_t *name,
efi_guid_t *vendor, u32 *attr, efi_guid_t *vendor, u32 *attr,
unsigned long *data_size, unsigned long *data_size,
...@@ -311,7 +300,7 @@ static efi_status_t gsmi_get_variable(efi_char16_t *name, ...@@ -311,7 +300,7 @@ static efi_status_t gsmi_get_variable(efi_char16_t *name,
}; };
efi_status_t ret = EFI_SUCCESS; efi_status_t ret = EFI_SUCCESS;
unsigned long flags; unsigned long flags;
size_t name_len = utf16_strlen(name, GSMI_BUF_SIZE / 2); size_t name_len = utf16_strnlen(name, GSMI_BUF_SIZE / 2);
int rc; int rc;
if (name_len >= GSMI_BUF_SIZE / 2) if (name_len >= GSMI_BUF_SIZE / 2)
...@@ -380,7 +369,7 @@ static efi_status_t gsmi_get_next_variable(unsigned long *name_size, ...@@ -380,7 +369,7 @@ static efi_status_t gsmi_get_next_variable(unsigned long *name_size,
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
/* Let's make sure the thing is at least null-terminated */ /* Let's make sure the thing is at least null-terminated */
if (utf16_strlen(name, GSMI_BUF_SIZE / 2) == GSMI_BUF_SIZE / 2) if (utf16_strnlen(name, GSMI_BUF_SIZE / 2) == GSMI_BUF_SIZE / 2)
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
spin_lock_irqsave(&gsmi_dev.lock, flags); spin_lock_irqsave(&gsmi_dev.lock, flags);
...@@ -408,7 +397,7 @@ static efi_status_t gsmi_get_next_variable(unsigned long *name_size, ...@@ -408,7 +397,7 @@ static efi_status_t gsmi_get_next_variable(unsigned long *name_size,
/* Copy the name back */ /* Copy the name back */
memcpy(name, gsmi_dev.name_buf->start, GSMI_BUF_SIZE); memcpy(name, gsmi_dev.name_buf->start, GSMI_BUF_SIZE);
*name_size = utf16_strlen(name, GSMI_BUF_SIZE / 2) * 2; *name_size = utf16_strnlen(name, GSMI_BUF_SIZE / 2) * 2;
/* copy guid to return buffer */ /* copy guid to return buffer */
memcpy(vendor, &param.guid, sizeof(param.guid)); memcpy(vendor, &param.guid, sizeof(param.guid));
...@@ -434,7 +423,7 @@ static efi_status_t gsmi_set_variable(efi_char16_t *name, ...@@ -434,7 +423,7 @@ static efi_status_t gsmi_set_variable(efi_char16_t *name,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_RUNTIME_ACCESS,
}; };
size_t name_len = utf16_strlen(name, GSMI_BUF_SIZE / 2); size_t name_len = utf16_strnlen(name, GSMI_BUF_SIZE / 2);
efi_status_t ret = EFI_SUCCESS; efi_status_t ret = EFI_SUCCESS;
int rc; int rc;
unsigned long flags; unsigned long flags;
......
...@@ -719,6 +719,23 @@ static inline void memrange_efi_to_native(u64 *addr, u64 *npages) ...@@ -719,6 +719,23 @@ static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
*addr &= PAGE_MASK; *addr &= PAGE_MASK;
} }
/* Return the number of unicode characters in data */
static inline unsigned long
utf16_strnlen(efi_char16_t *s, size_t maxlength)
{
unsigned long length = 0;
while (*s++ != 0 && length < maxlength)
length++;
return length;
}
static inline unsigned long
utf16_strlen(efi_char16_t *s)
{
return utf16_strnlen(s, ~0UL);
}
#if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE) #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
/* /*
* EFI Variable support. * EFI Variable support.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册