Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2404967pxu; Mon, 7 Dec 2020 05:56:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyb2g/0x8Zt6XHBJL3dspCO/fgScEIa0Tv++oXps0FwR3632sOA2rmQyGdYnhaRrDlLbemR X-Received: by 2002:a50:9d4f:: with SMTP id j15mr20191807edk.69.1607349376785; Mon, 07 Dec 2020 05:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607349376; cv=none; d=google.com; s=arc-20160816; b=aDKbFcN+VULmv/Jx6P5fc4dzI7rN4/fg/1amqU9QDiL796bVVGdqh9CMrITBvHt3aJ JFiRZDM00hDU3EMK6jDywTPxwHqPSTBoMRlLyhf95IGN3p8EnHYzZTvAN1tF1bRigoF/ 6ZU6I34oUQOasasHfVlNfgureA/+1Ru8shboTdIlSeVt//rbNfgxKo4rBXEL/Ba8C1NC T7eFI3JBvl9akndKz/7wQ6i6YYsn055YPEeZChMh540B+HvVayAD61JUgUdpUkUGN82k acLW6CcfojrdKxNgxGVle9RYbW9ZVqijTNIGQWZCsNwAHkOSli/tlGTJ955TrZvGewK7 fDPQ== 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 :message-id:date:subject:cc:to:from; bh=WFMSFmJ7rJ6AO6Cu31l9vIhzNDso/fkra35ocm8DqxE=; b=tGzbzcL2ahQukLOVkJS/moAqFN2TUm1zUtxVxjvP/9l4ujt31e4eNwyHNMHSNtz9zX kdnTkCk4qQ8wY8cNpado87GJ0xFUuR0wxmwJ+w7MY2ARSNNeH4UlhEI9WMuMribsKMUX Y7lu1aCTy+da6ydNYMr1u2Pv3/GSViM1UU0wlEWSJzAknJm836fG2Pcd0Ga+NEe4/CQP tmKdTp+Bwr6OJxilq2hc2gZ/HL9IjBN+9q4qBCHbX/LE82ssddZB7pV+0HL6Jxo2+FB5 P2OIq6DS6XGp1OTbOxp0tQwTJ9k8MZMqeEbOyQXFMLs4WH3CKA6s1IOIgTKP82SV2fai codg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l34si7873735ede.416.2020.12.07.05.55.45; Mon, 07 Dec 2020 05:56:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726508AbgLGNyE (ORCPT + 99 others); Mon, 7 Dec 2020 08:54:04 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9029 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726007AbgLGNyE (ORCPT ); Mon, 7 Dec 2020 08:54:04 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CqPry4HVtzhkhd; Mon, 7 Dec 2020 21:52:50 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Mon, 7 Dec 2020 21:53:13 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH v2] btrfs: free-space-cache: Fix error return code in __load_free_space_cache Date: Mon, 7 Dec 2020 21:56:12 +0800 Message-ID: <20201207135612.4132398-1-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix to return the error code(instead always 0) when memory allocating failed in __load_free_space_cache(). This lacks the analysis of consequences, so there's only one caller and that will treat values <=0 as 'cache not loaded'. There's no functional change but otherwise the error values should be there for clarity. Fixes: a67509c30079f4c50 ("Btrfs: add a io_ctl struct and helpers for dealing with the space cache") Reported-by: Hulk Robot Signed-off-by: Zhihao Cheng --- 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 af0013d3df63..ae4059ce2f84 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.25.4