From 3e497af63725c8ef24f7f8d34d8fd7975142c71d Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Mon, 20 Jul 2026 17:42:21 +0900 Subject: [PATCH] ntfs: propagate compression context allocation errors ntfs_compress_block() returns -ENOMEM when its compression context cannot be allocated, but its unsigned return type turns the error into a large positive value. ntfs_write_cb() then hides the allocation failure. Use a signed return type and propagate negative errors to the caller. Reviewed-by: Hyunchul Lee Signed-off-by: Namjae Jeon --- fs/ntfs/compress.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c index fe1877b86f49..6b78a8efe3ac 100644 --- a/fs/ntfs/compress.c +++ b/fs/ntfs/compress.c @@ -1070,10 +1070,10 @@ static void ntfs_skip_position(struct compress_context *pctx, const int i) * * Returns the size of the compressed block, including the * header (minimal size is 2, maximum size is 4098) - * 0 if an error has been met. + * A negative error code if an error has been met. */ -static unsigned int ntfs_compress_block(const char *inbuf, const int bufsize, - char *outbuf) +static int ntfs_compress_block(const char *inbuf, const int bufsize, + char *outbuf) { struct compress_context *pctx; int i; /* current position */ @@ -1264,7 +1264,8 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages, char *outbuf = NULL, *pbuf, *inbuf; u32 compsz, p, insz = pages_per_cb << PAGE_SHIFT; s32 rounded, bio_size; - unsigned int sz, bsz; + int sz; + unsigned int bsz; bool fail = false, allzeroes; /* a single compressed zero */ static char onezero[] = {0x01, 0xb0, 0x00, 0x00}; @@ -1319,6 +1320,10 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages, bsz = insz - p; pbuf = &outbuf[compsz]; sz = ntfs_compress_block(&inbuf[p], bsz, pbuf); + if (sz < 0) { + err = sz; + goto out; + } /* fail if all the clusters (or more) are needed */ if (!sz || ((compsz + sz + vol->cluster_size + 2) > ni->itype.compressed.block_size))