From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 394A33451B3 for ; Fri, 27 Feb 2026 18:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772217090; cv=none; b=tU2G1ofAIg5ZEvW0n8z1FFqEiRn0C4lii+w+GARhibPoa51ZQy6r6/8f26AvvhjjksnGqQWSPIthH+4u4bB4C8Uj0gbqSwyKNzQMD3tofPXXASNn1DwsYH/Fxymtceu3IqW27R1SY7NgdAv4uqprb96DppKlXiDy/CgUVWWWlhg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772217090; c=relaxed/simple; bh=YkEWqnBAPzrqci0BPAz5n9V4vIu9oUwhi4bREqwiwYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d6H0Y/AeN4cZEzi696UbK6Wk/0Hvm40HWFaoeHMmyZgGK21788OoMGSYywMfWd/S7Vf50r8y4Iy8ew0qarEsRHDORMXnKVsWP69k/2AmYrBb8alpT6p9rGVariP77tsiWxptvv7VI4f9QssGMXWECW8UEQ56qKoIXL2OftNBAWs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G9WZ8ez7; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G9WZ8ez7" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2ad617d5b80so15756735ad.1 for ; Fri, 27 Feb 2026 10:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772217089; x=1772821889; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rbJVYmXAbJJyKUBv1gVLWbj/RUC93TROXsUjXVfF1X4=; b=G9WZ8ez7OTtIMboZWnY7fu5mtitALVvtOI4lEipqXwSkiC5OpPEJajDvfJfkp2Dcbi YG4Kt/j/Eg0w+3OEbrz2duGZoO9mMt/FB8ci61qsJwnvnTK3s5chKX2vAM+US3YVPXv5 52h2Md6U6Ng0lHSkZVn0MuYPTf3NUOYkAc42beUexHuVXXcfJAT0qoFkyQ8dYtCrQ8bj dPwuCZepJpO2a+Tdv2SUJGwdu9gy/ZXekco3fhLKNMe19Cwb5SFMVy6JZzE7qT5SS6Aj FsOxRg4hXNNCieBiKg9mc7rb/jqsPKEg7nuUz8RylVp5Rk5U6Psu1UnWzx4T7JQTsoUb Do6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772217089; x=1772821889; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rbJVYmXAbJJyKUBv1gVLWbj/RUC93TROXsUjXVfF1X4=; b=frbJa9+uRu2Z4c/+AzDHJAHT3/cfdgIhYwnENnfSluB8FfbfMg17bVMwycRAzhNZ1s 7qTIwst+Y3KbtgeYXcFSDsGAUxTGqu7hnk/GmG+fsS03BDNUxM6oggeYYYFWCosZQb3m wfZZrTMqW/Vzrfd1CgjsdULQTl41G6EjwhxDJlRGhELwpnxkF1CykplnvmnW+I9TZDW3 cvo7P5VNPrGfKAGilELBl0P6pBT8ONnOXLoLcaZp6yxZEXRZkvj3W6hKK6hXLLzNrq3s M7yTh8FiwBiE6w5mYX9LnOe7PR1/aJ5fh6sLJewcSN3ZGpHzIpDOtayo4Mnr1cZ6m92E 1rwA== X-Forwarded-Encrypted: i=1; AJvYcCXySh/KPlGd0SO9HMFhdtXnlVRyjKQ4qgHS/8+sbh6i0Q65F8yNdJk4sV2FP4PZbtKiTwK+YyQZxtqwIZo=@vger.kernel.org X-Gm-Message-State: AOJu0YzMZ15RYZd3ZIDXeflpuMaGIluc6n816FD+0+/mmHn5ozleYhe6 XKLXpuyQi8IfyHo5XV2ckZp8Qo9LhEycI+aduHkibeSmUc+vQUPkkurd X-Gm-Gg: ATEYQzxAHGJTjFKRGn/TnS3vydZkWUD1dJNJgI7iuGmEauVH0RC9BmsmGIjl6g5DKym VsaYZTrVem3qB3czKl5kR/63EvyakgHQl4cQqP1j7/FAeykXwgE4nBFGIZul6oS5pPsUr6mHbjU TIZyGuUVa4l/j93gGI/59okwUvgU8sPhpOIAMfVX1IOa2ib1IX9vQd/94Okeg685F8fKAT01NoP SvIS6n15ao72XFDbzLSUCPPdmBMrrLSY+myP3Di6O76cdeMKFZ4uQ3OuvPFQP7QDDKDw4652tIi J6pxe29riskzFe3ihnXIy+gYMU2SUa6y8Bm20iOruriMVMP9vRp6H1gZAManutTxdCS10hHRmCx mlNZjgtSE2vLkMg9n/HoZgneus4vNDyLSU+0fLtkKXENNFrSWeNeuWI9keStTR94yGEyjmWPSu2 gwpaThe/jOGtUZvWDlCHniHu4e X-Received: by 2002:a17:902:ce84:b0:2ad:bd4c:9d with SMTP id d9443c01a7336-2ae2e3edc27mr43025325ad.3.1772217088429; Fri, 27 Feb 2026 10:31:28 -0800 (PST) Received: from archlinux ([103.208.68.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb5dbad2sm61932485ad.34.2026.02.27.10.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 10:31:28 -0800 (PST) From: Adarsh Das To: clm@fb.com, dsterba@suse.com Cc: terrelln@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Adarsh Das Subject: [PATCH 1/4] btrfs: replace BUG() with error handling in compression.c Date: Sat, 28 Feb 2026 00:01:08 +0530 Message-ID: <20260227183111.9311-2-adarshdas950@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227183111.9311-1-adarshdas950@gmail.com> References: <20260227183111.9311-1-adarshdas950@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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