Skip to contentSkip to conversation

affs: add kunmap in error path

PATCH In review Insu Yun 2 participants 3 messages Feb 2, 2016

Subsystems (2)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 affs: add kunmap in error path

When error occurs, it needs to unmap page.

---
 fs/affs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/affs/file.c +3 -1
index 0548c53..fa4f24e 100644
@@ -520,8 +520,10 @@ affs_do_readpage_ofs(struct page *page, unsigned to)
 
 	while (pos < to) {
 		bh = affs_bread_ino(inode, bidx, 0);
-		if (IS_ERR(bh))
+		if (IS_ERR(bh)) {
+			kunmap(page);
 			return PTR_ERR(bh);
+		}
 		tmp = min(bsize - boff, to - pos);
 		BUG_ON(pos + tmp > to || tmp > bsize);
 		memcpy(data + pos, AFFS_DATA(bh) + boff, tmp);
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 1 line · Insu Yun

When error occurs, it needs to unmap page.

Point, but... I'm not sure there's any point in keeping it mapped all along. After all, what we are doing is a bunch of memcpy() into the parts of page, so kmap_atomic()/kunmap_atomic() just around memcpy would do just fine.

maintainer
#2 lore raw
Quoted 7 lines · Al Viro
Quoted 1 line · Insu Yun

When error occurs, it needs to unmap page.

Point, but... I'm not sure there's any point in keeping it mapped all along. After all, what we are doing is a bunch of memcpy() into the parts of page, so kmap_atomic()/kunmap_atomic() just around memcpy would do just fine.

IOW, something like this (completely untested):

fs/affs/file.c +2 -3
index 0548c53..22fc7c8 100644
@@ -511,8 +511,6 @@ affs_do_readpage_ofs(struct page *page, unsigned to)
 	pr_debug("%s(%lu, %ld, 0, %d)\n", __func__, inode->i_ino,
 		 page->index, to);
 	BUG_ON(to > PAGE_CACHE_SIZE);
-	kmap(page);
-	data = page_address(page);
 	bsize = AFFS_SB(sb)->s_data_blksize;
 	tmp = page->index << PAGE_CACHE_SHIFT;
 	bidx = tmp / bsize;
@@ -524,14 +522,15 @@ affs_do_readpage_ofs(struct page *page, unsigned to)
 			return PTR_ERR(bh);
 		tmp = min(bsize - boff, to - pos);
 		BUG_ON(pos + tmp > to || tmp > bsize);
+		data = kmap_atomic(page);
 		memcpy(data + pos, AFFS_DATA(bh) + boff, tmp);
+		kunmap_atomic(data);
 		affs_brelse(bh);
 		bidx++;
 		pos += tmp;
 		boff = 0;
 	}
 	flush_dcache_page(page);
-	kunmap(page);
 	return 0;
 }