mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
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>
This commit is contained in:
parent
e3a93bce69
commit
ede9c27749
1 changed files with 7 additions and 16 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
#include <linux/netdevice.h>
|
#include <linux/netdevice.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/uuid.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/compat.h>
|
#include <linux/compat.h>
|
||||||
|
|
||||||
|
@ -1117,9 +1118,8 @@ static ssize_t bin_uuid(struct file *file,
|
||||||
|
|
||||||
/* Only supports reads */
|
/* Only supports reads */
|
||||||
if (oldval && oldlen) {
|
if (oldval && oldlen) {
|
||||||
char buf[40], *str = buf;
|
char buf[UUID_STRING_LEN + 1];
|
||||||
unsigned char uuid[16];
|
uuid_be uuid;
|
||||||
int i;
|
|
||||||
|
|
||||||
result = kernel_read(file, 0, buf, sizeof(buf) - 1);
|
result = kernel_read(file, 0, buf, sizeof(buf) - 1);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
|
@ -1127,24 +1127,15 @@ static ssize_t bin_uuid(struct file *file,
|
||||||
|
|
||||||
buf[result] = '\0';
|
buf[result] = '\0';
|
||||||
|
|
||||||
/* Convert the uuid to from a string to binary */
|
result = -EIO;
|
||||||
for (i = 0; i < 16; i++) {
|
if (uuid_be_to_bin(buf, &uuid))
|
||||||
result = -EIO;
|
goto out;
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldlen > 16)
|
if (oldlen > 16)
|
||||||
oldlen = 16;
|
oldlen = 16;
|
||||||
|
|
||||||
result = -EFAULT;
|
result = -EFAULT;
|
||||||
if (copy_to_user(oldval, uuid, oldlen))
|
if (copy_to_user(oldval, &uuid, oldlen))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
copied = oldlen;
|
copied = oldlen;
|
||||||
|
|
Loading…
Reference in a new issue