From nobody Sun Sep 7 12:17:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E290ECAAD5 for ; Fri, 2 Sep 2022 12:36:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236961AbiIBMgd (ORCPT ); Fri, 2 Sep 2022 08:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236945AbiIBMf3 (ORCPT ); Fri, 2 Sep 2022 08:35:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52EC7D9D64; Fri, 2 Sep 2022 05:28:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CB6C36212F; Fri, 2 Sep 2022 12:28:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1255C433C1; Fri, 2 Sep 2022 12:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121696; bh=6mqy5Wkl20w3CMC3oxYQb1A16d6We5aBAIxQMRwkoiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9j0otvSFSU0yvvzTRUvV33r6RfJrcxizPJzh9B00dLJFobsrnEIzJvuVr+XnMSiY Ay9hc70X91J1vqb5pi0hoRN6XEoeDhtRd6XACUzji1nMGulLWoPdnZDnE8tiSMF4fr W8/GEInCk7JfnA9Al3F+6v7yYUDVAPc2MRpx7cEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Filipe Manana , David Sterba Subject: [PATCH 5.4 36/77] btrfs: fix silent failure when deleting root reference Date: Fri, 2 Sep 2022 14:18:45 +0200 Message-Id: <20220902121404.848682885@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121403.569927325@linuxfoundation.org> References: <20220902121403.569927325@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Filipe Manana commit 47bf225a8d2cccb15f7e8d4a1ed9b757dd86afd7 upstream. At btrfs_del_root_ref(), if btrfs_search_slot() returns an error, we end up returning from the function with a value of 0 (success). This happens because the function returns the value stored in the variable 'err', which is 0, while the error value we got from btrfs_search_slot() is stored in the 'ret' variable. So fix it by setting 'err' with the error value. Fixes: 8289ed9f93bef2 ("btrfs: replace the BUG_ON in btrfs_del_root_ref wit= h proper error handling") CC: stable@vger.kernel.org # 5.16+ Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/root-tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c @@ -371,9 +371,10 @@ int btrfs_del_root_ref(struct btrfs_tran key.offset =3D ref_id; again: ret =3D btrfs_search_slot(trans, tree_root, &key, path, -1, 1); - if (ret < 0) + if (ret < 0) { + err =3D ret; goto out; - if (ret =3D=3D 0) { + } else if (ret =3D=3D 0) { leaf =3D path->nodes[0]; ref =3D btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref);