From patchwork Sun Apr 7 10:58:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 2402941 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 49F55DF2A1 for ; Sun, 7 Apr 2013 10:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933235Ab3DGK6o (ORCPT ); Sun, 7 Apr 2013 06:58:44 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:36912 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933164Ab3DGK6o (ORCPT ); Sun, 7 Apr 2013 06:58:44 -0400 Received: by mail-pa0-f47.google.com with SMTP id bj3so2766835pad.34 for ; Sun, 07 Apr 2013 03:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=vKkVcBmYLZl1kEpzjLpqWWXr/NqzHImNghAa5WL+8Vo=; b=n/O+YYBzuuIazDSNkB9vWC2K0HbUcEGmMSTOtL9qmkUKoTRlui2ihmTXzXn13/nE4T O/LTWbPGD8gnzg/XD3+YAkRQKuZghGfCughpnC3jad2yYr2xcGuPlmH3Xf0oFh6H7PMK OC+qYQG7T1gM3AysuQRghMKv3Qzx1FGIKpTGhoNPE1lMliMYLYcoeXzoxdyFsVeaEleu f4EDWYb4/6jCCK3Q2+3aTCSxmlDZxyBKatEJ/KtVW8sLsampfDuZSb+mgDkv5Ka7SIH7 R9FscD32w+WzhwEAvPtgIhmv4wdMwIWCJ+SEfDdz/RXschhyw/66wZiU49VqxtITIlmp SAKg== X-Received: by 10.66.122.8 with SMTP id lo8mr27124587pab.163.1365332323521; Sun, 07 Apr 2013 03:58:43 -0700 (PDT) Received: from localhost.localdomain.localdomain ([112.2.228.26]) by mx.google.com with ESMTPS id yp2sm28616646pab.10.2013.04.07.03.58.41 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 07 Apr 2013 03:58:42 -0700 (PDT) From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: sensille@gmx.net, wangsl-fnst@cn.fujitsu.com Subject: [PATCH] Btrfs: fix missing check about ulist_add() in qgroup.c Date: Sun, 7 Apr 2013 18:58:14 +0800 Message-Id: <1365332294-1230-1-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 1.7.11.7 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Wang Shilong ulist_add() may return -ENOMEM, fix missing check about return value. Signed-off-by: Wang Shilong --- fs/btrfs/qgroup.c | 60 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index deaa2e8..f585b8a 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1263,7 +1263,10 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, ulist_reinit(tmp); /* XXX id not needed */ - ulist_add(tmp, qg->qgroupid, (u64)(uintptr_t)qg, GFP_ATOMIC); + ret = ulist_add(tmp, qg->qgroupid, + (u64)(uintptr_t)qg, GFP_ATOMIC); + if (ret < 0) + goto unlock; ULIST_ITER_INIT(&tmp_uiter); while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) { struct btrfs_qgroup_list *glist; @@ -1275,9 +1278,11 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, ++qg->refcnt; list_for_each_entry(glist, &qg->groups, next_group) { - ulist_add(tmp, glist->group->qgroupid, - (u64)(uintptr_t)glist->group, - GFP_ATOMIC); + ret = ulist_add(tmp, glist->group->qgroupid, + (u64)(uintptr_t)glist->group, + GFP_ATOMIC); + if (ret < 0) + goto unlock; } } } @@ -1286,7 +1291,10 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, * step 2: walk from the new root */ ulist_reinit(tmp); - ulist_add(tmp, qgroup->qgroupid, (uintptr_t)qgroup, GFP_ATOMIC); + ret = ulist_add(tmp, qgroup->qgroupid, + (uintptr_t)qgroup, GFP_ATOMIC); + if (ret < 0) + goto unlock; ULIST_ITER_INIT(&uiter); while ((unode = ulist_next(tmp, &uiter))) { struct btrfs_qgroup *qg; @@ -1307,8 +1315,10 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, qg->tag = seq; list_for_each_entry(glist, &qg->groups, next_group) { - ulist_add(tmp, glist->group->qgroupid, - (uintptr_t)glist->group, GFP_ATOMIC); + ret = ulist_add(tmp, glist->group->qgroupid, + (uintptr_t)glist->group, GFP_ATOMIC); + if (ret < 0) + goto unlock; } } @@ -1326,7 +1336,10 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, continue; ulist_reinit(tmp); - ulist_add(tmp, qg->qgroupid, (uintptr_t)qg, GFP_ATOMIC); + ret = ulist_add(tmp, qg->qgroupid, + (uintptr_t)qg, GFP_ATOMIC); + if (ret < 0) + goto unlock; ULIST_ITER_INIT(&tmp_uiter); while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) { struct btrfs_qgroup_list *glist; @@ -1342,9 +1355,11 @@ int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, } list_for_each_entry(glist, &qg->groups, next_group) { - ulist_add(tmp, glist->group->qgroupid, - (uintptr_t)glist->group, - GFP_ATOMIC); + ret = ulist_add(tmp, glist->group->qgroupid, + (uintptr_t)glist->group, + GFP_ATOMIC); + if (ret < 0) + goto unlock; } } } @@ -1609,7 +1624,10 @@ int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes) ret = -ENOMEM; goto out; } - ulist_add(ulist, qgroup->qgroupid, (uintptr_t)qgroup, GFP_ATOMIC); + ret = ulist_add(ulist, qgroup->qgroupid, + (uintptr_t)qgroup, GFP_ATOMIC); + if (ret < 0) + goto out; ULIST_ITER_INIT(&uiter); while ((unode = ulist_next(ulist, &uiter))) { struct btrfs_qgroup *qg; @@ -1632,8 +1650,10 @@ int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes) } list_for_each_entry(glist, &qg->groups, next_group) { - ulist_add(ulist, glist->group->qgroupid, - (uintptr_t)glist->group, GFP_ATOMIC); + ret = ulist_add(ulist, glist->group->qgroupid, + (uintptr_t)glist->group, GFP_ATOMIC); + if (ret < 0) + goto out; } } @@ -1665,6 +1685,7 @@ void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes) struct ulist_node *unode; struct ulist_iterator uiter; u64 ref_root = root->root_key.objectid; + int ret = 0; if (!is_fstree(ref_root)) return; @@ -1687,7 +1708,10 @@ void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes) btrfs_std_error(fs_info, -ENOMEM); goto out; } - ulist_add(ulist, qgroup->qgroupid, (uintptr_t)qgroup, GFP_ATOMIC); + ret = ulist_add(ulist, qgroup->qgroupid, + (uintptr_t)qgroup, GFP_ATOMIC); + if (ret < 0) + goto out; ULIST_ITER_INIT(&uiter); while ((unode = ulist_next(ulist, &uiter))) { struct btrfs_qgroup *qg; @@ -1698,8 +1722,10 @@ void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes) qg->reserved -= num_bytes; list_for_each_entry(glist, &qg->groups, next_group) { - ulist_add(ulist, glist->group->qgroupid, - (uintptr_t)glist->group, GFP_ATOMIC); + ret = ulist_add(ulist, glist->group->qgroupid, + (uintptr_t)glist->group, GFP_ATOMIC); + if (ret < 0) + goto out; } }