From patchwork Mon Sep 24 04:38:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Sheng-Hui X-Patchwork-Id: 1496161 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 9D170E0117 for ; Mon, 24 Sep 2012 04:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751799Ab2IXEiS (ORCPT ); Mon, 24 Sep 2012 00:38:18 -0400 Received: from mail-oa0-f46.google.com ([209.85.219.46]:44778 "EHLO mail-oa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751461Ab2IXEiR (ORCPT ); Mon, 24 Sep 2012 00:38:17 -0400 Received: by oago6 with SMTP id o6so5032247oag.19 for ; Sun, 23 Sep 2012 21:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=2N8dhgjc3atP/EoKbWkD08PbSOuYfun2j7b+E6tqqBU=; b=Puulhipd6EWCCON2pGkpZCS0nRnTLjYO/MRnDVeUTk8zjKKb0dMpEMd11E4lLbo7WH umsTShzgB21BRwHOnSSh1VfmbTHMMESVPamCR/MHFQrSnbk5XZ1gCzQcB7mwxx4PWx3j 1RunIw7/eQnKFTZsgOF+I+YnUZkijdqSX6uH5MwFx/G3EbWfVTQ9OtSiV059N5qKQb/l j6hQxvzLVpr7S24OfCLRwqL2z+Or2bTSMnOVjgwe5fqzhDmz35HQ1ojxyCYP82avb5Bu 0QUmBst0wfs7/mhknJw1Irj+iEUGCGArJqBFk0cRtKr0fCcmeQHJeam04EoBIMsDPc8+ s6Hg== Received: by 10.60.32.19 with SMTP id e19mr9123864oei.9.1348461496574; Sun, 23 Sep 2012 21:38:16 -0700 (PDT) Received: from [9.115.120.40] ([202.108.130.138]) by mx.google.com with ESMTPS id th3sm15088561obb.6.2012.09.23.21.38.13 (version=SSLv3 cipher=OTHER); Sun, 23 Sep 2012 21:38:15 -0700 (PDT) Message-ID: <505FE3AF.2090302@gmail.com> Date: Mon, 24 Sep 2012 12:38:07 +0800 From: Wang Sheng-Hui User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: chris.mason@fusionio.com, jbacik@fusionio.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Btrfs: check range early in map_private_extent_buffer Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Check range early to avoid further check/compute in case of range error. Signed-off-by: Wang Sheng-Hui --- fs/btrfs/extent_io.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 4c87847..9250cf5 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -4643,6 +4643,14 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start, unsigned long end_i = (start_offset + start + min_len - 1) >> PAGE_CACHE_SHIFT; + if (start + min_len > eb->len) { + printk(KERN_ERR "btrfs bad mapping eb start %llu len %lu, " + "wanted %lu %lu\n", (unsigned long long)eb->start, + eb->len, start, min_len); + WARN_ON(1); + return -EINVAL; + } + if (i != end_i) return -EINVAL; @@ -4654,14 +4662,6 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start, *map_start = ((u64)i << PAGE_CACHE_SHIFT) - start_offset; } - if (start + min_len > eb->len) { - printk(KERN_ERR "btrfs bad mapping eb start %llu len %lu, " - "wanted %lu %lu\n", (unsigned long long)eb->start, - eb->len, start, min_len); - WARN_ON(1); - return -EINVAL; - } - p = extent_buffer_page(eb, i); kaddr = page_address(p); *map = kaddr + offset;