Skip to content

Commit ede9c27

Browse files
andy-shevtorvalds
authored andcommitted
kernel/sysctl_binary.c: use generic UUID library
UUID library provides uuid_be type and uuid_be_to_bin() function. This substitutes open coded variant by generic library calls. 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>
1 parent e3a93bc commit ede9c27

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

kernel/sysctl_binary.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/ctype.h>
1414
#include <linux/netdevice.h>
1515
#include <linux/kernel.h>
16+
#include <linux/uuid.h>
1617
#include <linux/slab.h>
1718
#include <linux/compat.h>
1819

@@ -1117,34 +1118,24 @@ static ssize_t bin_uuid(struct file *file,
11171118

11181119
/* Only supports reads */
11191120
if (oldval && oldlen) {
1120-
char buf[40], *str = buf;
1121-
unsigned char uuid[16];
1122-
int i;
1121+
char buf[UUID_STRING_LEN + 1];
1122+
uuid_be uuid;
11231123

11241124
result = kernel_read(file, 0, buf, sizeof(buf) - 1);
11251125
if (result < 0)
11261126
goto out;
11271127

11281128
buf[result] = '\0';
11291129

1130-
/* Convert the uuid to from a string to binary */
1131-
for (i = 0; i < 16; i++) {
1132-
result = -EIO;
1133-
if (!isxdigit(str[0]) || !isxdigit(str[1]))
1134-
goto out;
1135-
1136-
uuid[i] = (hex_to_bin(str[0]) << 4) |
1137-
hex_to_bin(str[1]);
1138-
str += 2;
1139-
if (*str == '-')
1140-
str++;
1141-
}
1130+
result = -EIO;
1131+
if (uuid_be_to_bin(buf, &uuid))
1132+
goto out;
11421133

11431134
if (oldlen > 16)
11441135
oldlen = 16;
11451136

11461137
result = -EFAULT;
1147-
if (copy_to_user(oldval, uuid, oldlen))
1138+
if (copy_to_user(oldval, &uuid, oldlen))
11481139
goto out;
11491140

11501141
copied = oldlen;

0 commit comments

Comments
 (0)