From patchwork Thu Jul 31 03:23:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 4653131 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 90C97C0338 for ; Thu, 31 Jul 2014 03:29:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C8D8F2018E for ; Thu, 31 Jul 2014 03:29:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED22C2015E for ; Thu, 31 Jul 2014 03:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756190AbaGaD3q (ORCPT ); Wed, 30 Jul 2014 23:29:46 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:42243 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756099AbaGaD3p (ORCPT ); Wed, 30 Jul 2014 23:29:45 -0400 X-IronPort-AV: E=Sophos;i="5.00,999,1396972800"; d="scan'208";a="33996461" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 31 Jul 2014 11:26:56 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s6V3TgNP008712 for ; Thu, 31 Jul 2014 11:29:42 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 31 Jul 2014 11:29:54 +0800 From: Gui Hecheng To: CC: Gui Hecheng Subject: [PATCH 3/3] btrfs-progs: fix improper return value check for is_existing_blk_or_reg_file Date: Thu, 31 Jul 2014 11:23:44 +0800 Message-ID: <1406777024-7647-3-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1406777024-7647-1-git-send-email-guihc.fnst@cn.fujitsu.com> References: <1406777024-7647-1-git-send-email-guihc.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 The function @is_existing_blk_or_reg_file has a return value of -errno, which indicate the @stat call fails with non-ENOENT errors. In this condition, we should not continue the following work. But -errno evaluates to true and will let the following work go. So we should judge more accurately whether the return value of @is_existing_blk_or_reg_file is > 0 or not to decide our behavior. Signed-off-by: Gui Hecheng --- utils.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/utils.c b/utils.c index 11250d9..1472e09 100644 --- a/utils.c +++ b/utils.c @@ -1595,22 +1595,29 @@ int get_label(const char *btrfs_dev, char *label) { int ret; - if (is_existing_blk_or_reg_file(btrfs_dev)) - ret = get_label_unmounted(btrfs_dev, label); - else + ret = is_existing_blk_or_reg_file(btrfs_dev); + if (!ret) ret = get_label_mounted(btrfs_dev, label); + else if (ret > 0) + ret = get_label_unmounted(btrfs_dev, label); return ret; } int set_label(const char *btrfs_dev, const char *label) { + int ret; + if (check_label(label)) return -1; - return is_existing_blk_or_reg_file(btrfs_dev) ? - set_label_unmounted(btrfs_dev, label) : - set_label_mounted(btrfs_dev, label); + ret = is_existing_blk_or_reg_file(btrfs_dev); + if (!ret) + ret = set_label_mounted(btrfs_dev, label); + else if (ret > 0) + ret = set_label_unmounted(btrfs_dev, label); + + return ret; } int btrfs_scan_block_devices(int run_ioctl)