public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: "Miquel Sabaté Solà" <mssola@mssola.com>, dsterba@suse.com
Cc: clm@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: return early if allocations fail on raid56
Date: Sat, 28 Feb 2026 07:20:13 +1030	[thread overview]
Message-ID: <00a3386c-e386-4cba-97f2-8142c16a4c50@gmx.com> (raw)
In-Reply-To: <20260227151759.704838-3-mssola@mssola.com>



在 2026/2/28 01:47, Miquel Sabaté Solà 写道:
> 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é Solà <mssola@mssola.com>

Again, the old pattern is just fine.

Thanks,
Qu

> ---
>   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 *rbio, int sector_nr,
>   
>   static int recover_sectors(struct btrfs_raid_bio *rbio)
>   {
> -	void **pointers = NULL;
> -	void **unmap_array = NULL;
> +	void **pointers;
> +	void **unmap_array;
>   	int sectornr;
>   	int ret = 0;
>   
> @@ -2105,11 +2105,15 @@ static int recover_sectors(struct btrfs_raid_bio *rbio)
>   	 * @unmap_array stores copy of pointers that does not get reordered
>   	 * during reconstruction so that kunmap_local works.
>   	 */
> +
>   	pointers = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS);
> +	if (!pointers)
> +		return -ENOMEM;
> +
>   	unmap_array = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS);
> -	if (!pointers || !unmap_array) {
> -		ret = -ENOMEM;
> -		goto out;
> +	if (!unmap_array) {
> +		kfree(pointers);
> +		return -ENOMEM;
>   	}
>   
>   	if (rbio->operation == BTRFS_RBIO_READ_REBUILD) {
> @@ -2126,7 +2130,6 @@ static int recover_sectors(struct btrfs_raid_bio *rbio)
>   			break;
>   	}
>   
> -out:
>   	kfree(pointers);
>   	kfree(unmap_array);
>   	return ret;
> @@ -2828,8 +2831,8 @@ static inline int is_data_stripe(struct btrfs_raid_bio *rbio, int stripe)
>   
>   static int recover_scrub_rbio(struct btrfs_raid_bio *rbio)
>   {
> -	void **pointers = NULL;
> -	void **unmap_array = NULL;
> +	void **pointers;
> +	void **unmap_array;
>   	int sector_nr;
>   	int ret = 0;
>   
> @@ -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 = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS);
> +	if (!pointers)
> +		return -ENOMEM;
> +
>   	unmap_array = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS);
> -	if (!pointers || !unmap_array) {
> -		ret = -ENOMEM;
> -		goto out;
> +	if (!unmap_array) {
> +		kfree(pointers);
> +		return -ENOMEM;
>   	}
>   
>   	for (sector_nr = 0; sector_nr < rbio->stripe_nsectors; sector_nr++) {


      reply	other threads:[~2026-02-27 20:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 15:17 [PATCH 0/2] btrfs: return early in allocation failures Miquel Sabaté Solà
2026-02-27 15:17 ` [PATCH 1/2] btrfs: return early if allocations fail on add_block_entry() Miquel Sabaté Solà
2026-02-27 20:49   ` Qu Wenruo
2026-02-27 15:17 ` [PATCH 2/2] btrfs: return early if allocations fail on raid56 Miquel Sabaté Solà
2026-02-27 20:50   ` Qu Wenruo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00a3386c-e386-4cba-97f2-8142c16a4c50@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mssola@mssola.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox