VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
author: Al Viro <viro@zeniv.linux.org.uk> 2012-08-12 16:17:59 -0400 committer: Al Viro <viro@zeniv.linux.org.uk> 2012-09-26 21:08:53 -0400 commit: f33ff9927f42045116d738ee47ff7bc59f739bd7 parent: 352e3b249284235e00745f3e71fc348b913e5deb
Commit Summary:
take rlimit check to callers of expand_files()
Diffstat:
1 file changed, 9 insertions, 7 deletions
diff --git a/fs/file.c b/fs/file.c
index 5b46e9970a7a..08922af4a62c 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -251,13 +251,6 @@ int expand_files(struct files_struct *files, int nr)
 
 	fdt = files_fdtable(files);
 
-	/*
-	 * N.B. For clone tasks sharing a files structure, this test
-	 * will limit the total number of files that can be opened.
-	 */
-	if (nr >= rlimit(RLIMIT_NOFILE))
-		return -EMFILE;
-
 	/* Do we need to expand? */
 	if (nr < fdt->max_fds)
 		return 0;
@@ -431,6 +424,7 @@ int alloc_fd(unsigned start, unsigned flags)
 {
 	struct files_struct *files = current->files;
 	unsigned int fd;
+	unsigned end = rlimit(RLIMIT_NOFILE);
 	int error;
 	struct fdtable *fdt;
 
@@ -444,6 +438,14 @@ repeat:
 	if (fd < fdt->max_fds)
 		fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, fd);
 
+	/*
+	 * N.B. For clone tasks sharing a files structure, this test
+	 * will limit the total number of files that can be opened.
+	 */
+	error = -EMFILE;
+	if (fd >= end)
+		goto out;
+
 	error = expand_files(files, fd);
 	if (error < 0)
 		goto out;