From patchwork Fri Jun 19 14:32:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 223722 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A943C433E1 for ; Fri, 19 Jun 2020 16:37:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E67A21527 for ; Fri, 19 Jun 2020 16:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592584639; bh=ilHl00Ind+MYDpzE63x8S6agboplY2CjLSDXuXLXyDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=SDOOE1rjE3mok2/49Lm2NPd7DnEhmUdQ+X6XvlEooWmHjOfwxI+OrzYi17KCldL1H HWoNL4ONeKxBiF/8Kyeb4oc7zG42J171nfvhRRacI60Et4DDSK8RDGKAkFoOP3eqB/ zgI3dc6cQO7yP/AEDUgiEq1Fnvem1K88X5UNzAoU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389075AbgFSQhP (ORCPT ); Fri, 19 Jun 2020 12:37:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:41168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389048AbgFSOsn (ORCPT ); Fri, 19 Jun 2020 10:48:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 21CDA2083B; Fri, 19 Jun 2020 14:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578123; bh=ilHl00Ind+MYDpzE63x8S6agboplY2CjLSDXuXLXyDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wBF38mPBXqEFcq3uq4wZx+gyaeRTmeAptatqCjS8wBughjYSaMr3QeTndtyC59sFx Zv5EX+BpD6UaKO0aAZGIue7YhSSLLrmp7+nGuIYLhOEXGwL5XNbIUqDknpzvuexAVQ vtczoGGRCZIM9ZI33RTW1YPbY7YhYNEW9mTLfqXw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 4.14 090/190] btrfs: do not ignore error from btrfs_next_leaf() when inserting checksums Date: Fri, 19 Jun 2020 16:32:15 +0200 Message-Id: <20200619141638.088594819@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141633.446429600@linuxfoundation.org> References: <20200619141633.446429600@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Filipe Manana [ Upstream commit 7e4a3f7ed5d54926ec671bbb13e171cfe179cc50 ] We are currently treating any non-zero return value from btrfs_next_leaf() the same way, by going to the code that inserts a new checksum item in the tree. However if btrfs_next_leaf() returns an error (a value < 0), we should just stop and return the error, and not behave as if nothing has happened, since in that case we do not have a way to know if there is a next leaf or we are currently at the last leaf already. So fix that by returning the error from btrfs_next_leaf(). Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/file-item.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 717d82d51bb1..edd5f152e448 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -795,10 +795,12 @@ again: nritems = btrfs_header_nritems(path->nodes[0]); if (!nritems || (path->slots[0] >= nritems - 1)) { ret = btrfs_next_leaf(root, path); - if (ret == 1) + if (ret < 0) { + goto out; + } else if (ret > 0) { found_next = 1; - if (ret != 0) goto insert; + } slot = path->slots[0]; } btrfs_item_key_to_cpu(path->nodes[0], &found_key, slot);