[AVR32] Optimize the TLB miss handler
[pandora-kernel.git] / net / socket.c
index 4e39631..ea8f81a 100644 (file)
@@ -117,7 +117,7 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,
  *     in the operation structures but are done directly via the socketcall() multiplexor.
  */
 
-static struct file_operations socket_file_ops = {
+static const struct file_operations socket_file_ops = {
        .owner =        THIS_MODULE,
        .llseek =       no_llseek,
        .aio_read =     sock_aio_read,
@@ -407,24 +407,11 @@ int sock_map_fd(struct socket *sock)
 
 static struct socket *sock_from_file(struct file *file, int *err)
 {
-       struct inode *inode;
-       struct socket *sock;
-
        if (file->f_op == &socket_file_ops)
                return file->private_data;      /* set in sock_map_fd */
 
-       inode = file->f_path.dentry->d_inode;
-       if (!S_ISSOCK(inode->i_mode)) {
-               *err = -ENOTSOCK;
-               return NULL;
-       }
-
-       sock = SOCKET_I(inode);
-       if (sock->file != file) {
-               printk(KERN_ERR "socki_lookup: socket file changed!\n");
-               sock->file = file;
-       }
-       return sock;
+       *err = -ENOTSOCK;
+       return NULL;
 }
 
 /**
@@ -1207,6 +1194,7 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
 {
        struct socket *sock1, *sock2;
        int fd1, fd2, err;
+       struct file *newfile1, *newfile2;
 
        /*
         * Obtain the first socket and check if the underlying protocol
@@ -1225,18 +1213,37 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
        if (err < 0)
                goto out_release_both;
 
-       fd1 = fd2 = -1;
+       fd1 = sock_alloc_fd(&newfile1);
+       if (unlikely(fd1 < 0))
+               goto out_release_both;
 
-       err = sock_map_fd(sock1);
-       if (err < 0)
+       fd2 = sock_alloc_fd(&newfile2);
+       if (unlikely(fd2 < 0)) {
+               put_filp(newfile1);
+               put_unused_fd(fd1);
                goto out_release_both;
-       fd1 = err;
+       }
 
-       err = sock_map_fd(sock2);
-       if (err < 0)
-               goto out_close_1;
-       fd2 = err;
+       err = sock_attach_fd(sock1, newfile1);
+       if (unlikely(err < 0)) {
+               goto out_fd2;
+       }
+
+       err = sock_attach_fd(sock2, newfile2);
+       if (unlikely(err < 0)) {
+               fput(newfile1);
+               goto out_fd1;
+       }
+
+       err = audit_fd_pair(fd1, fd2);
+       if (err < 0) {
+               fput(newfile1);
+               fput(newfile2);
+               goto out_fd;
+       }
 
+       fd_install(fd1, newfile1);
+       fd_install(fd2, newfile2);
        /* fd1 and fd2 may be already another descriptors.
         * Not kernel problem.
         */
@@ -1251,17 +1258,23 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
        sys_close(fd1);
        return err;
 
-out_close_1:
-       sock_release(sock2);
-       sys_close(fd1);
-       return err;
-
 out_release_both:
        sock_release(sock2);
 out_release_1:
        sock_release(sock1);
 out:
        return err;
+
+out_fd2:
+       put_filp(newfile1);
+       sock_release(sock1);
+out_fd1:
+       put_filp(newfile2);
+       sock_release(sock2);
+out_fd:
+       put_unused_fd(fd1);
+       put_unused_fd(fd2);
+       goto out;
 }
 
 /*
@@ -1368,7 +1381,7 @@ asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr,
 
        err = sock_attach_fd(newsock, newfile);
        if (err < 0)
-               goto out_fd;
+               goto out_fd_simple;
 
        err = security_socket_accept(sock, newsock);
        if (err)
@@ -1401,6 +1414,11 @@ out_put:
        fput_light(sock->file, fput_needed);
 out:
        return err;
+out_fd_simple:
+       sock_release(newsock);
+       put_filp(newfile);
+       put_unused_fd(newfd);
+       goto out_put;
 out_fd:
        fput(newfile);
        put_unused_fd(newfd);
@@ -1527,8 +1545,9 @@ asmlinkage long sys_sendto(int fd, void __user *buff, size_t len,
        struct file *sock_file;
 
        sock_file = fget_light(fd, &fput_needed);
+       err = -EBADF;
        if (!sock_file)
-               return -EBADF;
+               goto out;
 
        sock = sock_from_file(sock_file, &err);
        if (!sock)
@@ -1555,6 +1574,7 @@ asmlinkage long sys_sendto(int fd, void __user *buff, size_t len,
 
 out_put:
        fput_light(sock_file, fput_needed);
+out:
        return err;
 }
 
@@ -1586,12 +1606,13 @@ asmlinkage long sys_recvfrom(int fd, void __user *ubuf, size_t size,
        int fput_needed;
 
        sock_file = fget_light(fd, &fput_needed);
+       err = -EBADF;
        if (!sock_file)
-               return -EBADF;
+               goto out;
 
        sock = sock_from_file(sock_file, &err);
        if (!sock)
-               goto out;
+               goto out_put;
 
        msg.msg_control = NULL;
        msg.msg_controllen = 0;
@@ -1610,8 +1631,9 @@ asmlinkage long sys_recvfrom(int fd, void __user *ubuf, size_t size,
                if (err2 < 0)
                        err = err2;
        }
-out:
+out_put:
        fput_light(sock_file, fput_needed);
+out:
        return err;
 }
 
@@ -2189,7 +2211,7 @@ done:
 }
 
 int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen,
-                   int flags)
+                  int flags)
 {
        return sock->ops->connect(sock, addr, addrlen, flags);
 }