[patch 02/25] romfs_readpage: dont report errors for pages beyond i_size

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>, <stable@...>
Cc: Justin Forbes <jmforbes@...>, Zwane Mwaikambo <zwane@...>, Theodore Ts'o <tytso@...>, Randy Dunlap <rdunlap@...>, Dave Jones <davej@...>, Chuck Wolber <chuckw@...>, Chris Wedgwood <reviews@...>, Michael Krufky <mkrufky@...>, Chuck Ebbert <cebbert@...>, Domenico Andreoli <cavokz@...>, Willy Tarreau <w@...>, Rodrigo Rubira Branco <rbranco@...>, Jake Edge <jake@...>, Eugene Teo <eteo@...>, <torvalds@...>, <akpm@...>, <alan@...>, Alexander Viro <viro@...>, Matt Waddel <matt.waddel@...>, Greg Ungerer <gerg@...>
Date: Monday, August 4, 2008 - 5:29 pm

2.6.26-stable review patch.  If anyone has any objections, please let us
know.

------------------

From: Linus Torvalds <torvalds@linux-foundation.org>

commit 0056e65f9e28d83ee1a3fb4f7d0041e838f03c34 upstream

We zero-fill them like we are supposed to, and that's all fine.  It's
only an error if the 'romfs_copyfrom()' routine isn't able to fill the
data that is supposed to be there.

Most of the patch is really just re-organizing the code a bit, and using
separate variables for the error value and for how much of the page we
actually filled from the filesystem.

Reported-and-tested-by: Chris Fester <cfester@wms.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Matt Waddel <matt.waddel@freescale.com>
Cc: Greg Ungerer <gerg@snapgear.com>
Signed-of-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/romfs/inode.c |   37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

--- a/fs/romfs/inode.c
+++ b/fs/romfs/inode.c
@@ -418,7 +418,8 @@ static int
 romfs_readpage(struct file *file, struct page * page)
 {
 	struct inode *inode = page->mapping->host;
-	loff_t offset, avail, readlen;
+	loff_t offset, size;
+	unsigned long filled;
 	void *buf;
 	int result = -EIO;
 
@@ -430,21 +431,29 @@ romfs_readpage(struct file *file, struct
 
 	/* 32 bit warning -- but not for us :) */
 	offset = page_offset(page);
-	if (offset < i_size_read(inode)) {
-		avail = inode->i_size-offset;
-		readlen = min_t(unsigned long, avail, PAGE_SIZE);
-		if (romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen) == readlen) {
-			if (readlen < PAGE_SIZE) {
-				memset(buf + readlen,0,PAGE_SIZE-readlen);
-			}
-			SetPageUptodate(page);
-			result = 0;
+	size = i_size_read(inode);
+	filled = 0;
+	result = 0;
+	if (offset < size) {
+		unsigned long readlen;
+
+		size -= offset;
+		readlen = size > PAGE_SIZE ? PAGE_SIZE : size;
+
+		filled = romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen);
+
+		if (filled != readlen) {
+			SetPageError(page);
+			filled = 0;
+			result = -EIO;
 		}
 	}
-	if (result) {
-		memset(buf, 0, PAGE_SIZE);
-		SetPageError(page);
-	}
+
+	if (filled < PAGE_SIZE)
+		memset(buf + filled, 0, PAGE_SIZE-filled);
+
+	if (!result)
+		SetPageUptodate(page);
 	flush_dcache_page(page);
 
 	unlock_page(page);

-- 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 00/25] 2.6.26-stable review, Greg KH, (Mon Aug 4, 5:27 pm)
[patch 25/25] Ath5k: kill tasklets on shutdown, Greg KH, (Mon Aug 4, 5:30 pm)
[patch 24/25] Ath5k: fix memory corruption, Greg KH, (Mon Aug 4, 5:30 pm)
[patch 11/25] SCSI: ch: fix ch_remove oops, Greg KH, (Mon Aug 4, 5:30 pm)
[patch 07/25] Close race in md_probe, Greg KH, (Mon Aug 4, 5:29 pm)
[patch 02/25] romfs_readpage: dont report errors for pages b..., Greg KH, (Mon Aug 4, 5:29 pm)
Re: [patch 01/25] ftrace: remove unneeded documentation, Steven Rostedt, (Mon Aug 4, 5:42 pm)
Re: [patch 01/25] ftrace: remove unneeded documentation, Steven Rostedt, (Mon Aug 4, 6:02 pm)
Re: [patch 01/25] ftrace: remove unneeded documentation, Steven Rostedt, (Mon Aug 4, 6:16 pm)