Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3863972pxb; Mon, 1 Mar 2021 23:58:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7cmtM1l4es9xiLzwL9mo2TPBDoZpTR46Fn721N8tX3DsZIEjyw2DZbZxQghX3IAe6xBSr X-Received: by 2002:a17:906:a099:: with SMTP id q25mr19379754ejy.549.1614671899337; Mon, 01 Mar 2021 23:58:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614671899; cv=none; d=google.com; s=arc-20160816; b=m+mX5S+IaBwWXo7K6By1YzfDjwdwvjg2wS5AEfISPQYHjOezAclwcKhFPtN9dqXPHP 4NL2QTqUzo2zjsj140dSf2OmIdUO6TJajcKgJT0Pl0l/dwgvaIM44g7M4gerGasNgFvM LtS3ZtNPI9M/KjW5BmspUPGe5GAUIJU0ycZ+IADamxnB1a79diaQIXms4ysufdBx6bxa OZo9OYKUyuwVHFcEFBEzSYk4fk0/JxQZ05fZex1Vp8H47+zgvtqz6Ccs+Cp6RVmsuR9Q SrR34yBbX1kPMEPOYuIM5ptKjtkHe2eng12BU7abIOtKp3H1gJ2P5SgJ5evtQWL5ctg8 f3eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mOdGEpjRwwK4Bcgp6dvSKahqFdHGwUHswzkeAfkHsHc=; b=gks6OYQb0shWTRL7Ld+jS7RXa/xuQjVbhttkFCzG0kXu5WSJy3pc860aaOx5O3BpBS FuPAU8ZrY5mQri4jjXlRIfyfRaamKUNcFISM5yXWoiwaokHm4DAw6MGxIa6+7L2D4krg kHbdXIKcdQzMqOm+tZdYsIVxnMPEUxMJz4Olln9xTtfXadDKI1gUe39qyl3wtB2PljGL vr9NijwY84J+1WoBtvrqbQZq0NZ7xQ3bC5vnx6Ni9GcmgEVy5QgKhl2ixOOfIxUq1QY7 EbrJi5Ff3VLHIS4TXjftnzbZ8oGvG74BqBf5uCk77O9cj3s1rNMWWQxdb2c6ZV4PFDfw 2BRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BKMv8cyD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs2si12660190edb.459.2021.03.01.23.57.39; Mon, 01 Mar 2021 23:58:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BKMv8cyD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348409AbhCBBCX (ORCPT + 99 others); Mon, 1 Mar 2021 20:02:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:58764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240597AbhCASwm (ORCPT ); Mon, 1 Mar 2021 13:52:42 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 72C156502B; Mon, 1 Mar 2021 17:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614618813; bh=SZSyaRDm+wdvQ1Xi8YadFFBaQr8njyk7yGv9rRW3KGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BKMv8cyDu+IO7BmffWNgU2Sbii5GHTCT/VPPGss8Az1QUOtAv15MZSFThokc6J+A/ 2bqID5Pcdq3J6A5rnClhF9Ca87fgEjZcG/EN2gYtnz3cmu3mr5Xw9EwUfB+Nu7qTNj lMuyM62uAqB99v8X3CK2JRHhUIkr9DvVTMD+ddbE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Zhihao Cheng , David Sterba , Sasha Levin Subject: [PATCH 5.10 225/663] btrfs: clarify error returns values in __load_free_space_cache Date: Mon, 1 Mar 2021 17:07:53 +0100 Message-Id: <20210301161152.932812766@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhihao Cheng [ Upstream commit 3cc64e7ebfb0d7faaba2438334c43466955a96e8 ] Return value in __load_free_space_cache is not properly set after (unlikely) memory allocation failures and 0 is returned instead. This is not a problem for the caller load_free_space_cache because only value 1 is considered as 'cache loaded' but for clarity it's better to set the errors accordingly. Fixes: a67509c30079 ("Btrfs: add a io_ctl struct and helpers for dealing with the space cache") Reported-by: Hulk Robot Signed-off-by: Zhihao Cheng Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/free-space-cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index af0013d3df63f..ae4059ce2f84c 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -744,8 +744,10 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, while (num_entries) { e = kmem_cache_zalloc(btrfs_free_space_cachep, GFP_NOFS); - if (!e) + if (!e) { + ret = -ENOMEM; goto free_cache; + } ret = io_ctl_read_entry(&io_ctl, e, &type); if (ret) { @@ -764,6 +766,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, e->trim_state = BTRFS_TRIM_STATE_TRIMMED; if (!e->bytes) { + ret = -1; kmem_cache_free(btrfs_free_space_cachep, e); goto free_cache; } @@ -784,6 +787,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, e->bitmap = kmem_cache_zalloc( btrfs_free_space_bitmap_cachep, GFP_NOFS); if (!e->bitmap) { + ret = -ENOMEM; kmem_cache_free( btrfs_free_space_cachep, e); goto free_cache; -- 2.27.0