Skip to content

Commit 93ad5bc

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc: rearrange args
Rearrange args for smaller code. lookup revolves around memcmp() which gets len 3rd arg, so propagate length as 3rd arg. readdir and lookup add additional arg to VFS ->readdir and ->lookup, so better add it to the end. Space savings on x86_64: add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18 (-18) Function old new delta proc_readdir 22 13 -9 proc_lookup 18 9 -9 proc_match() is smaller if not inlined, I promise! Link: http://lkml.kernel.org/r/20180104175958.GB5204@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 15b158b commit 93ad5bc

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎fs/proc/generic.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
static DEFINE_RWLOCK(proc_subdir_lock);
3030

31-
static int proc_match(unsigned int len, const char *name, struct proc_dir_entry *de)
31+
static int proc_match(const char *name, struct proc_dir_entry *de, unsigned int len)
3232
{
3333
if (len < de->namelen)
3434
return -1;
@@ -60,7 +60,7 @@ static struct proc_dir_entry *pde_subdir_find(struct proc_dir_entry *dir,
6060
struct proc_dir_entry *de = rb_entry(node,
6161
struct proc_dir_entry,
6262
subdir_node);
63-
int result = proc_match(len, name, de);
63+
int result = proc_match(name, de, len);
6464

6565
if (result < 0)
6666
node = node->rb_left;
@@ -84,7 +84,7 @@ static bool pde_subdir_insert(struct proc_dir_entry *dir,
8484
struct proc_dir_entry *this = rb_entry(*new,
8585
struct proc_dir_entry,
8686
subdir_node);
87-
int result = proc_match(de->namelen, de->name, this);
87+
int result = proc_match(de->name, this, de->namelen);
8888

8989
parent = *new;
9090
if (result < 0)
@@ -211,8 +211,8 @@ void proc_free_inum(unsigned int inum)
211211
* Don't create negative dentries here, return -ENOENT by hand
212212
* instead.
213213
*/
214-
struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir,
215-
struct dentry *dentry)
214+
struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry,
215+
struct proc_dir_entry *de)
216216
{
217217
struct inode *inode;
218218

@@ -235,7 +235,7 @@ struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir,
235235
struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
236236
unsigned int flags)
237237
{
238-
return proc_lookup_de(PDE(dir), dir, dentry);
238+
return proc_lookup_de(dir, dentry, PDE(dir));
239239
}
240240

241241
/*
@@ -247,8 +247,8 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
247247
* value of the readdir() call, as long as it's non-negative
248248
* for success..
249249
*/
250-
int proc_readdir_de(struct proc_dir_entry *de, struct file *file,
251-
struct dir_context *ctx)
250+
int proc_readdir_de(struct file *file, struct dir_context *ctx,
251+
struct proc_dir_entry *de)
252252
{
253253
int i;
254254

@@ -292,7 +292,7 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
292292
{
293293
struct inode *inode = file_inode(file);
294294

295-
return proc_readdir_de(PDE(inode), file, ctx);
295+
return proc_readdir_de(file, ctx, PDE(inode));
296296
}
297297

298298
/*

‎fs/proc/internal.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
153153
* generic.c
154154
*/
155155
extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
156-
extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
157-
struct dentry *);
156+
struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *);
158157
extern int proc_readdir(struct file *, struct dir_context *);
159-
extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
158+
int proc_readdir_de(struct file *, struct dir_context *, struct proc_dir_entry *);
160159

161160
static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
162161
{

‎fs/proc/proc_net.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static struct dentry *proc_tgid_net_lookup(struct inode *dir,
135135
de = ERR_PTR(-ENOENT);
136136
net = get_proc_task_net(dir);
137137
if (net != NULL) {
138-
de = proc_lookup_de(net->proc_net, dir, dentry);
138+
de = proc_lookup_de(dir, dentry, net->proc_net);
139139
put_net(net);
140140
}
141141
return de;
@@ -172,7 +172,7 @@ static int proc_tgid_net_readdir(struct file *file, struct dir_context *ctx)
172172
ret = -EINVAL;
173173
net = get_proc_task_net(file_inode(file));
174174
if (net != NULL) {
175-
ret = proc_readdir_de(net->proc_net, file, ctx);
175+
ret = proc_readdir_de(file, ctx, net->proc_net);
176176
put_net(net);
177177
}
178178
return ret;

0 commit comments

Comments
 (0)