diff options
| author | Mike Waychison <mikew@google.com> | 2011-07-21 16:57:57 -0400 |
|---|---|---|
| committer | Luis Henriques <luis.henriques@canonical.com> | 2012-05-25 12:24:39 -0400 |
| commit | 7bbc19d84d0ea21f5f14dd67de77beeee4880e44 (patch) | |
| tree | 42075baed401063cbe11cefd7142a4e99a467447 /drivers/firmware | |
| parent | 8e5c6f440700b6b4d28874e0afd4b4757cbd6090 (diff) | |
efivars: String functions
BugLink: http://bugs.launchpad.net/bugs/996109
commit a2940908391f3cee72e38769b30e829b22742b5b upstream.
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/firmware')
| -rw-r--r-- | drivers/firmware/efivars.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c index 5f29aafd446..0ba8d69dd6c 100644 --- a/drivers/firmware/efivars.c +++ b/drivers/firmware/efivars.c | |||
| @@ -141,23 +141,29 @@ efivar_create_sysfs_entry(struct efivars *efivars, | |||
| 141 | 141 | ||
| 142 | /* Return the number of unicode characters in data */ | 142 | /* Return the number of unicode characters in data */ |
| 143 | static unsigned long | 143 | static unsigned long |
| 144 | utf8_strlen(efi_char16_t *data, unsigned long maxlength) | 144 | utf16_strnlen(efi_char16_t *s, size_t maxlength) |
| 145 | { | 145 | { |
| 146 | unsigned long length = 0; | 146 | unsigned long length = 0; |
| 147 | 147 | ||
| 148 | while (*data++ != 0 && length < maxlength) | 148 | while (*s++ != 0 && length < maxlength) |
| 149 | length++; | 149 | length++; |
| 150 | return length; | 150 | return length; |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | static unsigned long | ||
| 154 | utf16_strlen(efi_char16_t *s) | ||
| 155 | { | ||
| 156 | return utf16_strnlen(s, ~0UL); | ||
| 157 | } | ||
| 158 | |||
| 153 | /* | 159 | /* |
| 154 | * Return the number of bytes is the length of this string | 160 | * Return the number of bytes is the length of this string |
| 155 | * Note: this is NOT the same as the number of unicode characters | 161 | * Note: this is NOT the same as the number of unicode characters |
| 156 | */ | 162 | */ |
| 157 | static inline unsigned long | 163 | static inline unsigned long |
| 158 | utf8_strsize(efi_char16_t *data, unsigned long maxlength) | 164 | utf16_strsize(efi_char16_t *data, unsigned long maxlength) |
| 159 | { | 165 | { |
| 160 | return utf8_strlen(data, maxlength/sizeof(efi_char16_t)) * sizeof(efi_char16_t); | 166 | return utf16_strnlen(data, maxlength/sizeof(efi_char16_t)) * sizeof(efi_char16_t); |
| 161 | } | 167 | } |
| 162 | 168 | ||
| 163 | static efi_status_t | 169 | static efi_status_t |
| @@ -414,8 +420,8 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, | |||
| 414 | * Does this variable already exist? | 420 | * Does this variable already exist? |
| 415 | */ | 421 | */ |
| 416 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { | 422 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { |
| 417 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); | 423 | strsize1 = utf16_strsize(search_efivar->var.VariableName, 1024); |
| 418 | strsize2 = utf8_strsize(new_var->VariableName, 1024); | 424 | strsize2 = utf16_strsize(new_var->VariableName, 1024); |
| 419 | if (strsize1 == strsize2 && | 425 | if (strsize1 == strsize2 && |
| 420 | !memcmp(&(search_efivar->var.VariableName), | 426 | !memcmp(&(search_efivar->var.VariableName), |
| 421 | new_var->VariableName, strsize1) && | 427 | new_var->VariableName, strsize1) && |
| @@ -447,8 +453,8 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, | |||
| 447 | 453 | ||
| 448 | /* Create the entry in sysfs. Locking is not required here */ | 454 | /* Create the entry in sysfs. Locking is not required here */ |
| 449 | status = efivar_create_sysfs_entry(efivars, | 455 | status = efivar_create_sysfs_entry(efivars, |
| 450 | utf8_strsize(new_var->VariableName, | 456 | utf16_strsize(new_var->VariableName, |
| 451 | 1024), | 457 | 1024), |
| 452 | new_var->VariableName, | 458 | new_var->VariableName, |
| 453 | &new_var->VendorGuid); | 459 | &new_var->VendorGuid); |
| 454 | if (status) { | 460 | if (status) { |
| @@ -477,8 +483,8 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, | |||
| 477 | * Does this variable already exist? | 483 | * Does this variable already exist? |
| 478 | */ | 484 | */ |
| 479 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { | 485 | list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { |
| 480 | strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); | 486 | strsize1 = utf16_strsize(search_efivar->var.VariableName, 1024); |
| 481 | strsize2 = utf8_strsize(del_var->VariableName, 1024); | 487 | strsize2 = utf16_strsize(del_var->VariableName, 1024); |
| 482 | if (strsize1 == strsize2 && | 488 | if (strsize1 == strsize2 && |
| 483 | !memcmp(&(search_efivar->var.VariableName), | 489 | !memcmp(&(search_efivar->var.VariableName), |
| 484 | del_var->VariableName, strsize1) && | 490 | del_var->VariableName, strsize1) && |
