Skip to content

Commit 3ee2a19

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc: : uninline name_to_int()
Save ~360 bytes. add/remove: 1/0 grow/shrink: 0/4 up/down: 104/-463 (-359) function old new delta name_to_int - 104 +104 proc_pid_lookup 217 126 -91 proc_lookupfd_common 212 121 -91 proc_task_lookup 289 194 -95 __proc_create 588 402 -186 Link: http://lkml.kernel.org/r/20170912194850.GA17730@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c643401 commit 3ee2a19

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

‎fs/proc/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ proc-y += loadavg.o
2121
proc-y += meminfo.o
2222
proc-y += stat.o
2323
proc-y += uptime.o
24+
proc-y += util.o
2425
proc-y += version.o
2526
proc-y += softirqs.o
2627
proc-y += namespaces.o

‎fs/proc/internal.h‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,7 @@ static inline struct task_struct *get_proc_task(struct inode *inode)
103103
void task_dump_owner(struct task_struct *task, mode_t mode,
104104
kuid_t *ruid, kgid_t *rgid);
105105

106-
static inline unsigned name_to_int(const struct qstr *qstr)
107-
{
108-
const char *name = qstr->name;
109-
int len = qstr->len;
110-
unsigned n = 0;
111-
112-
if (len > 1 && *name == '0')
113-
goto out;
114-
while (len-- > 0) {
115-
unsigned c = *name++ - '0';
116-
if (c > 9)
117-
goto out;
118-
if (n >= (~0U-9)/10)
119-
goto out;
120-
n *= 10;
121-
n += c;
122-
}
123-
return n;
124-
out:
125-
return ~0U;
126-
}
127-
106+
unsigned name_to_int(const struct qstr *qstr);
128107
/*
129108
* Offset of the first process in the /proc root directory..
130109
*/

‎fs/proc/util.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <linux/dcache.h>
2+
3+
unsigned name_to_int(const struct qstr *qstr)
4+
{
5+
const char *name = qstr->name;
6+
int len = qstr->len;
7+
unsigned n = 0;
8+
9+
if (len > 1 && *name == '0')
10+
goto out;
11+
while (len-- > 0) {
12+
unsigned c = *name++ - '0';
13+
if (c > 9)
14+
goto out;
15+
if (n >= (~0U-9)/10)
16+
goto out;
17+
n *= 10;
18+
n += c;
19+
}
20+
return n;
21+
out:
22+
return ~0U;
23+
}

0 commit comments

Comments
 (0)