| .. | .. |
|---|
| 14 | 14 | */ |
|---|
| 15 | 15 | #include <linux/ctype.h> |
|---|
| 16 | 16 | #include <linux/errno.h> |
|---|
| 17 | | -#include <linux/kernel.h> |
|---|
| 18 | | -#include <linux/math64.h> |
|---|
| 19 | 17 | #include <linux/export.h> |
|---|
| 18 | +#include <linux/kstrtox.h> |
|---|
| 19 | +#include <linux/math64.h> |
|---|
| 20 | 20 | #include <linux/types.h> |
|---|
| 21 | 21 | #include <linux/uaccess.h> |
|---|
| 22 | + |
|---|
| 22 | 23 | #include "kstrtox.h" |
|---|
| 23 | 24 | |
|---|
| 24 | 25 | const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) |
|---|
| .. | .. |
|---|
| 122 | 123 | * @res: Where to write the result of the conversion on success. |
|---|
| 123 | 124 | * |
|---|
| 124 | 125 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 125 | | - * Used as a replacement for the obsolete simple_strtoull. Return code must |
|---|
| 126 | | - * be checked. |
|---|
| 126 | + * Preferred over simple_strtoull(). Return code must be checked. |
|---|
| 127 | 127 | */ |
|---|
| 128 | 128 | int kstrtoull(const char *s, unsigned int base, unsigned long long *res) |
|---|
| 129 | 129 | { |
|---|
| .. | .. |
|---|
| 146 | 146 | * @res: Where to write the result of the conversion on success. |
|---|
| 147 | 147 | * |
|---|
| 148 | 148 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 149 | | - * Used as a replacement for the obsolete simple_strtoull. Return code must |
|---|
| 150 | | - * be checked. |
|---|
| 149 | + * Preferred over simple_strtoll(). Return code must be checked. |
|---|
| 151 | 150 | */ |
|---|
| 152 | 151 | int kstrtoll(const char *s, unsigned int base, long long *res) |
|---|
| 153 | 152 | { |
|---|
| .. | .. |
|---|
| 182 | 181 | rv = kstrtoull(s, base, &tmp); |
|---|
| 183 | 182 | if (rv < 0) |
|---|
| 184 | 183 | return rv; |
|---|
| 185 | | - if (tmp != (unsigned long long)(unsigned long)tmp) |
|---|
| 184 | + if (tmp != (unsigned long)tmp) |
|---|
| 186 | 185 | return -ERANGE; |
|---|
| 187 | 186 | *res = tmp; |
|---|
| 188 | 187 | return 0; |
|---|
| .. | .. |
|---|
| 198 | 197 | rv = kstrtoll(s, base, &tmp); |
|---|
| 199 | 198 | if (rv < 0) |
|---|
| 200 | 199 | return rv; |
|---|
| 201 | | - if (tmp != (long long)(long)tmp) |
|---|
| 200 | + if (tmp != (long)tmp) |
|---|
| 202 | 201 | return -ERANGE; |
|---|
| 203 | 202 | *res = tmp; |
|---|
| 204 | 203 | return 0; |
|---|
| .. | .. |
|---|
| 218 | 217 | * @res: Where to write the result of the conversion on success. |
|---|
| 219 | 218 | * |
|---|
| 220 | 219 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 221 | | - * Used as a replacement for the obsolete simple_strtoull. Return code must |
|---|
| 222 | | - * be checked. |
|---|
| 220 | + * Preferred over simple_strtoul(). Return code must be checked. |
|---|
| 223 | 221 | */ |
|---|
| 224 | 222 | int kstrtouint(const char *s, unsigned int base, unsigned int *res) |
|---|
| 225 | 223 | { |
|---|
| .. | .. |
|---|
| 229 | 227 | rv = kstrtoull(s, base, &tmp); |
|---|
| 230 | 228 | if (rv < 0) |
|---|
| 231 | 229 | return rv; |
|---|
| 232 | | - if (tmp != (unsigned long long)(unsigned int)tmp) |
|---|
| 230 | + if (tmp != (unsigned int)tmp) |
|---|
| 233 | 231 | return -ERANGE; |
|---|
| 234 | 232 | *res = tmp; |
|---|
| 235 | 233 | return 0; |
|---|
| .. | .. |
|---|
| 249 | 247 | * @res: Where to write the result of the conversion on success. |
|---|
| 250 | 248 | * |
|---|
| 251 | 249 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 252 | | - * Used as a replacement for the obsolete simple_strtoull. Return code must |
|---|
| 253 | | - * be checked. |
|---|
| 250 | + * Preferred over simple_strtol(). Return code must be checked. |
|---|
| 254 | 251 | */ |
|---|
| 255 | 252 | int kstrtoint(const char *s, unsigned int base, int *res) |
|---|
| 256 | 253 | { |
|---|
| .. | .. |
|---|
| 260 | 257 | rv = kstrtoll(s, base, &tmp); |
|---|
| 261 | 258 | if (rv < 0) |
|---|
| 262 | 259 | return rv; |
|---|
| 263 | | - if (tmp != (long long)(int)tmp) |
|---|
| 260 | + if (tmp != (int)tmp) |
|---|
| 264 | 261 | return -ERANGE; |
|---|
| 265 | 262 | *res = tmp; |
|---|
| 266 | 263 | return 0; |
|---|
| .. | .. |
|---|
| 275 | 272 | rv = kstrtoull(s, base, &tmp); |
|---|
| 276 | 273 | if (rv < 0) |
|---|
| 277 | 274 | return rv; |
|---|
| 278 | | - if (tmp != (unsigned long long)(u16)tmp) |
|---|
| 275 | + if (tmp != (u16)tmp) |
|---|
| 279 | 276 | return -ERANGE; |
|---|
| 280 | 277 | *res = tmp; |
|---|
| 281 | 278 | return 0; |
|---|
| .. | .. |
|---|
| 290 | 287 | rv = kstrtoll(s, base, &tmp); |
|---|
| 291 | 288 | if (rv < 0) |
|---|
| 292 | 289 | return rv; |
|---|
| 293 | | - if (tmp != (long long)(s16)tmp) |
|---|
| 290 | + if (tmp != (s16)tmp) |
|---|
| 294 | 291 | return -ERANGE; |
|---|
| 295 | 292 | *res = tmp; |
|---|
| 296 | 293 | return 0; |
|---|
| .. | .. |
|---|
| 305 | 302 | rv = kstrtoull(s, base, &tmp); |
|---|
| 306 | 303 | if (rv < 0) |
|---|
| 307 | 304 | return rv; |
|---|
| 308 | | - if (tmp != (unsigned long long)(u8)tmp) |
|---|
| 305 | + if (tmp != (u8)tmp) |
|---|
| 309 | 306 | return -ERANGE; |
|---|
| 310 | 307 | *res = tmp; |
|---|
| 311 | 308 | return 0; |
|---|
| .. | .. |
|---|
| 320 | 317 | rv = kstrtoll(s, base, &tmp); |
|---|
| 321 | 318 | if (rv < 0) |
|---|
| 322 | 319 | return rv; |
|---|
| 323 | | - if (tmp != (long long)(s8)tmp) |
|---|
| 320 | + if (tmp != (s8)tmp) |
|---|
| 324 | 321 | return -ERANGE; |
|---|
| 325 | 322 | *res = tmp; |
|---|
| 326 | 323 | return 0; |
|---|