aboutsummaryrefslogtreecommitdiffstats
path: root/net/socket.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-13 22:58:36 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-13 22:58:36 -0400
commita66b4cd1e7163adb327838a3c81faaf6a9330d5a (patch)
tree2b123a010bb0f1566ff6f34e529f01ddf10ee308 /net/socket.c
parentb16528466786a540cb00148acb124e0149d62710 (diff)
parent5f336e722cc961be94d264d96b90c92888fffae1 (diff)
Merge branch 'work.open3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs open-related updates from Al Viro: - "do we need fput() or put_filp()" rules are gone - it's always fput() now. We keep track of that state where it belongs - in ->f_mode. - int *opened mess killed - in finish_open(), in ->atomic_open() instances and in fs/namei.c code around do_last()/lookup_open()/atomic_open(). - alloc_file() wrappers with saner calling conventions are introduced (alloc_file_clone() and alloc_file_pseudo()); callers converted, with much simplification. - while we are at it, saner calling conventions for path_init() and link_path_walk(), simplifying things inside fs/namei.c (both on open-related paths and elsewhere). * 'work.open3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (40 commits) few more cleanups of link_path_walk() callers allow link_path_walk() to take ERR_PTR() make path_init() unconditionally paired with terminate_walk() document alloc_file() changes make alloc_file() static do_shmat(): grab shp->shm_file earlier, switch to alloc_file_clone() new helper: alloc_file_clone() create_pipe_files(): switch the first allocation to alloc_file_pseudo() anon_inode_getfile(): switch to alloc_file_pseudo() hugetlb_file_setup(): switch to alloc_file_pseudo() ocxlflash_getfile(): switch to alloc_file_pseudo() cxl_getfile(): switch to alloc_file_pseudo() ... and switch shmem_file_setup() to alloc_file_pseudo() __shmem_file_setup(): reorder allocations new wrapper: alloc_file_pseudo() kill FILE_{CREATED,OPENED} switch atomic_open() and lookup_open() to returning 0 in all success cases document ->atomic_open() changes ->atomic_open(): return 0 in all success cases get rid of 'opened' in path_openat() and the helpers downstream ...
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c29
1 files changed, 5 insertions, 24 deletions
diff --git a/net/socket.c b/net/socket.c
index 8c24d5dc4bc8..792f0313ea91 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -388,39 +388,20 @@ static struct file_system_type sock_fs_type = {
388 388
389struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) 389struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname)
390{ 390{
391 struct qstr name = { .name = "" };
392 struct path path;
393 struct file *file; 391 struct file *file;
394 392
395 if (dname) { 393 if (!dname)
396 name.name = dname; 394 dname = sock->sk ? sock->sk->sk_prot_creator->name : "";
397 name.len = strlen(name.name);
398 } else if (sock->sk) {
399 name.name = sock->sk->sk_prot_creator->name;
400 name.len = strlen(name.name);
401 }
402 path.dentry = d_alloc_pseudo(sock_mnt->mnt_sb, &name);
403 if (unlikely(!path.dentry)) {
404 sock_release(sock);
405 return ERR_PTR(-ENOMEM);
406 }
407 path.mnt = mntget(sock_mnt);
408
409 d_instantiate(path.dentry, SOCK_INODE(sock));
410 395
411 file = alloc_file(&path, FMODE_READ | FMODE_WRITE, 396 file = alloc_file_pseudo(SOCK_INODE(sock), sock_mnt, dname,
412 &socket_file_ops); 397 O_RDWR | (flags & O_NONBLOCK),
398 &socket_file_ops);
413 if (IS_ERR(file)) { 399 if (IS_ERR(file)) {
414 /* drop dentry, keep inode for a bit */
415 ihold(d_inode(path.dentry));
416 path_put(&path);
417 /* ... and now kill it properly */
418 sock_release(sock); 400 sock_release(sock);
419 return file; 401 return file;
420 } 402 }
421 403
422 sock->file = file; 404 sock->file = file;
423 file->f_flags = O_RDWR | (flags & O_NONBLOCK);
424 file->private_data = sock; 405 file->private_data = sock;
425 return file; 406 return file;
426} 407}