Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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()

+41 -95
-2
arch/csky/include/asm/uaccess.h
··· 397 397 */ 398 398 long strnlen_user(const char *src, long n); 399 399 400 - #define strlen_user(str) strnlen_user(str, 32767) 401 - 402 400 struct exception_table_entry { 403 401 unsigned long insn; 404 402 unsigned long nextinsn;
+1 -1
arch/csky/lib/usercopy.c
··· 116 116 EXPORT_SYMBOL(strncpy_from_user); 117 117 118 118 /* 119 - * strlen_user: - Get the size of a string in user space. 119 + * strnlen_user: - Get the size of a string in user space. 120 120 * @str: The string to measure. 121 121 * @n: The maximum valid length 122 122 *
-1
arch/nds32/include/asm/uaccess.h
··· 260 260 261 261 extern unsigned long __arch_clear_user(void __user * addr, unsigned long n); 262 262 extern long strncpy_from_user(char *dest, const char __user * src, long count); 263 - extern __must_check long strlen_user(const char __user * str); 264 263 extern __must_check long strnlen_user(const char __user * str, long n); 265 264 extern unsigned long __arch_copy_from_user(void *to, const void __user * from, 266 265 unsigned long n);
-1
arch/nios2/include/asm/uaccess.h
··· 83 83 84 84 extern long strncpy_from_user(char *__to, const char __user *__from, 85 85 long __len); 86 - extern __must_check long strlen_user(const char __user *str); 87 86 extern __must_check long strnlen_user(const char __user *s, long n); 88 87 89 88 /* Optimized macros */
-1
arch/riscv/include/asm/uaccess.h
··· 375 375 376 376 extern long strncpy_from_user(char *dest, const char __user *src, long count); 377 377 378 - extern long __must_check strlen_user(const char __user *str); 379 378 extern long __must_check strnlen_user(const char __user *str, long n); 380 379 381 380 extern
+1
fs/autofs/autofs_i.h
··· 87 87 autofs_wqt_t wait_queue_token; 88 88 /* We use the following to see what we are waiting for */ 89 89 struct qstr name; 90 + u32 offset; 90 91 u32 dev; 91 92 u64 ino; 92 93 kuid_t uid;
+1 -1
fs/autofs/expire.c
··· 355 355 return NULL; 356 356 } 357 357 358 - if (d_really_is_positive(dentry) && d_is_symlink(dentry)) { 358 + if (d_is_symlink(dentry)) { 359 359 pr_debug("checking symlink %p %pd\n", dentry, dentry); 360 360 361 361 /* Forced expire, user space handles busy mounts */
+16 -56
fs/autofs/waitq.c
··· 30 30 while (wq) { 31 31 nwq = wq->next; 32 32 wq->status = -ENOENT; /* Magic is gone - report failure */ 33 - kfree(wq->name.name); 33 + kfree(wq->name.name - wq->offset); 34 34 wq->name.name = NULL; 35 35 wq->wait_ctr--; 36 36 wake_up_interruptible(&wq->queue); ··· 175 175 fput(pipe); 176 176 } 177 177 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 - 223 178 static struct autofs_wait_queue * 224 179 autofs_find_wait(struct autofs_sb_info *sbi, const struct qstr *qstr) 225 180 { ··· 307 352 struct qstr qstr; 308 353 char *name; 309 354 int status, ret, type; 355 + unsigned int offset = 0; 310 356 pid_t pid; 311 357 pid_t tgid; 312 358 ··· 345 389 return -ENOMEM; 346 390 347 391 /* If this is a direct mount request create a dummy name */ 348 - if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type)) 392 + if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type)) { 393 + qstr.name = name; 349 394 qstr.len = sprintf(name, "%p", dentry); 350 - else { 351 - qstr.len = autofs_getpath(sbi, dentry, name); 352 - if (!qstr.len) { 395 + } else { 396 + char *p = dentry_path_raw(dentry, name, NAME_MAX); 397 + if (IS_ERR(p)) { 353 398 kfree(name); 354 399 return -ENOENT; 355 400 } 401 + qstr.name = ++p; // skip the leading slash 402 + qstr.len = strlen(p); 403 + offset = p - name; 356 404 } 357 - qstr.name = name; 358 405 qstr.hash = full_name_hash(dentry, name, qstr.len); 359 406 360 407 if (mutex_lock_interruptible(&sbi->wq_mutex)) { 361 - kfree(qstr.name); 408 + kfree(name); 362 409 return -EINTR; 363 410 } 364 411 ··· 369 410 if (ret <= 0) { 370 411 if (ret != -EINTR) 371 412 mutex_unlock(&sbi->wq_mutex); 372 - kfree(qstr.name); 413 + kfree(name); 373 414 return ret; 374 415 } 375 416 ··· 377 418 /* Create a new wait queue */ 378 419 wq = kmalloc(sizeof(struct autofs_wait_queue), GFP_KERNEL); 379 420 if (!wq) { 380 - kfree(qstr.name); 421 + kfree(name); 381 422 mutex_unlock(&sbi->wq_mutex); 382 423 return -ENOMEM; 383 424 } ··· 389 430 sbi->queues = wq; 390 431 init_waitqueue_head(&wq->queue); 391 432 memcpy(&wq->name, &qstr, sizeof(struct qstr)); 433 + wq->offset = offset; 392 434 wq->dev = autofs_get_dev(sbi); 393 435 wq->ino = autofs_get_ino(sbi); 394 436 wq->uid = current_uid(); ··· 429 469 (unsigned long) wq->wait_queue_token, wq->name.len, 430 470 wq->name.name, notify); 431 471 mutex_unlock(&sbi->wq_mutex); 432 - kfree(qstr.name); 472 + kfree(name); 433 473 } 434 474 435 475 /* ··· 500 540 } 501 541 502 542 *wql = wq->next; /* Unlink from chain */ 503 - kfree(wq->name.name); 543 + kfree(wq->name.name - wq->offset); 504 544 wq->name.name = NULL; /* Do not wait on this queue */ 505 545 wq->status = status; 506 546 wake_up(&wq->queue);
+1 -5
fs/buffer.c
··· 1020 1020 pgoff_t index; 1021 1021 int sizebits; 1022 1022 1023 - sizebits = -1; 1024 - do { 1025 - sizebits++; 1026 - } while ((size << sizebits) < PAGE_SIZE); 1027 - 1023 + sizebits = PAGE_SHIFT - __ffs(size); 1028 1024 index = block >> sizebits; 1029 1025 1030 1026 /*
+5 -5
fs/d_path.c
··· 326 326 /* 327 327 * Write full pathname from the root of the filesystem into the buffer. 328 328 */ 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) 330 330 { 331 - struct dentry *dentry; 331 + const struct dentry *dentry; 332 332 char *end, *retval; 333 333 int len, seq = 0; 334 334 int error = 0; ··· 347 347 *retval = '/'; 348 348 read_seqbegin_or_lock(&rename_lock, &seq); 349 349 while (!IS_ROOT(dentry)) { 350 - struct dentry *parent = dentry->d_parent; 350 + const struct dentry *parent = dentry->d_parent; 351 351 352 352 prefetch(parent); 353 353 error = prepend_name(&end, &len, &dentry->d_name); ··· 371 371 return ERR_PTR(-ENAMETOOLONG); 372 372 } 373 373 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) 375 375 { 376 376 return __dentry_path(dentry, buf, buflen); 377 377 } 378 378 EXPORT_SYMBOL(dentry_path_raw); 379 379 380 - char *dentry_path(struct dentry *dentry, char *buf, int buflen) 380 + char *dentry_path(const struct dentry *dentry, char *buf, int buflen) 381 381 { 382 382 char *p = NULL; 383 383 char *retval;
+2
fs/dcache.c
··· 84 84 EXPORT_SYMBOL(empty_name); 85 85 const struct qstr slash_name = QSTR_INIT("/", 1); 86 86 EXPORT_SYMBOL(slash_name); 87 + const struct qstr dotdot_name = QSTR_INIT("..", 2); 88 + EXPORT_SYMBOL(dotdot_name); 87 89 88 90 /* 89 91 * This is the single most critical data structure when it comes
+1 -2
fs/ext2/namei.c
··· 81 81 82 82 struct dentry *ext2_get_parent(struct dentry *child) 83 83 { 84 - struct qstr dotdot = QSTR_INIT("..", 2); 85 84 ino_t ino; 86 85 int res; 87 86 88 - res = ext2_inode_by_name(d_inode(child), &dotdot, &ino); 87 + res = ext2_inode_by_name(d_inode(child), &dotdot_name, &ino); 89 88 if (res) 90 89 return ERR_PTR(res); 91 90
+1 -2
fs/ext4/namei.c
··· 1814 1814 struct dentry *ext4_get_parent(struct dentry *child) 1815 1815 { 1816 1816 __u32 ino; 1817 - static const struct qstr dotdot = QSTR_INIT("..", 2); 1818 1817 struct ext4_dir_entry_2 * de; 1819 1818 struct buffer_head *bh; 1820 1819 1821 - bh = ext4_find_entry(d_inode(child), &dotdot, &de, NULL); 1820 + bh = ext4_find_entry(d_inode(child), &dotdot_name, &de, NULL); 1822 1821 if (IS_ERR(bh)) 1823 1822 return ERR_CAST(bh); 1824 1823 if (!bh)
+1 -3
fs/f2fs/dir.c
··· 449 449 450 450 struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p) 451 451 { 452 - struct qstr dotdot = QSTR_INIT("..", 2); 453 - 454 - return f2fs_find_entry(dir, &dotdot, p); 452 + return f2fs_find_entry(dir, &dotdot_name, p); 455 453 } 456 454 457 455 ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
+1 -2
fs/f2fs/namei.c
··· 416 416 417 417 struct dentry *f2fs_get_parent(struct dentry *child) 418 418 { 419 - struct qstr dotdot = QSTR_INIT("..", 2); 420 419 struct page *page; 421 - unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page); 420 + unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot_name, &page); 422 421 if (!ino) { 423 422 if (IS_ERR(page)) 424 423 return ERR_CAST(page);
+1 -2
fs/fuse/inode.c
··· 873 873 struct inode *inode; 874 874 struct dentry *parent; 875 875 struct fuse_entry_out outarg; 876 - const struct qstr name = QSTR_INIT("..", 2); 877 876 int err; 878 877 879 878 if (!fc->export_support) 880 879 return ERR_PTR(-ESTALE); 881 880 882 881 err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode), 883 - &name, &outarg, &inode); 882 + &dotdot_name, &outarg, &inode); 884 883 if (err) { 885 884 if (err == -ENOENT) 886 885 return ERR_PTR(-ESTALE);
+1 -1
fs/hostfs/hostfs_kern.c
··· 316 316 if (mode & FMODE_WRITE) 317 317 r = w = 1; 318 318 319 - name = dentry_name(d_real(file->f_path.dentry, file->f_inode)); 319 + name = dentry_name(file_dentry(file)); 320 320 if (name == NULL) 321 321 return -ENOMEM; 322 322
+1 -2
fs/nilfs2/namei.c
··· 440 440 { 441 441 unsigned long ino; 442 442 struct inode *inode; 443 - struct qstr dotdot = QSTR_INIT("..", 2); 444 443 struct nilfs_root *root; 445 444 446 - ino = nilfs_inode_by_name(d_inode(child), &dotdot); 445 + ino = nilfs_inode_by_name(d_inode(child), &dotdot_name); 447 446 if (!ino) 448 447 return ERR_PTR(-ENOENT); 449 448
+1 -2
fs/udf/namei.c
··· 1215 1215 { 1216 1216 struct kernel_lb_addr tloc; 1217 1217 struct inode *inode = NULL; 1218 - struct qstr dotdot = QSTR_INIT("..", 2); 1219 1218 struct fileIdentDesc cfi; 1220 1219 struct udf_fileident_bh fibh; 1221 1220 1222 - if (!udf_find_entry(d_inode(child), &dotdot, &fibh, &cfi)) 1221 + if (!udf_find_entry(d_inode(child), &dotdot_name, &fibh, &cfi)) 1223 1222 return ERR_PTR(-EACCES); 1224 1223 1225 1224 if (fibh.sbh != fibh.ebh)
+1 -2
fs/ufs/super.c
··· 128 128 129 129 static struct dentry *ufs_get_parent(struct dentry *child) 130 130 { 131 - struct qstr dot_dot = QSTR_INIT("..", 2); 132 131 ino_t ino; 133 132 134 - ino = ufs_inode_by_name(d_inode(child), &dot_dot); 133 + ino = ufs_inode_by_name(d_inode(child), &dotdot_name); 135 134 if (!ino) 136 135 return ERR_PTR(-ENOENT); 137 136 return d_obtain_alias(ufs_iget(child->d_sb, ino));
+3 -2
include/linux/dcache.h
··· 59 59 60 60 extern const struct qstr empty_name; 61 61 extern const struct qstr slash_name; 62 + extern const struct qstr dotdot_name; 62 63 63 64 struct dentry_stat_t { 64 65 long nr_dentry; ··· 301 300 extern char *__d_path(const struct path *, const struct path *, char *, int); 302 301 extern char *d_absolute_path(const struct path *, char *, int); 303 302 extern char *d_path(const struct path *, char *, int); 304 - extern char *dentry_path_raw(struct dentry *, char *, int); 305 - extern char *dentry_path(struct dentry *, char *, int); 303 + extern char *dentry_path_raw(const struct dentry *, char *, int); 304 + extern char *dentry_path(const struct dentry *, char *, int); 306 305 307 306 /* Allocation counts.. */ 308 307
+2 -2
security/apparmor/mount.c
··· 370 370 * Returns: 0 on success else error 371 371 */ 372 372 static int match_mnt(struct aa_profile *profile, const struct path *path, 373 - char *buffer, struct path *devpath, char *devbuffer, 373 + char *buffer, const struct path *devpath, char *devbuffer, 374 374 const char *type, unsigned long flags, void *data, 375 375 bool binary) 376 376 { ··· 579 579 return error; 580 580 } 581 581 582 - static int profile_umount(struct aa_profile *profile, struct path *path, 582 + static int profile_umount(struct aa_profile *profile, const struct path *path, 583 583 char *buffer) 584 584 { 585 585 struct aa_perms perms = { };