public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Adarsh Das <adarshdas950@gmail.com>
To: clm@fb.com, dsterba@suse.com
Cc: terrelln@fb.com, linux-btrfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, Adarsh Das <adarshdas950@gmail.com>
Subject: [PATCH 1/4] btrfs: replace BUG() with error handling in compression.c
Date: Sat, 28 Feb 2026 00:01:08 +0530	[thread overview]
Message-ID: <20260227183111.9311-2-adarshdas950@gmail.com> (raw)
In-Reply-To: <20260227183111.9311-1-adarshdas950@gmail.com>

Replace BUG() calls with proper error handling. Where fs_info is
available, use btrfs_err() and return -EUCLEAN. Where fs_info is
not available, use WARN_ONCE() with the invalid type value so the
stack trace carries enough context for debugging.

Signed-off-by: Adarsh Das <adarshdas950@gmail.com>
---
 fs/btrfs/compression.c | 42 ++++++++++++------------------------------
 1 file changed, 12 insertions(+), 30 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 790518a8c803..29281aba925e 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -95,11 +95,9 @@ static int compression_decompress_bio(struct list_head *ws,
 	case BTRFS_COMPRESS_ZSTD: return zstd_decompress_bio(ws, cb);
 	case BTRFS_COMPRESS_NONE:
 	default:
-		/*
-		 * This can't happen, the type is validated several times
-		 * before we get here.
-		 */
-		BUG();
+		btrfs_err(cb_to_fs_info(cb), "invalid compression type %d",
+			  cb->compress_type);
+		return -EUCLEAN;
 	}
 }
 
@@ -116,11 +114,7 @@ static int compression_decompress(int type, struct list_head *ws,
 						dest_pgoff, srclen, destlen);
 	case BTRFS_COMPRESS_NONE:
 	default:
-		/*
-		 * This can't happen, the type is validated several times
-		 * before we get here.
-		 */
-		BUG();
+		return -EUCLEAN;
 	}
 }
 
@@ -703,11 +697,8 @@ static struct list_head *alloc_workspace(struct btrfs_fs_info *fs_info, int type
 	case BTRFS_COMPRESS_LZO:  return lzo_alloc_workspace(fs_info);
 	case BTRFS_COMPRESS_ZSTD: return zstd_alloc_workspace(fs_info, level);
 	default:
-		/*
-		 * This can't happen, the type is validated several times
-		 * before we get here.
-		 */
-		BUG();
+		btrfs_err(fs_info, "invalid compression type %d", type);
+		return ERR_PTR(-EUCLEAN);
 	}
 }
 
@@ -719,11 +710,8 @@ static void free_workspace(int type, struct list_head *ws)
 	case BTRFS_COMPRESS_LZO:  return lzo_free_workspace(ws);
 	case BTRFS_COMPRESS_ZSTD: return zstd_free_workspace(ws);
 	default:
-		/*
-		 * This can't happen, the type is validated several times
-		 * before we get here.
-		 */
-		BUG();
+		WARN_ONCE(1, "invalid compression type %d", type);
+		return;
 	}
 }
 
@@ -874,11 +862,8 @@ static struct list_head *get_workspace(struct btrfs_fs_info *fs_info, int type,
 	case BTRFS_COMPRESS_LZO:  return btrfs_get_workspace(fs_info, type, level);
 	case BTRFS_COMPRESS_ZSTD: return zstd_get_workspace(fs_info, level);
 	default:
-		/*
-		 * This can't happen, the type is validated several times
-		 * before we get here.
-		 */
-		BUG();
+		btrfs_err(fs_info, "invalid compression type %d", type);
+		return ERR_PTR(-EUCLEAN);
 	}
 }
 
@@ -925,11 +910,8 @@ static void put_workspace(struct btrfs_fs_info *fs_info, int type, struct list_h
 	case BTRFS_COMPRESS_LZO:  return btrfs_put_workspace(fs_info, type, ws);
 	case BTRFS_COMPRESS_ZSTD: return zstd_put_workspace(fs_info, ws);
 	default:
-		/*
-		 * This can't happen, the type is validated several times
-		 * before we get here.
-		 */
-		BUG();
+		btrfs_err(fs_info, "invalid compression type %d", type);
+		return;
 	}
 }
 
-- 
2.53.0


  reply	other threads:[~2026-02-27 18:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 18:31 [PATCH 0/4] btrfs: replace BUG() and BUG_ON() with error handling Adarsh Das
2026-02-27 18:31 ` Adarsh Das [this message]
2026-02-27 20:22   ` [PATCH 1/4] btrfs: replace BUG() with error handling in compression.c Qu Wenruo
2026-02-27 18:31 ` [PATCH 2/4] btrfs: clean coding style errors and warnings " Adarsh Das
2026-02-27 20:43   ` Qu Wenruo
2026-02-27 18:31 ` [PATCH 3/4] btrfs: replace BUG() and BUG_ON() with error handling in extent-tree.c Adarsh Das
2026-02-27 20:43   ` Qu Wenruo
2026-02-27 18:31 ` [PATCH 4/4] btrfs: clean coding style errors " Adarsh Das
2026-02-27 20:44   ` Qu Wenruo
2026-02-27 21:01 ` [PATCH 0/4] btrfs: replace BUG() and BUG_ON() with error handling Qu Wenruo

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=20260227183111.9311-2-adarshdas950@gmail.com \
    --to=adarshdas950@gmail.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=terrelln@fb.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