romfs_readpage: don't report errors for pages beyond i_size
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>
This commit is contained in:
parent
660fc1f4d8
commit
0056e65f9e
1 changed files with 23 additions and 14 deletions
|
@ -418,7 +418,8 @@ static int
|
||||||
romfs_readpage(struct file *file, struct page * page)
|
romfs_readpage(struct file *file, struct page * page)
|
||||||
{
|
{
|
||||||
struct inode *inode = page->mapping->host;
|
struct inode *inode = page->mapping->host;
|
||||||
loff_t offset, avail, readlen;
|
loff_t offset, size;
|
||||||
|
unsigned long filled;
|
||||||
void *buf;
|
void *buf;
|
||||||
int result = -EIO;
|
int result = -EIO;
|
||||||
|
|
||||||
|
@ -430,21 +431,29 @@ romfs_readpage(struct file *file, struct page * page)
|
||||||
|
|
||||||
/* 32 bit warning -- but not for us :) */
|
/* 32 bit warning -- but not for us :) */
|
||||||
offset = page_offset(page);
|
offset = page_offset(page);
|
||||||
if (offset < i_size_read(inode)) {
|
size = i_size_read(inode);
|
||||||
avail = inode->i_size-offset;
|
filled = 0;
|
||||||
readlen = min_t(unsigned long, avail, PAGE_SIZE);
|
result = 0;
|
||||||
if (romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen) == readlen) {
|
if (offset < size) {
|
||||||
if (readlen < PAGE_SIZE) {
|
unsigned long readlen;
|
||||||
memset(buf + readlen,0,PAGE_SIZE-readlen);
|
|
||||||
}
|
size -= offset;
|
||||||
SetPageUptodate(page);
|
readlen = size > PAGE_SIZE ? PAGE_SIZE : size;
|
||||||
result = 0;
|
|
||||||
|
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);
|
if (filled < PAGE_SIZE)
|
||||||
SetPageError(page);
|
memset(buf + filled, 0, PAGE_SIZE-filled);
|
||||||
}
|
|
||||||
|
if (!result)
|
||||||
|
SetPageUptodate(page);
|
||||||
flush_dcache_page(page);
|
flush_dcache_page(page);
|
||||||
|
|
||||||
unlock_page(page);
|
unlock_page(page);
|
||||||
|
|
Loading…
Reference in a new issue