From patchwork Mon Dec 13 09:50:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zefan X-Patchwork-Id: 405212 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBD9oCJ0017462 for ; Mon, 13 Dec 2010 09:50:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752764Ab0LMJt7 (ORCPT ); Mon, 13 Dec 2010 04:49:59 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:60195 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752289Ab0LMJt6 (ORCPT ); Mon, 13 Dec 2010 04:49:58 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 676B01709FD; Mon, 13 Dec 2010 17:49:57 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id oBD9jA4x027902; Mon, 13 Dec 2010 17:45:10 +0800 Received: from lizf.localdomain ([10.167.225.51]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2010121317495836-220678 ; Mon, 13 Dec 2010 17:49:58 +0800 Message-ID: <4D05EC4A.8000908@cn.fujitsu.com> Date: Mon, 13 Dec 2010 17:50:02 +0800 From: Li Zefan User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: "linux-btrfs@vger.kernel.org" CC: "Ian! D. Allen" Subject: [PATCH 2/3] Btrfs: Don't return items more than user specified References: <4D05EBC9.6020908@cn.fujitsu.com> In-Reply-To: <4D05EBC9.6020908@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-13 17:49:58, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-13 17:49:58, Serialize complete at 2010-12-13 17:49:58 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 13 Dec 2010 09:50:13 +0000 (UTC) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 785f713..08174e2 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1053,7 +1053,6 @@ static noinline int copy_to_sk(struct btrfs_root *root, int nritems; int i; int slot; - int found = 0; int ret = 0; leaf = path->nodes[0]; @@ -1100,8 +1099,8 @@ static noinline int copy_to_sk(struct btrfs_root *root, item_off, item_len); *sk_offset += item_len; } - found++; + (*num_found)++; if (*num_found >= sk->nr_items) break; } @@ -1119,7 +1118,6 @@ advance_key: } else ret = 1; overflow: - *num_found += found; return ret; } @@ -1136,6 +1134,9 @@ static noinline int search_ioctl(struct inode *inode, int num_found = 0; unsigned long sk_offset = 0; + if (sk->nr_items == 0) + return -EINVAL; + path = btrfs_alloc_path(); if (!path) return -ENOMEM;