Skip to content

Commit

Permalink
[NET]: cleanup sock_from_file()
Browse files Browse the repository at this point in the history
I believe dead code from sock_from_file() can be cleaned up.

All sockets are now built using sock_attach_fd(), that puts the 'sock' pointer 
into file->private_data and &socket_file_ops into file->f_op

I could not find a place where file->private_data could be set to NULL, 
keeping opened the file.

So to get 'sock' from a 'file' pointer, either :

- This is a socket file (f_op == &socket_file_ops), and we can directly get 
'sock' from private_data.
- This is not a socket, we return -ENOTSOCK and dont even try to find a socket 
via dentry/inode :)

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Feb 8, 2007
1 parent dbca9b2 commit 23bb80d
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 23bb80d

Please sign in to comment.