Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/efivarfs/inode.c: use generic UUID library

Instead of opencoding let's use generic UUID library functions here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andy Shevchenko and committed by
Linus Torvalds
8236431d ba7e34b1

+3 -37
+3 -37
fs/efivarfs/inode.c
··· 11 11 #include <linux/fs.h> 12 12 #include <linux/ctype.h> 13 13 #include <linux/slab.h> 14 + #include <linux/uuid.h> 14 15 15 16 #include "internal.h" 16 17 ··· 47 46 */ 48 47 bool efivarfs_valid_name(const char *str, int len) 49 48 { 50 - static const char dashes[EFI_VARIABLE_GUID_LEN] = { 51 - [8] = 1, [13] = 1, [18] = 1, [23] = 1 52 - }; 53 49 const char *s = str + len - EFI_VARIABLE_GUID_LEN; 54 - int i; 55 50 56 51 /* 57 52 * We need a GUID, plus at least one letter for the variable name, ··· 65 68 * 66 69 * 12345678-1234-1234-1234-123456789abc 67 70 */ 68 - for (i = 0; i < EFI_VARIABLE_GUID_LEN; i++) { 69 - if (dashes[i]) { 70 - if (*s++ != '-') 71 - return false; 72 - } else { 73 - if (!isxdigit(*s++)) 74 - return false; 75 - } 76 - } 77 - 78 - return true; 79 - } 80 - 81 - static void efivarfs_hex_to_guid(const char *str, efi_guid_t *guid) 82 - { 83 - guid->b[0] = hex_to_bin(str[6]) << 4 | hex_to_bin(str[7]); 84 - guid->b[1] = hex_to_bin(str[4]) << 4 | hex_to_bin(str[5]); 85 - guid->b[2] = hex_to_bin(str[2]) << 4 | hex_to_bin(str[3]); 86 - guid->b[3] = hex_to_bin(str[0]) << 4 | hex_to_bin(str[1]); 87 - guid->b[4] = hex_to_bin(str[11]) << 4 | hex_to_bin(str[12]); 88 - guid->b[5] = hex_to_bin(str[9]) << 4 | hex_to_bin(str[10]); 89 - guid->b[6] = hex_to_bin(str[16]) << 4 | hex_to_bin(str[17]); 90 - guid->b[7] = hex_to_bin(str[14]) << 4 | hex_to_bin(str[15]); 91 - guid->b[8] = hex_to_bin(str[19]) << 4 | hex_to_bin(str[20]); 92 - guid->b[9] = hex_to_bin(str[21]) << 4 | hex_to_bin(str[22]); 93 - guid->b[10] = hex_to_bin(str[24]) << 4 | hex_to_bin(str[25]); 94 - guid->b[11] = hex_to_bin(str[26]) << 4 | hex_to_bin(str[27]); 95 - guid->b[12] = hex_to_bin(str[28]) << 4 | hex_to_bin(str[29]); 96 - guid->b[13] = hex_to_bin(str[30]) << 4 | hex_to_bin(str[31]); 97 - guid->b[14] = hex_to_bin(str[32]) << 4 | hex_to_bin(str[33]); 98 - guid->b[15] = hex_to_bin(str[34]) << 4 | hex_to_bin(str[35]); 71 + return uuid_is_valid(s); 99 72 } 100 73 101 74 static int efivarfs_create(struct inode *dir, struct dentry *dentry, ··· 86 119 /* length of the variable name itself: remove GUID and separator */ 87 120 namelen = dentry->d_name.len - EFI_VARIABLE_GUID_LEN - 1; 88 121 89 - efivarfs_hex_to_guid(dentry->d_name.name + namelen + 1, 90 - &var->var.VendorGuid); 122 + uuid_le_to_bin(dentry->d_name.name + namelen + 1, &var->var.VendorGuid); 91 123 92 124 if (efivar_variable_is_removable(var->var.VendorGuid, 93 125 dentry->d_name.name, namelen))