History

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.

Andy Shevchenko committed 10 years ago

Commit ede9c271 parent e3a93bc1 file · +7 −16Browse files

Showing the changes to kernel/sysctl_binary.c (1 of 1 file). Show all

Unified · Split

kernel/sysctl_binary.c+7−16
@@ -13,6 +13,7 @@ · 12 unmodified lines
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,9 +1118,8 @@ static ssize_t bin_uuid(struct file *file, · 1098 unmodified lines
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)
@@ -1127,24 +1127,15 @@ static ssize_t bin_uuid(struct file *file, · 1 unmodified line
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;