From: Russ W. Knize Date: Tue, 24 Sep 2013 14:35:40 +0000 (-0500) Subject: f2fs: don't let the orphan inode counter underflow X-Git-Tag: upstream/snapshot3+hdmi~4002^2~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=885166c03c1d0ea6d79d707229340e3161ed1316;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git f2fs: don't let the orphan inode counter underflow Accounting errors from buggy code calling the acquire/release/remove orphan inode interfaces can cause n_orphans to underflow, which will then cause acquire_orphan_inode() to return -ENOSPC on the next operation. This commit guards against that condition. Signed-off-by: Russ Knize Signed-off-by: Jaegeuk Kim --- diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index bb31220..ca39442 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -206,6 +206,7 @@ int acquire_orphan_inode(struct f2fs_sb_info *sbi) void release_orphan_inode(struct f2fs_sb_info *sbi) { mutex_lock(&sbi->orphan_inode_mutex); + BUG_ON(sbi->n_orphans == 0); sbi->n_orphans--; mutex_unlock(&sbi->orphan_inode_mutex); } @@ -253,6 +254,7 @@ void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) if (orphan->ino == ino) { list_del(&orphan->list); kmem_cache_free(orphan_entry_slab, orphan); + BUG_ON(sbi->n_orphans == 0); sbi->n_orphans--; break; }