aboutsummaryrefslogtreecommitdiffstats
path: root/fs/efivarfs
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2016-05-20 20:01:21 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-20 20:58:30 -0400
commit8236431d8d09eee70e6cbc506426a7c97778a2e6 (patch)
treef17e64f9cf3a854c17daa67223634626d9065131 /fs/efivarfs
parentba7e34b1bbd2722685bbc75d168672d5154d8614 (diff)
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>
Diffstat (limited to 'fs/efivarfs')
-rw-r--r--fs/efivarfs/inode.c40
1 files changed, 3 insertions, 37 deletions
diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c
index e2ab6d0497f2..1d73fc6dba13 100644
--- a/fs/efivarfs/inode.c
+++ b/fs/efivarfs/inode.c
@@ -11,6 +11,7 @@
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/ctype.h> 12#include <linux/ctype.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/uuid.h>
14 15
15#include "internal.h" 16#include "internal.h"
16 17
@@ -46,11 +47,7 @@ struct inode *efivarfs_get_inode(struct super_block *sb,
46 */ 47 */
47bool efivarfs_valid_name(const char *str, int len) 48bool efivarfs_valid_name(const char *str, int len)
48{ 49{
49 static const char dashes[EFI_VARIABLE_GUID_LEN] = {
50 [8] = 1, [13] = 1, [18] = 1, [23] = 1
51 };
52 const char *s = str + len - EFI_VARIABLE_GUID_LEN; 50 const char *s = str + len - EFI_VARIABLE_GUID_LEN;
53 int i;
54 51
55 /* 52 /*
56 * We need a GUID, plus at least one letter for the variable name, 53 * We need a GUID, plus at least one letter for the variable name,
@@ -68,37 +65,7 @@ bool efivarfs_valid_name(const char *str, int len)
68 * 65 *
69 * 12345678-1234-1234-1234-123456789abc 66 * 12345678-1234-1234-1234-123456789abc
70 */ 67 */
71 for (i = 0; i < EFI_VARIABLE_GUID_LEN; i++) { 68 return uuid_is_valid(s);
72 if (dashes[i]) {
73 if (*s++ != '-')
74 return false;
75 } else {
76 if (!isxdigit(*s++))
77 return false;
78 }
79 }
80
81 return true;
82}
83
84static void efivarfs_hex_to_guid(const char *str, efi_guid_t *guid)
85{
86 guid->b[0] = hex_to_bin(str[6]) << 4 | hex_to_bin(str[7]);
87 guid->b[1] = hex_to_bin(str[4]) << 4 | hex_to_bin(str[5]);
88 guid->b[2] = hex_to_bin(str[2]) << 4 | hex_to_bin(str[3]);
89 guid->b[3] = hex_to_bin(str[0]) << 4 | hex_to_bin(str[1]);
90 guid->b[4] = hex_to_bin(str[11]) << 4 | hex_to_bin(str[12]);
91 guid->b[5] = hex_to_bin(str[9]) << 4 | hex_to_bin(str[10]);
92 guid->b[6] = hex_to_bin(str[16]) << 4 | hex_to_bin(str[17]);
93 guid->b[7] = hex_to_bin(str[14]) << 4 | hex_to_bin(str[15]);
94 guid->b[8] = hex_to_bin(str[19]) << 4 | hex_to_bin(str[20]);
95 guid->b[9] = hex_to_bin(str[21]) << 4 | hex_to_bin(str[22]);
96 guid->b[10] = hex_to_bin(str[24]) << 4 | hex_to_bin(str[25]);
97 guid->b[11] = hex_to_bin(str[26]) << 4 | hex_to_bin(str[27]);
98 guid->b[12] = hex_to_bin(str[28]) << 4 | hex_to_bin(str[29]);
99 guid->b[13] = hex_to_bin(str[30]) << 4 | hex_to_bin(str[31]);
100 guid->b[14] = hex_to_bin(str[32]) << 4 | hex_to_bin(str[33]);
101 guid->b[15] = hex_to_bin(str[34]) << 4 | hex_to_bin(str[35]);
102} 69}
103 70
104static int efivarfs_create(struct inode *dir, struct dentry *dentry, 71static int efivarfs_create(struct inode *dir, struct dentry *dentry,
@@ -119,8 +86,7 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
119 /* length of the variable name itself: remove GUID and separator */ 86 /* length of the variable name itself: remove GUID and separator */
120 namelen = dentry->d_name.len - EFI_VARIABLE_GUID_LEN - 1; 87 namelen = dentry->d_name.len - EFI_VARIABLE_GUID_LEN - 1;
121 88
122 efivarfs_hex_to_guid(dentry->d_name.name + namelen + 1, 89 uuid_le_to_bin(dentry->d_name.name + namelen + 1, &var->var.VendorGuid);
123 &var->var.VendorGuid);
124 90
125 if (efivar_variable_is_removable(var->var.VendorGuid, 91 if (efivar_variable_is_removable(var->var.VendorGuid,
126 dentry->d_name.name, namelen)) 92 dentry->d_name.name, namelen))