linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Fix an error handling path in btrfs_defrag_leaves()
@ 2022-12-12 20:01 Christophe JAILLET
  2022-12-13 18:45 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-12-12 20:01 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, Chris Mason,
	linux-btrfs

All error handling paths end to 'out', except this memory allocation
failure.

This is spurious. So branch to the error handling path also in this case.
It will add a call to:
	memset(&root->defrag_progress, 0,
	       sizeof(root->defrag_progress));

Fixes: 6702ed490ca0 ("Btrfs: Add run time btree defrag, and an ioctl to force btree defrag")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is completely speculative.

Review with care !
---
 fs/btrfs/defrag.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
index 0a3c261b69c9..d81b764a7644 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
@@ -358,8 +358,10 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 		goto out;
 
 	path = btrfs_alloc_path();
-	if (!path)
-		return -ENOMEM;
+	if (!path) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	level = btrfs_header_level(root->node);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs: Fix an error handling path in btrfs_defrag_leaves()
  2022-12-12 20:01 [PATCH] btrfs: Fix an error handling path in btrfs_defrag_leaves() Christophe JAILLET
@ 2022-12-13 18:45 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2022-12-13 18:45 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-kernel,
	kernel-janitors, Chris Mason, linux-btrfs

On Mon, Dec 12, 2022 at 09:01:43PM +0100, Christophe JAILLET wrote:
> All error handling paths end to 'out', except this memory allocation
> failure.
> 
> This is spurious. So branch to the error handling path also in this case.
> It will add a call to:
> 	memset(&root->defrag_progress, 0,
> 	       sizeof(root->defrag_progress));
> 
> Fixes: 6702ed490ca0 ("Btrfs: Add run time btree defrag, and an ioctl to force btree defrag")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This patch is completely speculative.
> 
> Review with care !

I think it's correct, using goto for cleanup is for consistency and the
memset is not necessary on error paths but again for consistency with
what other types of errors in the functions lead to. Added to misc-next,
thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-13 18:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-12 20:01 [PATCH] btrfs: Fix an error handling path in btrfs_defrag_leaves() Christophe JAILLET
2022-12-13 18:45 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).