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
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, · 1098 unmodified lines
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, · 1 unmodified line
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;