diff options
author | Mike Waychison <mikew@google.com> | 2011-07-21 16:57:57 -0400 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2011-07-22 19:15:21 -0400 |
commit | a2940908391f3cee72e38769b30e829b22742b5b (patch) | |
tree | 30dc4ca2eae129f2612e74b60ff125b75af45eae /drivers/firmware | |
parent | 5ee9c198a4208d7760275d48e4c4f6c89dcd2ef0 (diff) |
efivars: String functions
Fix the string functions in the efivars driver to be called utf16_*
instead of utf8_* as the encoding is utf16, not utf8.
As well, rename utf16_strlen to utf16_strnlen as it takes a maxlength
argument and the name should be consistent with the standard C function
names. utf16_strlen is still provided for convenience in a subsequent
patch.
Signed-off-by: Mike Waychison <mikew@google.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'drivers/firmware')
-rw-r--r-- | drivers/firmware/efivars.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c index 2bbb22670d2d..4202a3170467 100644 --- a/drivers/firmware/efivars.c +++ b/drivers/firmware/efivars.c | |||
@@ -144,23 +144,29 @@ efivar_create_sysfs_entry(struct efivars *efivars, | |||
144 | 144 | ||
145 | /* Return the number of unicode characters in data */ | 145 | /* Return the number of unicode characters in data */ |
146 | static unsigned long | 146 | static unsigned long |
147 | utf8_strlen(efi_char16_t *data, unsigned long maxlength) | 147 | utf16_strnlen(efi_char16_t *s, size_t maxlength) |
148 | { | 148 | { |
149 | unsigned long length = 0; | 149 | unsigned long length = 0; |
150 | 150 | ||
151 | while (*data++ != 0 && length < maxlength) | 151 | while (*s++ != 0 && length < maxlength) |
152 | length++; | 152 | length++; |
153 | return length; | 153 | return length; |
154 | } | 154 | } |
155 | 155 | ||
156 | static unsigned long | ||
157 | utf16_strlen(efi_char16_t *s) | ||
158 | { | ||
159 | return utf16_strnlen(s, ~0UL); | ||
160 | } | ||
161 | |||
156 | /* | 162 | /* |
157 | * Return the number of bytes is the length of this string | 163 | * Return the number of bytes is the length of this string |
158 | * Note: this is NOT the same as the number of unicode characters | 164 | * Note: this is NOT the same as the number of unicode characters |
159 | */ | 165 | */ |
160 | static inline unsigned long | 166 | static inline unsigned long |
161 | utf8_strsize(efi_char16_t *data, unsigned long maxlength) | 167 | utf16_strsize(efi_char16_t *data, unsigned long maxlength) |
162 | { | 168 | { |
163 | return utf8_strlen(data, maxlength/sizeof(efi_char16_t)) * sizeof(efi_char16_t); | 169 | return utf16_strnlen(data, maxlength/sizeof(efi_char16_t)) * sizeof(efi_char16_t); |
164 | } | 170 | } |
165 | 171 | ||
166 | static efi_status_t | 172 | static efi_status_t |
@@ -518,7 +524,9 @@ static u64 efi_pstore_write(enum pstore_type_id type, unsigned int part, | |||
518 | efivar_unregister(found); | 524 | efivar_unregister(found); |
519 | 525 | ||
520 | if (size) | 526 | if (size) |
521 | efivar_create_sysfs_entry(efivars, utf8_strsize(efi_name, DUMP_NAME_LEN * 2), | 527 | efivar_create_sysfs_entry(efivars, |
528 | utf16_strsize(efi_name, | ||
529 | DUMP_NAME_LEN * 2), | ||
522 | efi_name, &vendor); | 530 | efi_name, &vendor); |
523 | 531 | ||
524 | return part; | 532 | return part; |
@@ -591,8 +599,8 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, | |||
591 | * Does this variable already exist? | 599 | * Does this variable already exist? |
592 | */ | 600 | */ |
593 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { | 601 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { |
594 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); | 602 | strsize1 = utf16_strsize(search_efivar->var.VariableName, 1024); |
595 | strsize2 = utf8_strsize(new_var->VariableName, 1024); | 603 | strsize2 = utf16_strsize(new_var->VariableName, 1024); |
596 | if (strsize1 == strsize2 && | 604 | if (strsize1 == strsize2 && |
597 | !memcmp(&(search_efivar->var.VariableName), | 605 | !memcmp(&(search_efivar->var.VariableName), |
598 | new_var->VariableName, strsize1) && | 606 | new_var->VariableName, strsize1) && |
@@ -624,8 +632,8 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, | |||
624 | 632 | ||
625 | /* Create the entry in sysfs. Locking is not required here */ | 633 | /* Create the entry in sysfs. Locking is not required here */ |
626 | status = efivar_create_sysfs_entry(efivars, | 634 | status = efivar_create_sysfs_entry(efivars, |
627 | utf8_strsize(new_var->VariableName, | 635 | utf16_strsize(new_var->VariableName, |
628 | 1024), | 636 | 1024), |
629 | new_var->VariableName, | 637 | new_var->VariableName, |
630 | &new_var->VendorGuid); | 638 | &new_var->VendorGuid); |
631 | if (status) { | 639 | if (status) { |
@@ -654,8 +662,8 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, | |||
654 | * Does this variable already exist? | 662 | * Does this variable already exist? |
655 | */ | 663 | */ |
656 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { | 664 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { |
657 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); | 665 | strsize1 = utf16_strsize(search_efivar->var.VariableName, 1024); |
658 | strsize2 = utf8_strsize(del_var->VariableName, 1024); | 666 | strsize2 = utf16_strsize(del_var->VariableName, 1024); |
659 | if (strsize1 == strsize2 && | 667 | if (strsize1 == strsize2 && |
660 | !memcmp(&(search_efivar->var.VariableName), | 668 | !memcmp(&(search_efivar->var.VariableName), |
661 | del_var->VariableName, strsize1) && | 669 | del_var->VariableName, strsize1) && |