From nobody Tue Apr 7 18:48:14 2026 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0A491A23AC; Fri, 27 Feb 2026 15:18:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772205505; cv=none; b=Iy0BrtdyQ0VoiGRWjiw/Hr154PPa5gvY1/j79e4wBaC/MNyU6gkrXu4Fxhx7c8qYNYYqCDQluFQZMhm/JecNgSEXXoACrhaYhYQf23XS79fL1CxnvhEoV3Xfm4h5aWNVzLYQ3cltaETmUtgKqPr/df6Mwitk6Rc2zIZwqgfc354= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772205505; c=relaxed/simple; bh=c+EC9wP2LQZS+mnUdbL5ddZKP7WXJEsGwEj/Gp20W3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Trs6unRreUuoXSSjpVMuJWI0ylqjnbGPSMTrNGa7ispnVA+OHqZBXxoyrEqC5/YTXSL/ogcd68AQraRYQGfkgHN7OlxKLEBe4zRuVztMLjEm8irKdJH2emkrK/bg/JTQfE5usURjjFLlv+tiytocA2pKpLVlqwEfc2/RSU/jTzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mssola.com; spf=fail smtp.mailfrom=mssola.com; dkim=pass (2048-bit key) header.d=mssola.com header.i=@mssola.com header.b=1I8Fs3oS; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mssola.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=mssola.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mssola.com header.i=@mssola.com header.b="1I8Fs3oS" Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4fMsQz0Z97z9tFZ; Fri, 27 Feb 2026 16:18:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mssola.com; s=MBO0001; t=1772205499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i/8R02XIRzy8sQhuDCMP6q+5Q1Yj+EuHXolkMlvZNbk=; b=1I8Fs3oS9bAnsUlrIUe2z0ytPJcLZqzhYGiOGxN/DXALphIrOmP+57piEgEQBvUmrgQ2oL DdIc9HFyM280eDJR9EkasYM6bUrXkKTAF9rii0EwsfPZbwVXZgws9EP1ElaVLF6E+iQndY chffNDU4PCfZ5v6qDPh0vfAmMUbdtGOt0uOFYQ39YXVa+WFwOvDIaDyX6qOAjZYeR4mbjx q9TmqUYPSKEoMiuhh+ul6DCwgh4zr6tlVKS1bxn1dQT5P5UPCxgxo+mnZW/RgprhdY/pqB cEg5o8Xr/btQRIUYqVQ41LNUZNJnzUBKK9MxaDBuPy3NaNG3g5i0QKVZZa/7zA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=softfail (outgoing_mbo_mout: 2001:67c:2050:b231:465::1 is neither permitted nor denied by domain of mssola@mssola.com) smtp.mailfrom=mssola@mssola.com From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= To: dsterba@suse.com Cc: clm@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Subject: [PATCH 1/2] btrfs: return early if allocations fail on add_block_entry() Date: Fri, 27 Feb 2026 16:17:58 +0100 Message-ID: <20260227151759.704838-2-mssola@mssola.com> In-Reply-To: <20260227151759.704838-1-mssola@mssola.com> References: <20260227151759.704838-1-mssola@mssola.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4fMsQz0Z97z9tFZ In add_block_entry(), if the allocation of 're' fails, return right away instead of trying to allocate 'be' next. This also removes a useless kfree() call. Signed-off-by: Miquel Sabat=C3=A9 Sol=C3=A0 --- fs/btrfs/ref-verify.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c index f78369ff2a66..7b4d52db7897 100644 --- a/fs/btrfs/ref-verify.c +++ b/fs/btrfs/ref-verify.c @@ -246,14 +246,16 @@ static struct block_entry *add_block_entry(struct btr= fs_fs_info *fs_info, u64 bytenr, u64 len, u64 root_objectid) { - struct block_entry *be =3D NULL, *exist; - struct root_entry *re =3D NULL; + struct block_entry *be, *exist; + struct root_entry *re; =20 re =3D kzalloc_obj(struct root_entry, GFP_NOFS); + if (!re) + return ERR_PTR(-ENOMEM); + be =3D kzalloc_obj(struct block_entry, GFP_NOFS); - if (!be || !re) { + if (!be) { kfree(re); - kfree(be); return ERR_PTR(-ENOMEM); } be->bytenr =3D bytenr; --=20 2.53.0 From nobody Tue Apr 7 18:48:14 2026 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33A7643D4EE; Fri, 27 Feb 2026 15:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772205508; cv=none; b=gEoyLJOCneZBZmYoJ4JXdnm06y/SzdFM8JySoqrfHttF+d5q6/dpMMf1+yu33KChHEN4Bk8/Ix8AQaRKhMJ6sRSWVqvfYKn1YCeINeYFgLfFtIkUQ7GLdGwQj3L6R4iC4JTi8HyzJNTsBJzevIWVrszxkVXBb5erJcOGZdKckB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772205508; c=relaxed/simple; bh=fl7jQGTvsC3ojATpqZT9R/QFVdjDoWbg5HqK9AjFOnE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UyJHldF6D/bmA1KWtCKM1OeKwRkXyKbJc5HHF5qgXwU4RMzrZKSMQCWerNHij0sZf4HaFvM3QfTGd/tlu23NcFwXFJG6aU9c8vjPldwDM9n3iAu4VZL36E3IR/tCu+wu2UWAdDHGQZB5x7WngR7+3vr32kq23ajPUhVbihKBryQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mssola.com; spf=fail smtp.mailfrom=mssola.com; dkim=pass (2048-bit key) header.d=mssola.com header.i=@mssola.com header.b=I5Mwv879; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mssola.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=mssola.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mssola.com header.i=@mssola.com header.b="I5Mwv879" Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4fMsR144x0z9tdd; Fri, 27 Feb 2026 16:18:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mssola.com; s=MBO0001; t=1772205501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z2gr55nK34t+qwZft7veoNCYKCfapDhr2mloccIQd3E=; b=I5Mwv879ZWzdczKLrD32izj+kLCCQzBirrw7tLJMIVlLkg6vO0zzXBV3K7zxi1dZ1neRpw 3DwbQX/cqyTQfi0inpIkCQilGfyzWkkdF+pqqdyyroMBqWAB7iiq0kc0nSMoQelPaC4yEa ZMJ9z6vzC4iO+2tgYwMKLowI7tvYTJYGrk7E46y0vzpjZzIL02imX52t1Bsc6j1MzN0s/V hqXqduQhELyVoSCa9mGxau7PhAyLylsPjRFo+S2TBSDVEC0lZw55GSye5pNhASJk370J2Z jzLWgPDqUdeAJXEyvBe9Of+LjCQG57saoBpVCEURMJZhTxFLi9rZu0b/soOPpw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=softfail (outgoing_mbo_mout: 2001:67c:2050:b231:465::1 is neither permitted nor denied by domain of mssola@mssola.com) smtp.mailfrom=mssola@mssola.com From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= To: dsterba@suse.com Cc: clm@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Subject: [PATCH 2/2] btrfs: return early if allocations fail on raid56 Date: Fri, 27 Feb 2026 16:17:59 +0100 Message-ID: <20260227151759.704838-3-mssola@mssola.com> In-Reply-To: <20260227151759.704838-1-mssola@mssola.com> References: <20260227151759.704838-1-mssola@mssola.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4fMsR144x0z9tdd In both the recover_sectors() and the recover_scrub_rbio() functions we initialized two pointers by allocating them, and then returned early if either of them failed. But we can simply allocate the first one and do the check, and repeat for the second pointer. This way we return earlier on allocation failures, and we don't perform unneeded kfree() calls. Signed-off-by: Miquel Sabat=C3=A9 Sol=C3=A0 --- fs/btrfs/raid56.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index e31d57d6ab1e..c8ece97259e3 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -2094,8 +2094,8 @@ static int recover_vertical(struct btrfs_raid_bio *rb= io, int sector_nr, =20 static int recover_sectors(struct btrfs_raid_bio *rbio) { - void **pointers =3D NULL; - void **unmap_array =3D NULL; + void **pointers; + void **unmap_array; int sectornr; int ret =3D 0; =20 @@ -2105,11 +2105,15 @@ static int recover_sectors(struct btrfs_raid_bio *r= bio) * @unmap_array stores copy of pointers that does not get reordered * during reconstruction so that kunmap_local works. */ + pointers =3D kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); + if (!pointers) + return -ENOMEM; + unmap_array =3D kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); - if (!pointers || !unmap_array) { - ret =3D -ENOMEM; - goto out; + if (!unmap_array) { + kfree(pointers); + return -ENOMEM; } =20 if (rbio->operation =3D=3D BTRFS_RBIO_READ_REBUILD) { @@ -2126,7 +2130,6 @@ static int recover_sectors(struct btrfs_raid_bio *rbi= o) break; } =20 -out: kfree(pointers); kfree(unmap_array); return ret; @@ -2828,8 +2831,8 @@ static inline int is_data_stripe(struct btrfs_raid_bi= o *rbio, int stripe) =20 static int recover_scrub_rbio(struct btrfs_raid_bio *rbio) { - void **pointers =3D NULL; - void **unmap_array =3D NULL; + void **pointers; + void **unmap_array; int sector_nr; int ret =3D 0; =20 @@ -2839,11 +2842,15 @@ static int recover_scrub_rbio(struct btrfs_raid_bio= *rbio) * @unmap_array stores copy of pointers that does not get reordered * during reconstruction so that kunmap_local works. */ + pointers =3D kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); + if (!pointers) + return -ENOMEM; + unmap_array =3D kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS); - if (!pointers || !unmap_array) { - ret =3D -ENOMEM; - goto out; + if (!unmap_array) { + kfree(pointers); + return -ENOMEM; } =20 for (sector_nr =3D 0; sector_nr < rbio->stripe_nsectors; sector_nr++) { --=20 2.53.0