From patchwork Sun Jun 22 12:30:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 4396021 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 13D4ABEEAA for ; Sun, 22 Jun 2014 12:30:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2866A20268 for ; Sun, 22 Jun 2014 12:30:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A10782027D for ; Sun, 22 Jun 2014 12:30:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752164AbaFVMaU (ORCPT ); Sun, 22 Jun 2014 08:30:20 -0400 Received: from mail-we0-f176.google.com ([74.125.82.176]:53560 "EHLO mail-we0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751608AbaFVMaT (ORCPT ); Sun, 22 Jun 2014 08:30:19 -0400 Received: by mail-we0-f176.google.com with SMTP id u56so5554486wes.7 for ; Sun, 22 Jun 2014 05:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=OdRnnApe68az/bt9ae2MMjW2pLPpxKXBQMa06VUqW3g=; b=J9OXRzjKzZKeU+RHq6D2Mx955U8ztjhaI7gElK7GPd20tT8/6Su1kgIq+DBzEouIFg lOoopgbwRcEYN5TPsaf0Xkv45nZfjo7/x4WK4R+oI2eBTxzW+Wn4Xjz6wSIQncqBSQ+A iCNcAM1IIpEFHx9PumMECjkIc8NlnTiBQIOz6WDcZI0oYoqE3RsNfv1wukqMhs77Xc9Y /AvBGNegmdArSaEPs6R33h23VWauhtRGIz6jDxxW6G9U7dnnL03VJBMKp5/kDOQDEDxv g2Uiv1LTaA609x6Czsn359Akx0X09KONQ5wNHTnFbMhNzeijB25Lglq63cYe14LxoEdx 9FyQ== X-Received: by 10.194.122.169 with SMTP id lt9mr19229147wjb.16.1403440216161; Sun, 22 Jun 2014 05:30:16 -0700 (PDT) Received: from ramsan.of.borg (d54C1488D.access.telenet.be. [84.193.72.141]) by mx.google.com with ESMTPSA id ev9sm23160364wic.24.2014.06.22.05.30.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Jun 2014 05:30:15 -0700 (PDT) From: Geert Uytterhoeven To: Miao Xie , Chris Mason , Josef Bacik Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] Btrfs: Refactor btrfs_lock_cluster() to kill compiler warning Date: Sun, 22 Jun 2014 14:30:09 +0200 Message-Id: <1403440209-13370-1-git-send-email-geert@linux-m68k.org> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP fs/btrfs/extent-tree.c: In function ‘btrfs_lock_cluster’: fs/btrfs/extent-tree.c:6399: warning: ‘used_bg’ may be used uninitialized in this function - Replace "again: ... goto again;" by standard C "while (1) { ... }", - Move block not processed during the first iteration of the loop to the end of the loop, which allows to kill the "locked" variable, Signed-off-by: Geert Uytterhoeven --- Please review, compile tested only. --- fs/btrfs/extent-tree.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 99c253918208..e151c4a73d7b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -6397,36 +6397,34 @@ btrfs_lock_cluster(struct btrfs_block_group_cache *block_group, int delalloc) { struct btrfs_block_group_cache *used_bg; - bool locked = false; -again: + spin_lock(&cluster->refill_lock); - if (locked) { - if (used_bg == cluster->block_group) - return used_bg; + while (1) { + used_bg = cluster->block_group; + if (!used_bg) + return NULL; - up_read(&used_bg->data_rwsem); - btrfs_put_block_group(used_bg); - } + if (used_bg == block_group) + return used_bg; - used_bg = cluster->block_group; - if (!used_bg) - return NULL; + btrfs_get_block_group(used_bg); - if (used_bg == block_group) - return used_bg; + if (!delalloc) + return used_bg; - btrfs_get_block_group(used_bg); + if (down_read_trylock(&used_bg->data_rwsem)) + return used_bg; - if (!delalloc) - return used_bg; + spin_unlock(&cluster->refill_lock); + down_read(&used_bg->data_rwsem); - if (down_read_trylock(&used_bg->data_rwsem)) - return used_bg; + spin_lock(&cluster->refill_lock); + if (used_bg == cluster->block_group) + return used_bg; - spin_unlock(&cluster->refill_lock); - down_read(&used_bg->data_rwsem); - locked = true; - goto again; + up_read(&used_bg->data_rwsem); + btrfs_put_block_group(used_bg); + } } static inline void