aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sysctl_binary.c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2016-05-20 20:01:10 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-20 20:58:30 -0400
commitede9c27749b9b35efdffa4f63a39f819d7913752 (patch)
tree0aef5f5ffaa37df36c8d3a5dab4d7adebe2f292e /kernel/sysctl_binary.c
parente3a93bce69ad3e2c38927abe311b8cb4f17abbaf (diff)
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>
Diffstat (limited to 'kernel/sysctl_binary.c')
-rw-r--r--kernel/sysctl_binary.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index 10a1d7dc9313..6eb99c17dbd8 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -13,6 +13,7 @@
13#include <linux/ctype.h> 13#include <linux/ctype.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/uuid.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <linux/compat.h> 18#include <linux/compat.h>
18 19
@@ -1117,9 +1118,8 @@ static ssize_t bin_uuid(struct file *file,
1117 1118
1118 /* Only supports reads */ 1119 /* Only supports reads */
1119 if (oldval && oldlen) { 1120 if (oldval && oldlen) {
1120 char buf[40], *str = buf; 1121 char buf[UUID_STRING_LEN + 1];
1121 unsigned char uuid[16]; 1122 uuid_be uuid;
1122 int i;
1123 1123
1124 result = kernel_read(file, 0, buf, sizeof(buf) - 1); 1124 result = kernel_read(file, 0, buf, sizeof(buf) - 1);
1125 if (result < 0) 1125 if (result < 0)
@@ -1127,24 +1127,15 @@ static ssize_t bin_uuid(struct file *file,
1127 1127
1128 buf[result] = '\0'; 1128 buf[result] = '\0';
1129 1129
1130 /* Convert the uuid to from a string to binary */ 1130 result = -EIO;
1131 for (i = 0; i < 16; i++) { 1131 if (uuid_be_to_bin(buf, &uuid))
1132 result = -EIO; 1132 goto out;
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 }
1142 1133
1143 if (oldlen > 16) 1134 if (oldlen > 16)
1144 oldlen = 16; 1135 oldlen = 16;
1145 1136
1146 result = -EFAULT; 1137 result = -EFAULT;
1147 if (copy_to_user(oldval, uuid, oldlen)) 1138 if (copy_to_user(oldval, &uuid, oldlen))
1148 goto out; 1139 goto out;
1149 1140
1150 copied = oldlen; 1141 copied = oldlen;