From nobody Tue Apr 7 20:08:11 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