From patchwork Tue Oct 19 08:22:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 68279 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A7FBDB70DF for ; Tue, 19 Oct 2010 19:22:27 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758008Ab0JSIWQ (ORCPT ); Tue, 19 Oct 2010 04:22:16 -0400 Received: from mail-pz0-f46.google.com ([209.85.210.46]:58379 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758003Ab0JSIWO (ORCPT ); Tue, 19 Oct 2010 04:22:14 -0400 Received: by pzk3 with SMTP id 3so199008pzk.19 for ; Tue, 19 Oct 2010 01:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=ignINDtP9g3chUJz0jIIzCZx1t0AKCU/nNW5IFhh7f0=; b=BhCcENI0ub6QtOnoPZ1hnt1PgjVKBrkfWVJCPc9aUyd/iKwrOUFRB+01Zui0X7pw9k MYz59gEL35HaH8jNVOW0obp++XS29Pd3Y/qGTOOVuDofwXoDuw1D3eNeUBrkSU7iZuq/ asFg03R4bRJR3gqt2nr+KhLlx6xHZm9gE0Vng= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=OJTkKZbBLsao5y6jH9nxVrWcODf90b6nUl47UuRU+SoIZmV8z8kOGYh0U8gj2cX1Zp sN4NDuyTPAnnJZztWBP44U5MC2+w+0q+si98xJTjIkGTUGB+N7lX/V2P4M9JW6dqUs/w ieBZwp8t/UlU6K712aP49GE9MGCUQ8H+jvxqM= Received: by 10.142.185.8 with SMTP id i8mr2390610wff.394.1287476533840; Tue, 19 Oct 2010 01:22:13 -0700 (PDT) Received: from localhost.localdomain ([211.201.183.198]) by mx.google.com with ESMTPS id w42sm15976000wfh.3.2010.10.19.01.22.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 19 Oct 2010 01:22:13 -0700 (PDT) From: Namhyung Kim To: Theodore Ts'o , Andreas Dilger Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ext4: Check return value of sb_getblk() and friends Date: Tue, 19 Oct 2010 17:22:09 +0900 Message-Id: <1287476529-5314-1-git-send-email-namhyung@gmail.com> X-Mailer: git-send-email 1.7.0.4 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Fail block allocation if sb_getblk() returns NULL. In that case, sb_find_get_block() also likely to fail so that it should skip calling ext4_forget(). Signed-off-by: Namhyung Kim --- fs/ext4/inode.c | 5 +++++ fs/ext4/mballoc.c | 2 ++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4b8debe..12c0310 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -755,6 +755,11 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode, * parent to disk. */ bh = sb_getblk(inode->i_sb, new_blocks[n-1]); + if (unlikely(!bh)) { + err = -EIO; + goto failed; + } + branch[n].bh = bh; lock_buffer(bh); BUFFER_TRACE(bh, "call get_create_access"); diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 4b4ad4b..48f5d10 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4531,6 +4531,8 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, if (!bh) tbh = sb_find_get_block(inode->i_sb, block + i); + if (unlikely(!tbh)) + continue; ext4_forget(handle, flags & EXT4_FREE_BLOCKS_METADATA, inode, tbh, block + i); }