From patchwork Wed Nov 6 23:15:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 3149731 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 A3725BEEB3 for ; Wed, 6 Nov 2013 23:17:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D9CAB2031C for ; Wed, 6 Nov 2013 23:17:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0493220303 for ; Wed, 6 Nov 2013 23:17:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752192Ab3KFXQc (ORCPT ); Wed, 6 Nov 2013 18:16:32 -0500 Received: from sandeen.net ([63.231.237.45]:56129 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751902Ab3KFXP6 (ORCPT ); Wed, 6 Nov 2013 18:15:58 -0500 Received: by sandeen.net (Postfix, from userid 500) id B5C52654E64B; Wed, 6 Nov 2013 17:15:57 -0600 (CST) From: Eric Sandeen To: linux-btrfs@vger.kernel.org Subject: [PATCH 13/16] btrfs-progs: check btrfs_scan_one_device in btrfs_scan_lblkid() Date: Wed, 6 Nov 2013 17:15:52 -0600 Message-Id: <1383779755-18228-14-git-send-email-sandeen@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1383779755-18228-1-git-send-email-sandeen@redhat.com> References: <1383779755-18228-1-git-send-email-sandeen@redhat.com> 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.9 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 Even if it's "definitely" btrfs at this point, btrfs_scan_one_device could fail for other reasons. Check the return value, warn if it fails, and skip the device register. Resolves-Coverity-CID: 1125925 Signed-off-by: Eric Sandeen reviewed-by: Anand Jain --- utils.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/utils.c b/utils.c index 8471148..ecacc29 100644 --- a/utils.c +++ b/utils.c @@ -1937,6 +1937,7 @@ int test_skip_this_disk(char *path) int btrfs_scan_lblkid(int update_kernel) { int fd = -1; + int ret; u64 num_devices; struct btrfs_fs_devices *tmp_devices; blkid_dev_iterate iter = NULL; @@ -1965,8 +1966,14 @@ int btrfs_scan_lblkid(int update_kernel) printf("ERROR: could not open %s\n", path); continue; } - btrfs_scan_one_device(fd, path, &tmp_devices, + ret = btrfs_scan_one_device(fd, path, &tmp_devices, &num_devices, BTRFS_SUPER_INFO_OFFSET); + if (ret) { + printf("ERROR: could not scan %s\n", path); + close (fd); + continue; + } + close(fd); if (update_kernel) btrfs_register_one_device(path);