aboutsummaryrefslogtreecommitdiff
path: root/lib/efi_loader
diff options
context:
space:
mode:
authorHeinrich Schuchardt2019-09-07 21:05:45 +0200
committerHeinrich Schuchardt2019-09-09 15:21:08 +0200
commit87c4840610e037018b9df30b1a31896b0bd284a9 (patch)
treed7e112606eb5f99afac3b277bc0c125335b79f20 /lib/efi_loader
parentb0f1c728c82c25291895d66e591fa2a6851ba374 (diff)
efi_loader: eliminate inline function ascii2unicode()
ascii2unicode() can only convert characters 0x00-0x7f from UTF-8 to UTF-16. Use utf8_utf16_strcpy() instead. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'lib/efi_loader')
-rw-r--r--lib/efi_loader/efi_device_path_to_text.c10
-rw-r--r--lib/efi_loader/efi_file.c23
2 files changed, 20 insertions, 13 deletions
diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c
index b20b7c097c9..0f3796b373b 100644
--- a/lib/efi_loader/efi_device_path_to_text.c
+++ b/lib/efi_loader/efi_device_path_to_text.c
@@ -29,15 +29,15 @@ const efi_guid_t efi_guid_device_path_to_text_protocol =
static u16 *efi_str_to_u16(char *str)
{
efi_uintn_t len;
- u16 *out;
+ u16 *out, *dst;
efi_status_t ret;
- len = strlen(str) + 1;
- ret = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, len * sizeof(u16),
- (void **)&out);
+ len = sizeof(u16) * (utf8_utf16_strlen(str) + 1);
+ ret = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, len, (void **)&out);
if (ret != EFI_SUCCESS)
return NULL;
- ascii2unicode(out, str);
+ dst = out;
+ utf8_utf16_strcpy(&dst, str);
return out;
}
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index a13754a558f..9f78b822419 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -339,6 +339,7 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
struct efi_file_info *info = buffer;
struct fs_dirent *dent;
unsigned int required_size;
+ u16 *dst;
if (!fh->dirs) {
assert(fh->offset == 0);
@@ -381,7 +382,8 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
}
/* check buffer size: */
- required_size = sizeof(*info) + 2 * (strlen(dent->name) + 1);
+ required_size = sizeof(*info) +
+ 2 * (utf8_utf16_strlen(dent->name) + 1);
if (*buffer_size < required_size) {
*buffer_size = required_size;
fh->dent = dent;
@@ -398,7 +400,8 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
if (dent->type == FS_DT_DIR)
info->attribute |= EFI_FILE_DIRECTORY;
- ascii2unicode(info->file_name, dent->name);
+ dst = info->file_name;
+ utf8_utf16_strcpy(&dst, dent->name);
fh->offset++;
@@ -577,6 +580,7 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file,
{
struct file_handle *fh = to_fh(file);
efi_status_t ret = EFI_SUCCESS;
+ u16 *dst;
EFI_ENTRY("%p, %pUl, %p, %p", file, info_type, buffer_size, buffer);
@@ -587,7 +591,8 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file,
loff_t file_size;
/* check buffer size: */
- required_size = sizeof(*info) + 2 * (strlen(filename) + 1);
+ required_size = sizeof(*info) +
+ 2 * (utf8_utf16_strlen(filename) + 1);
if (*buffer_size < required_size) {
*buffer_size = required_size;
ret = EFI_BUFFER_TOO_SMALL;
@@ -613,7 +618,8 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file,
if (fh->isdir)
info->attribute |= EFI_FILE_DIRECTORY;
- ascii2unicode(info->file_name, filename);
+ dst = info->file_name;
+ utf8_utf16_strcpy(&dst, filename);
} else if (!guidcmp(info_type, &efi_file_system_info_guid)) {
struct efi_file_system_info *info = buffer;
disk_partition_t part;
@@ -628,8 +634,9 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file,
ret = EFI_DEVICE_ERROR;
goto error;
}
- required_size = sizeof(info) + 2 *
- (strlen((const char *)part.name) + 1);
+ required_size = sizeof(*info) + 2 *
+ (utf8_utf16_strlen((const char *)part.name) +
+ 1);
if (*buffer_size < required_size) {
*buffer_size = required_size;
ret = EFI_BUFFER_TOO_SMALL;
@@ -647,8 +654,8 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file,
* TODO: The volume label is not available in U-Boot.
* Use the partition name as substitute.
*/
- ascii2unicode((u16 *)info->volume_label,
- (const char *)part.name);
+ dst = info->volume_label;
+ utf8_utf16_strcpy(&dst, (const char *)part.name);
} else {
ret = EFI_UNSUPPORTED;
}