Skip to content

Commit

Permalink
kernel/sysctl_binary.c: use generic UUID library
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Matt Fleming <[email protected]>
Cc: Dmitry Kasatkin <[email protected]>
Cc: Mimi Zohar <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: "Theodore Ts'o" <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Jens Axboe <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
andy-shev authored and torvalds committed May 21, 2016
1 parent e3a93bc commit ede9c27
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions kernel/sysctl_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/ctype.h>
#include <linux/netdevice.h>
#include <linux/kernel.h>
#include <linux/uuid.h>
#include <linux/slab.h>
#include <linux/compat.h>

Expand Down Expand Up @@ -1117,34 +1118,24 @@ static ssize_t bin_uuid(struct file *file,

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

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

buf[result] = '\0';

/* Convert the uuid to from a string to binary */
for (i = 0; i < 16; i++) {
result = -EIO;
if (!isxdigit(str[0]) || !isxdigit(str[1]))
goto out;

uuid[i] = (hex_to_bin(str[0]) << 4) |
hex_to_bin(str[1]);
str += 2;
if (*str == '-')
str++;
}
result = -EIO;
if (uuid_be_to_bin(buf, &uuid))
goto out;

if (oldlen > 16)
oldlen = 16;

result = -EFAULT;
if (copy_to_user(oldval, uuid, oldlen))
if (copy_to_user(oldval, &uuid, oldlen))
goto out;

copied = oldlen;
Expand Down

0 comments on commit ede9c27

Please sign in to comment.