[PATCH v2] btrfs: Add missing sctx check in cleanup path

Hongling Zeng posted 1 patch 1 week, 4 days ago
fs/btrfs/send.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] btrfs: Add missing sctx check in cleanup path
Posted by Hongling Zeng 1 week, 4 days ago
Add sctx NULL check in the for loop condition of the sort_clone_roots
cleanup path for consistency with the else branch

Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
Suggested-by: David Sterba <dsterba@suse.cz>
---
 Change in v2:
 -Uses the same pattern: for (i = 0; sctx && i < clone_sources_to_rollback; i++)
  ,suggested by David
---
 fs/btrfs/send.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 3ae480c7474b..297704edf1b4 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -8251,7 +8251,7 @@ long btrfs_ioctl_send(struct btrfs_root *send_root, const struct btrfs_ioctl_sen
 	}
 
 	if (sort_clone_roots) {
-		for (i = 0; i < sctx->clone_roots_cnt; i++) {
+		for (i = 0; sctx && i < sctx->clone_roots_cnt; i++) {
 			btrfs_root_dec_send_in_progress(
 					sctx->clone_roots[i].root);
 			btrfs_put_root(sctx->clone_roots[i].root);
-- 
2.25.1
Re: [PATCH v2] btrfs: Add missing sctx check in cleanup path
Posted by David Sterba 5 days, 9 hours ago
On Tue, Jul 14, 2026 at 09:28:50AM +0800, Hongling Zeng wrote:
> Add sctx NULL check in the for loop condition of the sort_clone_roots
> cleanup path for consistency with the else branch
> 
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> Suggested-by: David Sterba <dsterba@suse.cz>

Added to for-next, thanks.
Re: [PATCH v2] btrfs: Add missing sctx check in cleanup path
Posted by Boris Burkov 1 week, 1 day ago
On Tue, Jul 14, 2026 at 09:28:50AM +0800, Hongling Zeng wrote:
> Add sctx NULL check in the for loop condition of the sort_clone_roots
> cleanup path for consistency with the else branch
> 
Reviewed-by: Boris Burkov <boris@bur.io>
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> Suggested-by: David Sterba <dsterba@suse.cz>
> ---
>  Change in v2:
>  -Uses the same pattern: for (i = 0; sctx && i < clone_sources_to_rollback; i++)
>   ,suggested by David
> ---
>  fs/btrfs/send.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
> index 3ae480c7474b..297704edf1b4 100644
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -8251,7 +8251,7 @@ long btrfs_ioctl_send(struct btrfs_root *send_root, const struct btrfs_ioctl_sen
>  	}
>  
>  	if (sort_clone_roots) {
> -		for (i = 0; i < sctx->clone_roots_cnt; i++) {
> +		for (i = 0; sctx && i < sctx->clone_roots_cnt; i++) {
>  			btrfs_root_dec_send_in_progress(
>  					sctx->clone_roots[i].root);
>  			btrfs_put_root(sctx->clone_roots[i].root);
> -- 
> 2.25.1
>