diff options
Diffstat (limited to 'kernel/fork.c')
| -rw-r--r-- | kernel/fork.c | 32 | 
1 files changed, 14 insertions, 18 deletions
| diff --git a/kernel/fork.c b/kernel/fork.c index 60c0b4868fd4..89ceb4a68af2 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1756,33 +1756,30 @@ static int copy_files(unsigned long clone_flags, struct task_struct *tsk,  		      int no_files)  {  	struct files_struct *oldf, *newf; -	int error = 0;  	/*  	 * A background process may not have any files ...  	 */  	oldf = current->files;  	if (!oldf) -		goto out; +		return 0;  	if (no_files) {  		tsk->files = NULL; -		goto out; +		return 0;  	}  	if (clone_flags & CLONE_FILES) {  		atomic_inc(&oldf->count); -		goto out; +		return 0;  	} -	newf = dup_fd(oldf, NR_OPEN_MAX, &error); -	if (!newf) -		goto out; +	newf = dup_fd(oldf, NULL); +	if (IS_ERR(newf)) +		return PTR_ERR(newf);  	tsk->files = newf; -	error = 0; -out: -	return error; +	return 0;  }  static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) @@ -3238,17 +3235,16 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)  /*   * Unshare file descriptor table if it is being shared   */ -int unshare_fd(unsigned long unshare_flags, unsigned int max_fds, -	       struct files_struct **new_fdp) +static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)  {  	struct files_struct *fd = current->files; -	int error = 0;  	if ((unshare_flags & CLONE_FILES) &&  	    (fd && atomic_read(&fd->count) > 1)) { -		*new_fdp = dup_fd(fd, max_fds, &error); -		if (!*new_fdp) -			return error; +		fd = dup_fd(fd, NULL); +		if (IS_ERR(fd)) +			return PTR_ERR(fd); +		*new_fdp = fd;  	}  	return 0; @@ -3306,7 +3302,7 @@ int ksys_unshare(unsigned long unshare_flags)  	err = unshare_fs(unshare_flags, &new_fs);  	if (err)  		goto bad_unshare_out; -	err = unshare_fd(unshare_flags, NR_OPEN_MAX, &new_fd); +	err = unshare_fd(unshare_flags, &new_fd);  	if (err)  		goto bad_unshare_cleanup_fs;  	err = unshare_userns(unshare_flags, &new_cred); @@ -3398,7 +3394,7 @@ int unshare_files(void)  	struct files_struct *old, *copy = NULL;  	int error; -	error = unshare_fd(CLONE_FILES, NR_OPEN_MAX, ©); +	error = unshare_fd(CLONE_FILES, ©);  	if (error || !copy)  		return error; | 
