From 6ddedca2180b095aacca0f628e0d03a32477f68f Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 22 Oct 2023 18:29:54 -0400 Subject: bcachefs: Guard against unknown compression options Since compression options now include compression level, proper validation is a bit more involved. This adds bch2_compression_opt_valid(), and plumbs it around appropriately. Signed-off-by: Kent Overstreet --- fs/bcachefs/compress.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'fs/bcachefs/compress.c') diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c index 1480b64547b0..0e3981f42526 100644 --- a/fs/bcachefs/compress.c +++ b/fs/bcachefs/compress.c @@ -708,3 +708,13 @@ void bch2_opt_compression_to_text(struct printbuf *out, if (opt.level) prt_printf(out, ":%u", opt.level); } + +int bch2_opt_compression_validate(u64 v, struct printbuf *err) +{ + if (!bch2_compression_opt_valid(v)) { + prt_printf(err, "invalid compression opt %llu", v); + return -BCH_ERR_invalid_sb_opt_compression; + } + + return 0; +} -- cgit v1.2.3