[POWERPC] 83xx: Suppress warning when CONFIG_PCI is not defined
[powerpc.git] / net / socket.c
index 0778c54..98a8f67 100644 (file)
@@ -261,8 +261,7 @@ static void init_once(void *foo, struct kmem_cache *cachep, unsigned long flags)
 {
        struct socket_alloc *ei = (struct socket_alloc *)foo;
 
-       if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR))
-           == SLAB_CTOR_CONSTRUCTOR)
+       if (flags & SLAB_CTOR_CONSTRUCTOR)
                inode_init_once(&ei->vfs_inode);
 }
 
@@ -314,8 +313,19 @@ static int sockfs_delete_dentry(struct dentry *dentry)
        dentry->d_flags |= DCACHE_UNHASHED;
        return 0;
 }
+
+/*
+ * sockfs_dname() is called from d_path().
+ */
+static char *sockfs_dname(struct dentry *dentry, char *buffer, int buflen)
+{
+       return dynamic_dname(dentry, buffer, buflen, "socket:[%lu]",
+                               dentry->d_inode->i_ino);
+}
+
 static struct dentry_operations sockfs_dentry_operations = {
        .d_delete = sockfs_delete_dentry,
+       .d_dname  = sockfs_dname,
 };
 
 /*
@@ -355,14 +365,9 @@ static int sock_alloc_fd(struct file **filep)
 
 static int sock_attach_fd(struct socket *sock, struct file *file)
 {
-       struct qstr this;
-       char name[32];
-
-       this.len = sprintf(name, "[%lu]", SOCK_INODE(sock)->i_ino);
-       this.name = name;
-       this.hash = 0;
+       struct qstr name = { .name = "" };
 
-       file->f_path.dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this);
+       file->f_path.dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name);
        if (unlikely(!file->f_path.dentry))
                return -ENOMEM;
 
@@ -585,6 +590,37 @@ int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
        return result;
 }
 
+/*
+ * called from sock_recv_timestamp() if sock_flag(sk, SOCK_RCVTSTAMP)
+ */
+void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
+       struct sk_buff *skb)
+{
+       ktime_t kt = skb->tstamp;
+
+       if (!sock_flag(sk, SOCK_RCVTSTAMPNS)) {
+               struct timeval tv;
+               /* Race occurred between timestamp enabling and packet
+                  receiving.  Fill in the current time for now. */
+               if (kt.tv64 == 0)
+                       kt = ktime_get_real();
+               skb->tstamp = kt;
+               tv = ktime_to_timeval(kt);
+               put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP, sizeof(tv), &tv);
+       } else {
+               struct timespec ts;
+               /* Race occurred between timestamp enabling and packet
+                  receiving.  Fill in the current time for now. */
+               if (kt.tv64 == 0)
+                       kt = ktime_get_real();
+               skb->tstamp = kt;
+               ts = ktime_to_timespec(kt);
+               put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPNS, sizeof(ts), &ts);
+       }
+}
+
+EXPORT_SYMBOL_GPL(__sock_recv_timestamp);
+
 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
                                 struct msghdr *msg, size_t size, int flags)
 {
@@ -1194,6 +1230,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
@@ -1212,18 +1249,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.
         */
@@ -1238,17 +1294,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;
 }
 
 /*
@@ -1266,7 +1328,7 @@ asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
        int err, fput_needed;
 
        sock = sockfd_lookup_light(fd, &err, &fput_needed);
-       if(sock) {
+       if (sock) {
                err = move_addr_to_kernel(umyaddr, addrlen, address);
                if (err >= 0) {
                        err = security_socket_bind(sock,
@@ -1355,7 +1417,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)
@@ -1388,6 +1450,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);