Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linux-davinci
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
linux
linux-davinci
Commits
7cbe66b6
Commit
7cbe66b6
authored
Aug 05, 2009
by
Al Viro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge sock_alloc_fd/sock_attach_fd into a new helper
Signed-off-by:
Al Viro
<
viro@zeniv.linux.org.uk
>
parent
198de4d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
57 deletions
+23
-57
net/socket.c
net/socket.c
+23
-57
No files found.
net/socket.c
View file @
7cbe66b6
...
@@ -355,32 +355,30 @@ static const struct dentry_operations sockfs_dentry_operations = {
...
@@ -355,32 +355,30 @@ static const struct dentry_operations sockfs_dentry_operations = {
* but we take care of internal coherence yet.
* but we take care of internal coherence yet.
*/
*/
static
int
sock_alloc_f
d
(
struct
file
**
filep
,
int
flags
)
static
int
sock_alloc_f
ile
(
struct
socket
*
sock
,
struct
file
**
f
,
int
flags
)
{
{
struct
qstr
name
=
{
.
name
=
""
};
struct
dentry
*
dentry
;
struct
file
*
file
;
int
fd
;
int
fd
;
fd
=
get_unused_fd_flags
(
flags
);
fd
=
get_unused_fd_flags
(
flags
);
if
(
likely
(
fd
>=
0
))
{
if
(
unlikely
(
fd
<
0
))
struct
file
*
file
=
get_empty_filp
()
;
return
fd
;
*
filep
=
file
;
file
=
get_empty_filp
();
if
(
unlikely
(
!
file
))
{
put_unused_fd
(
fd
);
return
-
ENFILE
;
}
}
else
*
filep
=
NULL
;
return
fd
;
}
static
int
sock_attach_fd
(
struct
socket
*
sock
,
struct
file
*
file
,
int
flags
)
if
(
unlikely
(
!
file
))
{
{
put_unused_fd
(
fd
);
struct
dentry
*
dentry
;
return
-
ENFILE
;
struct
qstr
name
=
{
.
name
=
""
};
}
dentry
=
d_alloc
(
sock_mnt
->
mnt_sb
->
s_root
,
&
name
);
dentry
=
d_alloc
(
sock_mnt
->
mnt_sb
->
s_root
,
&
name
);
if
(
unlikely
(
!
dentry
))
if
(
unlikely
(
!
dentry
))
{
put_filp
(
file
);
put_unused_fd
(
fd
);
return
-
ENOMEM
;
return
-
ENOMEM
;
}
dentry
->
d_op
=
&
sockfs_dentry_operations
;
dentry
->
d_op
=
&
sockfs_dentry_operations
;
/*
/*
...
@@ -399,24 +397,18 @@ static int sock_attach_fd(struct socket *sock, struct file *file, int flags)
...
@@ -399,24 +397,18 @@ static int sock_attach_fd(struct socket *sock, struct file *file, int flags)
file
->
f_pos
=
0
;
file
->
f_pos
=
0
;
file
->
private_data
=
sock
;
file
->
private_data
=
sock
;
return
0
;
*
f
=
file
;
return
fd
;
}
}
int
sock_map_fd
(
struct
socket
*
sock
,
int
flags
)
int
sock_map_fd
(
struct
socket
*
sock
,
int
flags
)
{
{
struct
file
*
newfile
;
struct
file
*
newfile
;
int
fd
=
sock_alloc_fd
(
&
newfile
,
flags
);
int
fd
=
sock_alloc_file
(
sock
,
&
newfile
,
flags
);
if
(
likely
(
fd
>=
0
))
{
int
err
=
sock_attach_fd
(
sock
,
newfile
,
flags
);
if
(
unlikely
(
err
<
0
))
{
if
(
likely
(
fd
>=
0
))
put_filp
(
newfile
);
put_unused_fd
(
fd
);
return
err
;
}
fd_install
(
fd
,
newfile
);
fd_install
(
fd
,
newfile
);
}
return
fd
;
return
fd
;
}
}
...
@@ -1390,20 +1382,13 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
...
@@ -1390,20 +1382,13 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
if
(
err
<
0
)
if
(
err
<
0
)
goto
out_release_both
;
goto
out_release_both
;
fd1
=
sock_alloc_f
d
(
&
newfile1
,
flags
&
O_CLOEXEC
);
fd1
=
sock_alloc_f
ile
(
sock1
,
&
newfile1
,
flags
);
if
(
unlikely
(
fd1
<
0
))
{
if
(
unlikely
(
fd1
<
0
))
{
err
=
fd1
;
err
=
fd1
;
goto
out_release_both
;
goto
out_release_both
;
}
}
err
=
sock_attach_fd
(
sock1
,
newfile1
,
flags
&
O_NONBLOCK
);
fd2
=
sock_alloc_file
(
sock2
,
&
newfile2
,
flags
);
if
(
unlikely
(
err
<
0
))
{
put_filp
(
newfile1
);
put_unused_fd
(
fd1
);
goto
out_release_both
;
}
fd2
=
sock_alloc_fd
(
&
newfile2
,
flags
&
O_CLOEXEC
);
if
(
unlikely
(
fd2
<
0
))
{
if
(
unlikely
(
fd2
<
0
))
{
err
=
fd2
;
err
=
fd2
;
fput
(
newfile1
);
fput
(
newfile1
);
...
@@ -1412,16 +1397,6 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
...
@@ -1412,16 +1397,6 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
goto
out
;
goto
out
;
}
}
err
=
sock_attach_fd
(
sock2
,
newfile2
,
flags
&
O_NONBLOCK
);
if
(
unlikely
(
err
<
0
))
{
put_filp
(
newfile2
);
put_unused_fd
(
fd2
);
fput
(
newfile1
);
put_unused_fd
(
fd1
);
sock_release
(
sock2
);
goto
out
;
}
audit_fd_pair
(
fd1
,
fd2
);
audit_fd_pair
(
fd1
,
fd2
);
fd_install
(
fd1
,
newfile1
);
fd_install
(
fd1
,
newfile1
);
fd_install
(
fd2
,
newfile2
);
fd_install
(
fd2
,
newfile2
);
...
@@ -1548,17 +1523,13 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
...
@@ -1548,17 +1523,13 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
*/
*/
__module_get
(
newsock
->
ops
->
owner
);
__module_get
(
newsock
->
ops
->
owner
);
newfd
=
sock_alloc_f
d
(
&
newfile
,
flags
&
O_CLOEXEC
);
newfd
=
sock_alloc_f
ile
(
newsock
,
&
newfile
,
flags
);
if
(
unlikely
(
newfd
<
0
))
{
if
(
unlikely
(
newfd
<
0
))
{
err
=
newfd
;
err
=
newfd
;
sock_release
(
newsock
);
sock_release
(
newsock
);
goto
out_put
;
goto
out_put
;
}
}
err
=
sock_attach_fd
(
newsock
,
newfile
,
flags
&
O_NONBLOCK
);
if
(
err
<
0
)
goto
out_fd_simple
;
err
=
security_socket_accept
(
sock
,
newsock
);
err
=
security_socket_accept
(
sock
,
newsock
);
if
(
err
)
if
(
err
)
goto
out_fd
;
goto
out_fd
;
...
@@ -1588,11 +1559,6 @@ out_put:
...
@@ -1588,11 +1559,6 @@ out_put:
fput_light
(
sock
->
file
,
fput_needed
);
fput_light
(
sock
->
file
,
fput_needed
);
out:
out:
return
err
;
return
err
;
out_fd_simple:
sock_release
(
newsock
);
put_filp
(
newfile
);
put_unused_fd
(
newfd
);
goto
out_put
;
out_fd:
out_fd:
fput
(
newfile
);
fput
(
newfile
);
put_unused_fd
(
newfd
);
put_unused_fd
(
newfd
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment