From 10794d1410e477f3a81e912d4a22a7fecab6a6ca Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 23 Nov 2007 15:38:32 -0500 Subject: [PATCH] - pre4: - truncate really fixed this time. Everybody agrees. --- drivers/sound/nm256_audio.c | 2 +- fs/buffer.c | 27 ++++++++------------------- fs/ext2/inode.c | 3 +-- include/linux/fs.h | 19 +++++++++++++++---- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/drivers/sound/nm256_audio.c b/drivers/sound/nm256_audio.c index 9049b4ceaaa9..c41c858d085d 100644 --- a/drivers/sound/nm256_audio.c +++ b/drivers/sound/nm256_audio.c @@ -1467,7 +1467,7 @@ nm256_audio_ioctl(int dev, unsigned int cmd, caddr_t arg) break; case SNDCTL_DSP_SETFMT: - if (get_user(ret, (int *) arg) + if (get_user(ret, (int *) arg)) return -EFAULT; if (ret != 0) { diff --git a/fs/buffer.c b/fs/buffer.c index b9120655e774..5ee5d376fdab 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1514,6 +1514,9 @@ static int __block_commit_write(struct inode *inode, struct page *page, bh != head || !block_start; block_start=block_end, bh = bh->b_this_page) { block_end = block_start + blocksize; + /* This can happen for the truncate case */ + if (!buffer_mapped(bh)) + continue; if (block_end <= from || block_start >= to) { if (!buffer_uptodate(bh)) partial = 1; @@ -1721,24 +1724,12 @@ int generic_commit_write(struct file *file, struct page *page, return 0; } -/* - * If it would be '74 that would go into libc... - */ -int mem_is_zero(char *p, unsigned len) -{ - while (len--) - if (*p++) - return 0; - return 1; -} - int block_zero_page(struct address_space *mapping, loff_t from, unsigned length) { unsigned long index = from >> PAGE_CACHE_SHIFT; unsigned offset = from & (PAGE_CACHE_SIZE-1); struct inode *inode = (struct inode *)mapping->host; struct page *page; - char *kaddr; int err; if (!length) @@ -1747,21 +1738,19 @@ int block_zero_page(struct address_space *mapping, loff_t from, unsigned length) page = read_cache_page(mapping, index, (filler_t *)mapping->a_ops->readpage, NULL); err = PTR_ERR(page); - if (ERR_PTR(page)) + if (IS_ERR(page)) goto out; lock_page(page); err = -EIO; if (!Page_Uptodate(page)) goto unlock; - kaddr = (char*)kmap(page); - err = 0; - if (mem_is_zero(kaddr+offset, length)) - goto unmap; - memset(kaddr+offset, 0, length); + + memset((char *) kmap(page) + offset, 0, length); flush_dcache_page(page); __block_commit_write(inode, page, offset, offset+length); -unmap: kunmap(page); + err = 0; + unlock: UnlockPage(page); page_cache_release(page); diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index a6567685e9c5..6c89f5090424 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -919,8 +919,7 @@ void ext2_truncate (struct inode * inode) >> EXT2_BLOCK_SIZE_BITS(inode->i_sb); tail = (iblock << EXT2_BLOCK_SIZE_BITS(inode->i_sb)) - inode->i_size; - if (block_zero_page(inode->i_mapping, inode->i_size, tail) != 0) - return; + block_zero_page(inode->i_mapping, inode->i_size, tail); n = ext2_block_to_path(inode, iblock, offsets); if (n == 0) diff --git a/include/linux/fs.h b/include/linux/fs.h index 17f2502cc141..15b5aa8886f1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1050,9 +1050,20 @@ extern ino_t find_inode_number(struct dentry *, struct qstr *); * This should be a per-architecture thing, to allow different * error and pointer decisions. */ -#define ERR_PTR(err) ((void *)((long)(err))) -#define PTR_ERR(ptr) ((long)(ptr)) -#define IS_ERR(ptr) ((unsigned long)(ptr) > (unsigned long)(-1000)) +static inline void *ERR_PTR(long error) +{ + return (void *) error; +} + +static inline long PTR_ERR(const void *ptr) +{ + return (long) ptr; +} + +static inline long IS_ERR(const void *ptr) +{ + return (unsigned long)ptr > (unsigned long)-1000L; +} /* * The bitmask for a lookup event: @@ -1162,7 +1173,7 @@ extern int block_sync_page(struct page *); int generic_block_bmap(struct address_space *, long, get_block_t *); int generic_commit_write(struct file *, struct page *, unsigned, unsigned); -int block_zero_page(struct address_space *mapping, loff_t, unsigned); +int block_zero_page(struct address_space *, loff_t, unsigned); extern int generic_file_mmap(struct file *, struct vm_area_struct *); extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *); -- 2.39.5