Skip to content

Commit 27787ba

Browse files
committed
Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull misc vfs updates from Al Viro: "Assorted stuff all over the place" * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: useful constants: struct qstr for ".." hostfs_open(): don't open-code file_dentry() whack-a-mole: kill strlen_user() (again) autofs: should_expire() argument is guaranteed to be positive apparmor:match_mn() - constify devpath argument buffer: a small optimization in grow_buffers get rid of autofs_getpath() constify dentry argument of dentry_path()/dentry_path_raw()
2 parents b28866f + 80e5d1f commit 27787ba

File tree

22 files changed

+41
-95
lines changed

22 files changed

+41
-95
lines changed

arch/csky/include/asm/uaccess.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,6 @@ long __strncpy_from_user(char *dst, const char *src, long count);
397397
*/
398398
long strnlen_user(const char *src, long n);
399399

400-
#define strlen_user(str) strnlen_user(str, 32767)
401-
402400
struct exception_table_entry {
403401
unsigned long insn;
404402
unsigned long nextinsn;

arch/csky/lib/usercopy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ long strncpy_from_user(char *dst, const char *src, long count)
116116
EXPORT_SYMBOL(strncpy_from_user);
117117

118118
/*
119-
* strlen_user: - Get the size of a string in user space.
119+
* strnlen_user: - Get the size of a string in user space.
120120
* @str: The string to measure.
121121
* @n: The maximum valid length
122122
*

arch/nds32/include/asm/uaccess.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ do { \
260260

261261
extern unsigned long __arch_clear_user(void __user * addr, unsigned long n);
262262
extern long strncpy_from_user(char *dest, const char __user * src, long count);
263-
extern __must_check long strlen_user(const char __user * str);
264263
extern __must_check long strnlen_user(const char __user * str, long n);
265264
extern unsigned long __arch_copy_from_user(void *to, const void __user * from,
266265
unsigned long n);

arch/nios2/include/asm/uaccess.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n);
8383

8484
extern long strncpy_from_user(char *__to, const char __user *__from,
8585
long __len);
86-
extern __must_check long strlen_user(const char __user *str);
8786
extern __must_check long strnlen_user(const char __user *s, long n);
8887

8988
/* Optimized macros */

arch/riscv/include/asm/uaccess.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
375375

376376
extern long strncpy_from_user(char *dest, const char __user *src, long count);
377377

378-
extern long __must_check strlen_user(const char __user *str);
379378
extern long __must_check strnlen_user(const char __user *str, long n);
380379

381380
extern

fs/autofs/autofs_i.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct autofs_wait_queue {
8787
autofs_wqt_t wait_queue_token;
8888
/* We use the following to see what we are waiting for */
8989
struct qstr name;
90+
u32 offset;
9091
u32 dev;
9192
u64 ino;
9293
kuid_t uid;

fs/autofs/expire.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static struct dentry *should_expire(struct dentry *dentry,
355355
return NULL;
356356
}
357357

358-
if (d_really_is_positive(dentry) && d_is_symlink(dentry)) {
358+
if (d_is_symlink(dentry)) {
359359
pr_debug("checking symlink %p %pd\n", dentry, dentry);
360360

361361
/* Forced expire, user space handles busy mounts */

fs/autofs/waitq.c

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void autofs_catatonic_mode(struct autofs_sb_info *sbi)
3030
while (wq) {
3131
nwq = wq->next;
3232
wq->status = -ENOENT; /* Magic is gone - report failure */
33-
kfree(wq->name.name);
33+
kfree(wq->name.name - wq->offset);
3434
wq->name.name = NULL;
3535
wq->wait_ctr--;
3636
wake_up_interruptible(&wq->queue);
@@ -175,51 +175,6 @@ static void autofs_notify_daemon(struct autofs_sb_info *sbi,
175175
fput(pipe);
176176
}
177177

178-
static int autofs_getpath(struct autofs_sb_info *sbi,
179-
struct dentry *dentry, char *name)
180-
{
181-
struct dentry *root = sbi->sb->s_root;
182-
struct dentry *tmp;
183-
char *buf;
184-
char *p;
185-
int len;
186-
unsigned seq;
187-
188-
rename_retry:
189-
buf = name;
190-
len = 0;
191-
192-
seq = read_seqbegin(&rename_lock);
193-
rcu_read_lock();
194-
spin_lock(&sbi->fs_lock);
195-
for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
196-
len += tmp->d_name.len + 1;
197-
198-
if (!len || --len > NAME_MAX) {
199-
spin_unlock(&sbi->fs_lock);
200-
rcu_read_unlock();
201-
if (read_seqretry(&rename_lock, seq))
202-
goto rename_retry;
203-
return 0;
204-
}
205-
206-
*(buf + len) = '\0';
207-
p = buf + len - dentry->d_name.len;
208-
strncpy(p, dentry->d_name.name, dentry->d_name.len);
209-
210-
for (tmp = dentry->d_parent; tmp != root ; tmp = tmp->d_parent) {
211-
*(--p) = '/';
212-
p -= tmp->d_name.len;
213-
strncpy(p, tmp->d_name.name, tmp->d_name.len);
214-
}
215-
spin_unlock(&sbi->fs_lock);
216-
rcu_read_unlock();
217-
if (read_seqretry(&rename_lock, seq))
218-
goto rename_retry;
219-
220-
return len;
221-
}
222-
223178
static struct autofs_wait_queue *
224179
autofs_find_wait(struct autofs_sb_info *sbi, const struct qstr *qstr)
225180
{
@@ -352,6 +307,7 @@ int autofs_wait(struct autofs_sb_info *sbi,
352307
struct qstr qstr;
353308
char *name;
354309
int status, ret, type;
310+
unsigned int offset = 0;
355311
pid_t pid;
356312
pid_t tgid;
357313

@@ -389,36 +345,39 @@ int autofs_wait(struct autofs_sb_info *sbi,
389345
return -ENOMEM;
390346

391347
/* If this is a direct mount request create a dummy name */
392-
if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
348+
if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type)) {
349+
qstr.name = name;
393350
qstr.len = sprintf(name, "%p", dentry);
394-
else {
395-
qstr.len = autofs_getpath(sbi, dentry, name);
396-
if (!qstr.len) {
351+
} else {
352+
char *p = dentry_path_raw(dentry, name, NAME_MAX);
353+
if (IS_ERR(p)) {
397354
kfree(name);
398355
return -ENOENT;
399356
}
357+
qstr.name = ++p; // skip the leading slash
358+
qstr.len = strlen(p);
359+
offset = p - name;
400360
}
401-
qstr.name = name;
402361
qstr.hash = full_name_hash(dentry, name, qstr.len);
403362

404363
if (mutex_lock_interruptible(&sbi->wq_mutex)) {
405-
kfree(qstr.name);
364+
kfree(name);
406365
return -EINTR;
407366
}
408367

409368
ret = validate_request(&wq, sbi, &qstr, path, notify);
410369
if (ret <= 0) {
411370
if (ret != -EINTR)
412371
mutex_unlock(&sbi->wq_mutex);
413-
kfree(qstr.name);
372+
kfree(name);
414373
return ret;
415374
}
416375

417376
if (!wq) {
418377
/* Create a new wait queue */
419378
wq = kmalloc(sizeof(struct autofs_wait_queue), GFP_KERNEL);
420379
if (!wq) {
421-
kfree(qstr.name);
380+
kfree(name);
422381
mutex_unlock(&sbi->wq_mutex);
423382
return -ENOMEM;
424383
}
@@ -430,6 +389,7 @@ int autofs_wait(struct autofs_sb_info *sbi,
430389
sbi->queues = wq;
431390
init_waitqueue_head(&wq->queue);
432391
memcpy(&wq->name, &qstr, sizeof(struct qstr));
392+
wq->offset = offset;
433393
wq->dev = autofs_get_dev(sbi);
434394
wq->ino = autofs_get_ino(sbi);
435395
wq->uid = current_uid();
@@ -469,7 +429,7 @@ int autofs_wait(struct autofs_sb_info *sbi,
469429
(unsigned long) wq->wait_queue_token, wq->name.len,
470430
wq->name.name, notify);
471431
mutex_unlock(&sbi->wq_mutex);
472-
kfree(qstr.name);
432+
kfree(name);
473433
}
474434

475435
/*
@@ -540,7 +500,7 @@ int autofs_wait_release(struct autofs_sb_info *sbi,
540500
}
541501

542502
*wql = wq->next; /* Unlink from chain */
543-
kfree(wq->name.name);
503+
kfree(wq->name.name - wq->offset);
544504
wq->name.name = NULL; /* Do not wait on this queue */
545505
wq->status = status;
546506
wake_up(&wq->queue);

fs/buffer.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,11 +1020,7 @@ grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp)
10201020
pgoff_t index;
10211021
int sizebits;
10221022

1023-
sizebits = -1;
1024-
do {
1025-
sizebits++;
1026-
} while ((size << sizebits) < PAGE_SIZE);
1027-
1023+
sizebits = PAGE_SHIFT - __ffs(size);
10281024
index = block >> sizebits;
10291025

10301026
/*

fs/d_path.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ char *simple_dname(struct dentry *dentry, char *buffer, int buflen)
326326
/*
327327
* Write full pathname from the root of the filesystem into the buffer.
328328
*/
329-
static char *__dentry_path(struct dentry *d, char *buf, int buflen)
329+
static char *__dentry_path(const struct dentry *d, char *buf, int buflen)
330330
{
331-
struct dentry *dentry;
331+
const struct dentry *dentry;
332332
char *end, *retval;
333333
int len, seq = 0;
334334
int error = 0;
@@ -347,7 +347,7 @@ static char *__dentry_path(struct dentry *d, char *buf, int buflen)
347347
*retval = '/';
348348
read_seqbegin_or_lock(&rename_lock, &seq);
349349
while (!IS_ROOT(dentry)) {
350-
struct dentry *parent = dentry->d_parent;
350+
const struct dentry *parent = dentry->d_parent;
351351

352352
prefetch(parent);
353353
error = prepend_name(&end, &len, &dentry->d_name);
@@ -371,13 +371,13 @@ static char *__dentry_path(struct dentry *d, char *buf, int buflen)
371371
return ERR_PTR(-ENAMETOOLONG);
372372
}
373373

374-
char *dentry_path_raw(struct dentry *dentry, char *buf, int buflen)
374+
char *dentry_path_raw(const struct dentry *dentry, char *buf, int buflen)
375375
{
376376
return __dentry_path(dentry, buf, buflen);
377377
}
378378
EXPORT_SYMBOL(dentry_path_raw);
379379

380-
char *dentry_path(struct dentry *dentry, char *buf, int buflen)
380+
char *dentry_path(const struct dentry *dentry, char *buf, int buflen)
381381
{
382382
char *p = NULL;
383383
char *retval;

0 commit comments

Comments
 (0)