blob: 98f8adc17345311c25a18708079d554e833e894c [file] [log] [blame]
Alexey Dobriyan3ee2a192017-11-17 15:26:49 -08001#include <linux/dcache.h>
Eric Biggers81966d832019-01-03 15:26:00 -08002#include "internal.h"
Alexey Dobriyan3ee2a192017-11-17 15:26:49 -08003
4unsigned name_to_int(const struct qstr *qstr)
5{
6 const char *name = qstr->name;
7 int len = qstr->len;
8 unsigned n = 0;
9
10 if (len > 1 && *name == '0')
11 goto out;
Alexey Dobriyan0746a0b2017-11-17 15:26:52 -080012 do {
Alexey Dobriyan3ee2a192017-11-17 15:26:49 -080013 unsigned c = *name++ - '0';
14 if (c > 9)
15 goto out;
16 if (n >= (~0U-9)/10)
17 goto out;
18 n *= 10;
19 n += c;
Alexey Dobriyan0746a0b2017-11-17 15:26:52 -080020 } while (--len > 0);
Alexey Dobriyan3ee2a192017-11-17 15:26:49 -080021 return n;
22out:
23 return ~0U;
24}