UUID library provides uuid_be type and uuid_be_to_bin() function. This substitutes open coded variant by generic library calls.
Showing the changes to kernel/sysctl_binary.c (1 of 1 file). Show all
Unified · Split
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | #include <linux/ctype.h> |
| 14 | 14 | #include <linux/netdevice.h> |
| 15 | 15 | #include <linux/kernel.h> |
| 16 | +#include <linux/uuid.h> | |
| 16 | 17 | #include <linux/slab.h> |
| 17 | 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 | 1119 | /* Only supports reads */ |
| 1119 | 1120 | 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; | |
| 1123 | 1123 | |
| 1124 | 1124 | result = kernel_read(file, 0, buf, sizeof(buf) - 1); |
| 1125 | 1125 | if (result < 0) |
| @@ -1127,24 +1127,15 @@ static ssize_t bin_uuid(struct file *file, · 1 unmodified line | ||
| 1127 | 1127 | |
| 1128 | 1128 | buf[result] = '\0'; |
| 1129 | 1129 | |
| 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; | |
| 1142 | 1133 | |
| 1143 | 1134 | if (oldlen > 16) |
| 1144 | 1135 | oldlen = 16; |
| 1145 | 1136 | |
| 1146 | 1137 | result = -EFAULT; |
| 1147 | − if (copy_to_user(oldval, uuid, oldlen)) | |
| 1138 | + if (copy_to_user(oldval, &uuid, oldlen)) | |
| 1148 | 1139 | goto out; |
| 1149 | 1140 | |
| 1150 | 1141 | copied = oldlen; |