erofs: improve decompression error reporting
Subsystems (2)
PATCH 1/4 erofs: improve decompression error reporting
Change the return type of decompress() from int to const char * to provide more informative error diagnostics:
- A NULL return indicates successful decompression;
- If IS_ERR(ptr) is true, the return value encodes a standard negative errno (e.g., -ENOMEM, -EOPNOTSUPP) identifying the specific error;
- Otherwise, a non-NULL return points to a human-readable error string, and the corresponding error code should be treated as -EFSCORRUPTED.
--- fs/erofs/compress.h | 4 ++-- fs/erofs/decompressor.c | 20 +++++++++----------- fs/erofs/decompressor_deflate.c | 10 ++++------ fs/erofs/decompressor_lzma.c | 10 ++++------ fs/erofs/decompressor_zstd.c | 12 ++++-------- fs/erofs/zdata.c | 21 +++++++++++++++++---- 6 files changed, 40 insertions(+), 37 deletions(-)
fs/erofs/compress.h +2 -2
@@ -23,8 +23,8 @@ struct z_erofs_decompress_req {struct z_erofs_decompressor {int (*config)(struct super_block *sb,struct erofs_super_block *dsb,void *data,int size); -int (*decompress)(struct z_erofs_decompress_req *rq, -struct page **pagepool); +const char *(*decompress)(struct z_erofs_decompress_req *rq, +struct page **pagepool);int (*init)(void );void (*exit)(void );char *name;
fs/erofs/decompressor.c +9 -11
@@ -235,8 +235,6 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst rq->inputsize, rq->outputsize);if (ret != rq->outputsize) { -erofs_err (rq->sb,"failed to decompress %d in[%u, %u] out[%u]" , - ret, rq->inputsize, inputmargin, rq->outputsize);if (ret >=0 )memset (out + ret,0 , rq->outputsize - ret); ret = -EFSCORRUPTED ;
@@ -257,8 +255,8 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dstreturn ret; } -static int z_erofs_lz4_decompress (struct z_erofs_decompress_req *rq, -struct page **pagepool) +static const char *z_erofs_lz4_decompress (struct z_erofs_decompress_req *rq, +struct page **pagepool) {unsigned int dst_maptype;void *dst;
@@ -273,14 +271,14 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,/* general decoding path which can be used for all cases */ ret =z_erofs_lz4_prepare_dstpages (rq, pagepool);if (ret <0 ) -return ret; +return ERR_PTR (ret);if (ret >0 ) { dst =page_address (*rq->out); dst_maptype =1 ; }else { dst =erofs_vm_map_ram (rq->out, rq->outpages);if (!dst) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); dst_maptype =2 ; } }
@@ -289,11 +287,11 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,kunmap_local (dst); else if (dst_maptype == 2) vm_unmap_ram(dst, rq->outpages); -return ret; +return ERR_PTR (ret); } -static int z_erofs_transform_plain (struct z_erofs_decompress_req *rq, -struct page **pagepool) +static const char *z_erofs_transform_plain (struct z_erofs_decompress_req *rq, +struct page **pagepool) {const unsigned int nrpages_in = rq->inpages, nrpages_out = rq->outpages;const unsigned int bs = rq->sb->s_blocksize;
@@ -301,7 +299,7 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,u8 *kin;if (rq->outputsize > rq->inputsize) -return -EOPNOTSUPP ; +return ERR_PTR (-EOPNOTSUPP );if (rq->alg ==Z_EROFS_COMPRESSION_INTERLACED ) { cur = bs - (rq->pageofs_out & (bs -1 )); pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK ;
@@ -341,7 +339,7 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,kunmap_local (kin); }DBG_BUGON (ni > nrpages_in); -return 0 ; +return NULL ; } int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
fs/erofs/decompressor_deflate.c +4 -6
@@ -157,8 +157,6 @@ static int __z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ;if (zerr ==Z_STREAM_END && !rq->outputsize)break ; -erofs_err (sb,"failed to decompress %d in[%u] out[%u]" , - zerr, rq->inputsize, rq->outputsize); err = -EFSCORRUPTED ;break ; }
@@ -178,8 +176,8 @@ static int __z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,return err; } -static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, -struct page **pgpl) +static const char *z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) {#ifdef CONFIG_EROFS_FS_ZIP_ACCEL int err;
@@ -187,11 +185,11 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,if (!rq->partial_decoding) { err =z_erofs_crypto_decompress (rq, pgpl);if (err != -EOPNOTSUPP ) -return err; +return ERR_PTR (err); }#endif -return __z_erofs_deflate_decompress (rq, pgpl); +return ERR_PTR (__z_erofs_deflate_decompress (rq, pgpl)); }const struct z_erofs_decompressor z_erofs_deflate_decomp = {
fs/erofs/decompressor_lzma.c +4 -6
@@ -146,8 +146,8 @@ static int z_erofs_load_lzma_config(struct super_block *sb,return err; } -static int z_erofs_lzma_decompress (struct z_erofs_decompress_req *rq, -struct page **pgpl) +static const char *z_erofs_lzma_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) {struct super_block *sb = rq->sb;struct z_erofs_stream_dctx dctx = { .rq = rq, .no =-1 , .ni =0 };
@@ -162,7 +162,7 @@ static int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, min(rq->inputsize, sb->s_blocksize - rq->pageofs_in));if (err) {kunmap_local (dctx.kin); -return err; +return ERR_PTR (err); }/* 2. get an available lzma context */
@@ -207,8 +207,6 @@ static int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,if (xz_err !=XZ_OK ) {if (xz_err ==XZ_STREAM_END && !rq->outputsize)break ; -erofs_err (sb,"failed to decompress %d in[%u] out[%u]" , - xz_err, rq->inputsize, rq->outputsize); err = -EFSCORRUPTED ;break ; }
@@ -223,7 +221,7 @@ static int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, z_erofs_lzma_head = strm;spin_unlock (&z_erofs_lzma_lock);wake_up (&z_erofs_lzma_wq); -return err; +return ERR_PTR (err); }const struct z_erofs_decompressor z_erofs_lzma_decomp = {
fs/erofs/decompressor_zstd.c +4 -8
@@ -135,8 +135,8 @@ static int z_erofs_load_zstd_config(struct super_block *sb,return strm ? -ENOMEM :0 ; } -static int z_erofs_zstd_decompress (struct z_erofs_decompress_req *rq, -struct page **pgpl) +static const char *z_erofs_zstd_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) {struct super_block *sb = rq->sb;struct z_erofs_stream_dctx dctx = { .rq = rq, .no =-1 , .ni =0 };
@@ -152,7 +152,7 @@ static int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, min(rq->inputsize, sb->s_blocksize - rq->pageofs_in));if (err) {kunmap_local (dctx.kin); -return err; +return ERR_PTR (err); }/* 2. get an available ZSTD context */
@@ -191,10 +191,6 @@ static int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,if (zstd_is_error (zerr) || ((rq->outputsize + dctx.avail_out) && (!zerr || (zerr >0 && !(rq->inputsize + in_buf.size - in_buf.pos))))) { -erofs_err (sb,"failed to decompress in[%u] out[%u]: %s" , - rq->inputsize, rq->outputsize, -zstd_is_error (zerr) ?zstd_get_error_name (zerr) : -"unexpected end of stream" ); err = -EFSCORRUPTED ;break ; }
@@ -210,7 +206,7 @@ static int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, z_erofs_zstd_head = strm;spin_unlock (&z_erofs_zstd_lock);wake_up (&z_erofs_zstd_wq); -return err; +return ERR_PTR (err); }const struct z_erofs_decompressor z_erofs_zstd_decomp = {
fs/erofs/zdata.c +17 -4
@@ -1267,12 +1267,13 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, int err)struct erofs_sb_info *const sbi =EROFS_SB (be->sb);struct z_erofs_pcluster *pcl = be->pcl;unsigned int pclusterpages =z_erofs_pclusterpages (pcl); -const struct z_erofs_decompressor *decomp = +const struct z_erofs_decompressor *alg = z_erofs_decomp[pcl->algorithmformat]; +bool try_free = true;int i, j, jtop, err2;struct page *page;bool overlapped; -bool try_free = true; +const char *reason;mutex_lock (&pcl->lock); be->nr_pages =PAGE_ALIGN (pcl->length + pcl->pageofs_out) >>PAGE_SHIFT ;
@@ -1304,8 +1305,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, int err) err2 =z_erofs_parse_in_bvecs (be, &overlapped);if (err2) err = err2; -if (!err) - err = decomp->decompress(&(struct z_erofs_decompress_req) { +if (!err) { + reason = alg->decompress(&(struct z_erofs_decompress_req) { .sb = be->sb, .in = be->compressed_pages, .out = be->decompressed_pages,
@@ -1322,6 +1323,18 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, int err) .gfp = pcl->besteffort ? GFP_KERNEL :GFP_NOWAIT | __GFP_NORETRY }, be->pagepool); +if (IS_ERR (reason)) { +erofs_err (be->sb,"failed to decompress (%s) %ld @ pa %llu size %u => %u" , + alg->name,PTR_ERR (reason), pcl->pos, + pcl->pclustersize, pcl->length); + err =PTR_ERR (reason); + }else if (unlikely (reason)) { +erofs_err (be->sb,"failed to decompress (%s) %s @ pa %llu size %u => %u" , + alg->name, reason, pcl->pos, + pcl->pclustersize, pcl->length); + err = -EFSCORRUPTED ; + } + }/* must handle all compressed pages before actual file pages */ if (pcl->from_meta) {
Signature · 1 line
2.43.5
PATCH 2/4 erofs: improve Zstd, LZMA and DEFLATE error strings
Enable better, more detailed, and unique error reporting.
--- fs/erofs/decompressor_deflate.c | 16 ++++++++++------ fs/erofs/decompressor_lzma.c | 7 +++++-- fs/erofs/decompressor_zstd.c | 8 +++++--- 3 files changed, 20 insertions(+), 11 deletions(-)
fs/erofs/decompressor_deflate.c +10 -6
@@ -97,12 +97,13 @@ static int z_erofs_load_deflate_config(struct super_block *sb,return -ENOMEM ; } -static int __z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, -struct page **pgpl) +static const char *__z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) {struct super_block *sb = rq->sb;struct z_erofs_stream_dctx dctx = { .rq = rq, .no =-1 , .ni =0 };struct z_erofs_deflate *strm; +const char *reason =NULL ;int zerr, err;/* 1. get the exact DEFLATE compressed size */
@@ -111,7 +112,7 @@ static int __z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, min(rq->inputsize, sb->s_blocksize - rq->pageofs_in));if (err) {kunmap_local (dctx.kin); -return err; +return ERR_PTR (err); }/* 2. get an available DEFLATE context */
@@ -129,7 +130,7 @@ static int __z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,/* 3. multi-call decompress */ zerr =zlib_inflateInit2 (&strm->z, -MAX_WBITS );if (zerr !=Z_OK ) { - err = -EIO ; + err = -EINVAL ; goto failed_zinit; }
@@ -157,6 +158,9 @@ static int __z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ;if (zerr ==Z_STREAM_END && !rq->outputsize)break ; + reason = (zerr ==Z_DATA_ERROR ? +"corrupted compressed data" : +"unexpected end of stream" ); err = -EFSCORRUPTED ;break ; }
@@ -173,7 +177,7 @@ static int __z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, z_erofs_deflate_head = strm;spin_unlock (&z_erofs_deflate_lock);wake_up (&z_erofs_deflate_wq); -return err; +return reason ?:ERR_PTR (err); } static const char *z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
@@ -189,7 +193,7 @@ static const char *z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, }#endif -return ERR_PTR (__z_erofs_deflate_decompress (rq, pgpl)); +return __z_erofs_deflate_decompress (rq, pgpl); } const struct z_erofs_decompressor z_erofs_deflate_decomp = {
fs/erofs/decompressor_lzma.c +5 -2
@@ -154,6 +154,7 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,struct xz_buf buf = {};struct z_erofs_lzma *strm;enum xz_ret xz_err; +const char *reason =NULL ;int err;/* 1. get the exact LZMA compressed size */
@@ -207,7 +208,9 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,if (xz_err !=XZ_OK ) {if (xz_err ==XZ_STREAM_END && !rq->outputsize)break ; - err = -EFSCORRUPTED ; + reason = (xz_err ==XZ_DATA_ERROR ? +"corrupted compressed data" : +"unexpected end of stream" );break ; } }while (1 );
@@ -221,7 +224,7 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, z_erofs_lzma_head = strm;spin_unlock (&z_erofs_lzma_lock);wake_up (&z_erofs_lzma_wq); -return ERR_PTR (err); +return reason ?:ERR_PTR (err); }const struct z_erofs_decompressor z_erofs_lzma_decomp = {
fs/erofs/decompressor_zstd.c +5 -3
@@ -143,6 +143,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,zstd_in_buffer in_buf = {NULL ,0 ,0 };zstd_out_buffer out_buf = {NULL ,0 ,0 };struct z_erofs_zstd *strm; +const char *reason =NULL ;zstd_dstream *stream;int zerr, err;
@@ -161,7 +162,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,/* 3. multi-call decompress */ stream =zstd_init_dstream (z_erofs_zstd_max_dictsize, strm->wksp, strm->wkspsz);if (!stream) { - err = -EIO ; + err = -ENOMEM ; goto failed_zinit; }
@@ -191,7 +192,8 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,if (zstd_is_error (zerr) || ((rq->outputsize + dctx.avail_out) && (!zerr || (zerr >0 && !(rq->inputsize + in_buf.size - in_buf.pos))))) { - err = -EFSCORRUPTED ; + reason =zstd_is_error (zerr) ?zstd_get_error_name (zerr) : +"unexpected end of stream" ;break ; } }while (rq->outputsize + dctx.avail_out);
@@ -206,7 +208,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, z_erofs_zstd_head = strm;spin_unlock (&z_erofs_zstd_lock);wake_up (&z_erofs_zstd_wq); -return ERR_PTR (err); +return reason ?:ERR_PTR (err); }const struct z_erofs_decompressor z_erofs_zstd_decomp = {
Signature · 1 line
2.43.5
PATCH 3/4 erofs: enable error reporting for z_erofs_stream_switch_bufs()
In reply to Gao XiangEnable propagation of detailed errors to callers.
--- fs/erofs/compress.h | 4 ++-- fs/erofs/decompressor.c | 23 +++++++++-------------- fs/erofs/decompressor_deflate.c | 4 ++-- fs/erofs/decompressor_lzma.c | 6 +++--- fs/erofs/decompressor_zstd.c | 4 ++-- 5 files changed, 18 insertions(+), 23 deletions(-)
fs/erofs/compress.h +2 -2
@@ -70,8 +70,8 @@ struct z_erofs_stream_dctx {bool bounced;/* is the bounce buffer used now? */ }; -int z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx,void **dst, -void **src,struct page **pgpl); +const char *z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx, +void **dst,void **src,struct page **pgpl);int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf,unsigned int padbufsize);int __init z_erofs_init_decompressor (void );
fs/erofs/decompressor.c +9 -14
@@ -342,19 +342,16 @@ static const char *z_erofs_transform_plain(struct z_erofs_decompress_req *rq,return NULL ; } -int z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx,void **dst, -void **src,struct page **pgpl) +const char *z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx, +void **dst,void **src,struct page **pgpl) {struct z_erofs_decompress_req *rq = dctx->rq; -struct super_block *sb = rq->sb;struct page **pgo, *tmppage;unsigned int j;if (!dctx->avail_out) { -if (++dctx->no >= rq->outpages || !rq->outputsize) { -erofs_err (sb,"insufficient space for decompressed data" ); -return -EFSCORRUPTED ; - } +if (++dctx->no >= rq->outpages || !rq->outputsize) +return "insufficient space for decompressed data" ;if (dctx->kout)kunmap_local (dctx->kout);
@@ -365,7 +362,7 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst, *pgo =erofs_allocpage (pgpl, rq->gfp);if (!*pgo) { dctx->kout =NULL ; -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); }set_page_private (*pgo,Z_EROFS_SHORTLIVED_PAGE ); }
@@ -379,10 +376,8 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst, }if (dctx->inbuf_pos == dctx->inbuf_sz && rq->inputsize) { -if (++dctx->ni >= rq->inpages) { -erofs_err (sb,"invalid compressed data" ); -return -EFSCORRUPTED ; - } +if (++dctx->ni >= rq->inpages) +return "invalid compressed data" ;if (dctx->kout)/* unlike kmap(), take care of the orders */ kunmap_local (dctx->kout);kunmap_local (dctx->kin);
@@ -417,12 +412,12 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,continue ; tmppage =erofs_allocpage (pgpl, rq->gfp);if (!tmppage) -return -ENOMEM ; +return ERR_PTR (-ENOMEM );set_page_private (tmppage,Z_EROFS_SHORTLIVED_PAGE );copy_highpage (tmppage, rq->in[j]); rq->in[j] = tmppage; } -return 0 ; +return NULL ; }const struct z_erofs_decompressor *z_erofs_decomp[] = {
fs/erofs/decompressor_deflate.c +2 -2
@@ -144,10 +144,10 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *rwhile (1 ) { dctx.avail_out = strm->z.avail_out; dctx.inbuf_sz = strm->z.avail_in; - err =z_erofs_stream_switch_bufs (&dctx, + reason =z_erofs_stream_switch_bufs (&dctx, (void **)&strm->z.next_out, (void **)&strm->z.next_in, pgpl); -if (err) +if (reason)break ; strm->z.avail_out = dctx.avail_out; strm->z.avail_in = dctx.inbuf_sz;
fs/erofs/decompressor_lzma.c +3 -3
@@ -189,9 +189,9 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, dctx.avail_out = buf.out_size - buf.out_pos; dctx.inbuf_sz = buf.in_size; dctx.inbuf_pos = buf.in_pos; - err =z_erofs_stream_switch_bufs (&dctx, (void **)&buf.out, - (void **)&buf.in, pgpl); -if (err) + reason =z_erofs_stream_switch_bufs (&dctx, (void **)&buf.out, + (void **)&buf.in, pgpl); +if (reason)break ;if (buf.out_size == buf.out_pos) {
fs/erofs/decompressor_zstd.c +2 -2
@@ -175,9 +175,9 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, do { dctx.inbuf_sz = in_buf.size; dctx.inbuf_pos = in_buf.pos; - err = z_erofs_stream_switch_bufs(&dctx, &out_buf.dst, + reason = z_erofs_stream_switch_bufs(&dctx, &out_buf.dst, (void **)&in_buf.src, pgpl); - if (err) + if (reason) break; if (out_buf.size == out_buf.pos) {
Signature · 1 line
2.43.5
PATCH 4/4 erofs: enable error reporting for z_erofs_fixup_insize()
In reply to Gao XiangEnable propagation of detailed errors to callers.
--- fs/erofs/compress.h | 4 ++-- fs/erofs/decompressor.c | 19 ++++++++++--------- fs/erofs/decompressor_crypto.c | 7 ++++--- fs/erofs/decompressor_deflate.c | 19 +++++++++---------- fs/erofs/decompressor_lzma.c | 11 +++++------ fs/erofs/decompressor_zstd.c | 14 +++++++------- 6 files changed, 37 insertions(+), 37 deletions(-)
fs/erofs/compress.h +2 -2
@@ -72,8 +72,8 @@ struct z_erofs_stream_dctx {const char *z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx,void **dst,void **src,struct page **pgpl); -int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf, -unsigned int padbufsize); +const char *z_erofs_fixup_insize (struct z_erofs_decompress_req *rq, +const char *padbuf,unsigned int padbufsize);int __init z_erofs_init_decompressor (void );void z_erofs_exit_decompressor (void ); int z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,
fs/erofs/decompressor.c +10 -9
@@ -178,18 +178,18 @@ static void *z_erofs_lz4_handle_overlap(const struct z_erofs_decompress_req *rq, }/* -* Get the exact inputsize with zero_padding feature. -* - For LZ4, it should work if zero_padding feature is on (5.3+); -* - For MicroLZMA, it'd be enabled all the time. +* Get the exact on-disk size of the compressed data: +* - For LZ4, it should apply if the zero_padding feature is on (5.3+); +* - For others, zero_padding is enabled all the time. */ -int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf, -unsigned int padbufsize) +const char *z_erofs_fixup_insize (struct z_erofs_decompress_req *rq, +const char *padbuf,unsigned int padbufsize) {const char *padend; padend =memchr_inv (padbuf,0 , padbufsize);if (!padend) -return -EFSCORRUPTED ; +return "compressed data start not found" ; rq->inputsize -= padend - padbuf; rq->pageofs_in += padend - padbuf;return 0 ;
@@ -200,6 +200,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dstbool support_0padding = false, may_inplace = false;unsigned int inputmargin;u8 *out, *headpage, *src; +const char *reason;int ret, maptype;DBG_BUGON (*rq->in ==NULL );
@@ -208,12 +209,12 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst/* LZ4 decompression inplace is only safe if zero_padding is enabled */ if (erofs_sb_has_zero_padding (EROFS_SB (rq->sb))) { support_0padding = true; - ret =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, min_t(unsigned int, rq->inputsize, rq->sb->s_blocksize - rq->pageofs_in)); -if (ret) { +if (reason) {kunmap_local (headpage); -return ret; +return IS_ERR (reason) ?PTR_ERR (reason) : -EFSCORRUPTED ; } may_inplace = !((rq->pageofs_in + rq->inputsize) & (rq->sb->s_blocksize -1 ));
fs/erofs/decompressor_crypto.c +4 -3
@@ -9,16 +9,17 @@ static int __z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,struct sg_table st_src, st_dst;struct acomp_req *req;struct crypto_wait wait; +const char *reason;u8 *headpage;int ret; headpage =kmap_local_page (*rq->in); - ret =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, min_t(unsigned int, rq->inputsize, rq->sb->s_blocksize - rq->pageofs_in));kunmap_local (headpage); -if (ret) -return ret; +if (reason) +return IS_ERR (reason) ?PTR_ERR (reason) : -EFSCORRUPTED ; req =acomp_request_alloc (tfm);if (!req)
fs/erofs/decompressor_deflate.c +9 -10
@@ -103,16 +103,16 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *rstruct super_block *sb = rq->sb;struct z_erofs_stream_dctx dctx = { .rq = rq, .no =-1 , .ni =0 };struct z_erofs_deflate *strm; -const char *reason =NULL ; -int zerr, err; +const char *reason; +int zerr;/* 1. get the exact DEFLATE compressed size */ dctx.kin =kmap_local_page (*rq->in); - err =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in,min (rq->inputsize, sb->s_blocksize - rq->pageofs_in)); -if (err) { +if (reason) {kunmap_local (dctx.kin); -return ERR_PTR (err); +return reason; }/* 2. get an available DEFLATE context */
@@ -130,7 +130,7 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r/* 3. multi-call decompress */ zerr =zlib_inflateInit2 (&strm->z, -MAX_WBITS );if (zerr !=Z_OK ) { - err = -EINVAL ; + reason =ERR_PTR (-EINVAL ); goto failed_zinit; }
@@ -161,12 +161,11 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r reason = (zerr ==Z_DATA_ERROR ?"corrupted compressed data" :"unexpected end of stream" ); - err = -EFSCORRUPTED ;break ; } } -if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) - err = -EIO ; +if (zlib_inflateEnd (&strm->z) !=Z_OK && !reason) + reason =ERR_PTR (-EIO );if (dctx.kout)kunmap_local (dctx.kout); failed_zinit:
@@ -177,7 +176,7 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r z_erofs_deflate_head = strm;spin_unlock (&z_erofs_deflate_lock);wake_up (&z_erofs_deflate_wq); -return reason ?:ERR_PTR (err); +return reason; } static const char *z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
fs/erofs/decompressor_lzma.c +5 -6
@@ -154,16 +154,15 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,struct xz_buf buf = {};struct z_erofs_lzma *strm;enum xz_ret xz_err; -const char *reason =NULL ; -int err; +const char *reason;/* 1. get the exact LZMA compressed size */ dctx.kin =kmap_local_page (*rq->in); - err =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in,min (rq->inputsize, sb->s_blocksize - rq->pageofs_in)); -if (err) { +if (reason) {kunmap_local (dctx.kin); -return ERR_PTR (err); +return reason; }/* 2. get an available lzma context */
@@ -224,7 +223,7 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, z_erofs_lzma_head = strm;spin_unlock (&z_erofs_lzma_lock);wake_up (&z_erofs_lzma_wq); -return reason ?:ERR_PTR (err); +return reason; }const struct z_erofs_decompressor z_erofs_lzma_decomp = {
fs/erofs/decompressor_zstd.c +7 -7
@@ -143,17 +143,17 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,zstd_in_buffer in_buf = {NULL ,0 ,0 };zstd_out_buffer out_buf = {NULL ,0 ,0 };struct z_erofs_zstd *strm; -const char *reason =NULL ;zstd_dstream *stream; -int zerr, err; +const char *reason; +int zerr;/* 1. get the exact compressed size */ dctx.kin =kmap_local_page (*rq->in); - err =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in,min (rq->inputsize, sb->s_blocksize - rq->pageofs_in)); -if (err) { +if (reason) {kunmap_local (dctx.kin); -return ERR_PTR (err); +return reason; }/* 2. get an available ZSTD context */
@@ -162,7 +162,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,/* 3. multi-call decompress */ stream =zstd_init_dstream (z_erofs_zstd_max_dictsize, strm->wksp, strm->wkspsz);if (!stream) { - err = -ENOMEM ; + reason =ERR_PTR (-ENOMEM ); goto failed_zinit; }
@@ -208,7 +208,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, z_erofs_zstd_head = strm;spin_unlock (&z_erofs_zstd_lock);wake_up (&z_erofs_zstd_wq); -return reason ?:ERR_PTR (err); +return reason; }const struct z_erofs_decompressor z_erofs_zstd_decomp = {
Signature · 1 line
2.43.5
kernel test robot
build botRe: [PATCH 4/4] erofs: enable error reporting for z_erofs_fixup_insize()
kernel test robot noticed the following build warnings:
Hi Gao,
kernel test robot noticed the following build warnings:
[auto build test WARNING on xiang-erofs/dev-test]
[also build test WARNING on xiang-erofs/fixes linus/master v6.18-rc7 next-20251128] [cannot apply to xiang-erofs/dev]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Gao-Xiang/erofs-improve-Zstd-LZMA-and-DEFLATE-error-strings/20251127-153426 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test patch link: https://lore.kernel.org/r/20251127073122.2542542-4-hsiangkao%40linux.alibaba.com patch subject: [PATCH 4/4] erofs: enable error reporting for z_erofs_fixup_insize() config: x86_64-randconfig-123-20251128 (https://download.01.org/0day-ci/archive/20251129/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251129/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> fs/erofs/decompressor.c:195:16: sparse: sparse: Using plain integer as NULL pointer
vim +195 fs/erofs/decompressor.c
7fc45dbc938a2e drivers/staging/erofs/decompressor.c Gao Xiang 2019-06-24 179
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 180 /*
c06acfa83138b7 fs/erofs/decompressor.c Gao Xiang 2025-11-27 181 * Get the exact on-disk size of the compressed data:
c06acfa83138b7 fs/erofs/decompressor.c Gao Xiang 2025-11-27 182 * - For LZ4, it should apply if the zero_padding feature is on (5.3+);
c06acfa83138b7 fs/erofs/decompressor.c Gao Xiang 2025-11-27 183 * - For others, zero_padding is enabled all the time.
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 184 */
c06acfa83138b7 fs/erofs/decompressor.c Gao Xiang 2025-11-27 185 const char *z_erofs_fixup_insize(struct z_erofs_decompress_req *rq,
c06acfa83138b7 fs/erofs/decompressor.c Gao Xiang 2025-11-27 186 const char *padbuf, unsigned int padbufsize)
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 187 {
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 188 const char *padend;
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 189
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 190 padend = memchr_inv(padbuf, 0, padbufsize);
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 191 if (!padend)
c06acfa83138b7 fs/erofs/decompressor.c Gao Xiang 2025-11-27 192 return "compressed data start not found";
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 193 rq->inputsize -= padend - padbuf;
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 194 rq->pageofs_in += padend - padbuf;
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 @195 return 0;
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 196 }
10e5f6e482e18d fs/erofs/decompressor.c Gao Xiang 2021-12-28 197 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Gao Xiang
maintainerPATCH v2 4/4 erofs: enable error reporting for z_erofs_fixup_insize()
In reply to Gao XiangFrom: Gao Xiang <[email protected]>
Enable propagation of detailed errors to callers.
---
v2:
- fix sparse warning:
"Using plain integer as NULL pointer"
fs/erofs/compress.h | 4 ++-- fs/erofs/decompressor.c | 21 +++++++++++---------- fs/erofs/decompressor_crypto.c | 7 ++++--- fs/erofs/decompressor_deflate.c | 19 +++++++++---------- fs/erofs/decompressor_lzma.c | 11 +++++------ fs/erofs/decompressor_zstd.c | 14 +++++++------- 6 files changed, 38 insertions(+), 38 deletions(-)
fs/erofs/compress.h +2 -2
@@ -72,8 +72,8 @@ struct z_erofs_stream_dctx {const char *z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx,void **dst,void **src,struct page **pgpl); -int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf, -unsigned int padbufsize); +const char *z_erofs_fixup_insize (struct z_erofs_decompress_req *rq, +const char *padbuf,unsigned int padbufsize);int __init z_erofs_init_decompressor (void );void z_erofs_exit_decompressor (void ); int z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,
fs/erofs/decompressor.c +11 -10
@@ -178,21 +178,21 @@ static void *z_erofs_lz4_handle_overlap(const struct z_erofs_decompress_req *rq, }/* -* Get the exact inputsize with zero_padding feature. -* - For LZ4, it should work if zero_padding feature is on (5.3+); -* - For MicroLZMA, it'd be enabled all the time. +* Get the exact on-disk size of the compressed data: +* - For LZ4, it should apply if the zero_padding feature is on (5.3+); +* - For others, zero_padding is enabled all the time. */ -int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf, -unsigned int padbufsize) +const char *z_erofs_fixup_insize (struct z_erofs_decompress_req *rq, +const char *padbuf,unsigned int padbufsize) {const char *padend; padend =memchr_inv (padbuf,0 , padbufsize);if (!padend) -return -EFSCORRUPTED ; +return "compressed data start not found" ; rq->inputsize -= padend - padbuf; rq->pageofs_in += padend - padbuf; -return 0 ; +return NULL ; }static int z_erofs_lz4_decompress_mem (struct z_erofs_decompress_req *rq,u8 *dst)
@@ -200,6 +200,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dstbool support_0padding = false, may_inplace = false;unsigned int inputmargin;u8 *out, *headpage, *src; +const char *reason;int ret, maptype;DBG_BUGON (*rq->in ==NULL );
@@ -208,12 +209,12 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst/* LZ4 decompression inplace is only safe if zero_padding is enabled */ if (erofs_sb_has_zero_padding (EROFS_SB (rq->sb))) { support_0padding = true; - ret =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, min_t(unsigned int, rq->inputsize, rq->sb->s_blocksize - rq->pageofs_in)); -if (ret) { +if (reason) {kunmap_local (headpage); -return ret; +return IS_ERR (reason) ?PTR_ERR (reason) : -EFSCORRUPTED ; } may_inplace = !((rq->pageofs_in + rq->inputsize) & (rq->sb->s_blocksize -1 ));
fs/erofs/decompressor_crypto.c +4 -3
@@ -9,16 +9,17 @@ static int __z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,struct sg_table st_src, st_dst;struct acomp_req *req;struct crypto_wait wait; +const char *reason;u8 *headpage;int ret; headpage =kmap_local_page (*rq->in); - ret =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, min_t(unsigned int, rq->inputsize, rq->sb->s_blocksize - rq->pageofs_in));kunmap_local (headpage); -if (ret) -return ret; +if (reason) +return IS_ERR (reason) ?PTR_ERR (reason) : -EFSCORRUPTED ; req =acomp_request_alloc (tfm);if (!req)
fs/erofs/decompressor_deflate.c +9 -10
@@ -103,16 +103,16 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *rstruct super_block *sb = rq->sb;struct z_erofs_stream_dctx dctx = { .rq = rq, .no =-1 , .ni =0 };struct z_erofs_deflate *strm; -const char *reason =NULL ; -int zerr, err; +const char *reason; +int zerr;/* 1. get the exact DEFLATE compressed size */ dctx.kin =kmap_local_page (*rq->in); - err =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in,min (rq->inputsize, sb->s_blocksize - rq->pageofs_in)); -if (err) { +if (reason) {kunmap_local (dctx.kin); -return ERR_PTR (err); +return reason; }/* 2. get an available DEFLATE context */
@@ -130,7 +130,7 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r/* 3. multi-call decompress */ zerr =zlib_inflateInit2 (&strm->z, -MAX_WBITS );if (zerr !=Z_OK ) { - err = -EINVAL ; + reason =ERR_PTR (-EINVAL ); goto failed_zinit; }
@@ -161,12 +161,11 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r reason = (zerr ==Z_DATA_ERROR ?"corrupted compressed data" :"unexpected end of stream" ); - err = -EFSCORRUPTED ;break ; } } -if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) - err = -EIO ; +if (zlib_inflateEnd (&strm->z) !=Z_OK && !reason) + reason =ERR_PTR (-EIO );if (dctx.kout)kunmap_local (dctx.kout); failed_zinit:
@@ -177,7 +176,7 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r z_erofs_deflate_head = strm;spin_unlock (&z_erofs_deflate_lock);wake_up (&z_erofs_deflate_wq); -return reason ?:ERR_PTR (err); +return reason; } static const char *z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
fs/erofs/decompressor_lzma.c +5 -6
@@ -154,16 +154,15 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,struct xz_buf buf = {};struct z_erofs_lzma *strm;enum xz_ret xz_err; -const char *reason =NULL ; -int err; +const char *reason;/* 1. get the exact LZMA compressed size */ dctx.kin =kmap_local_page (*rq->in); - err =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in,min (rq->inputsize, sb->s_blocksize - rq->pageofs_in)); -if (err) { +if (reason) {kunmap_local (dctx.kin); -return ERR_PTR (err); +return reason; }/* 2. get an available lzma context */
@@ -224,7 +223,7 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, z_erofs_lzma_head = strm;spin_unlock (&z_erofs_lzma_lock);wake_up (&z_erofs_lzma_wq); -return reason ?:ERR_PTR (err); +return reason; }const struct z_erofs_decompressor z_erofs_lzma_decomp = {
fs/erofs/decompressor_zstd.c +7 -7
@@ -143,17 +143,17 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,zstd_in_buffer in_buf = {NULL ,0 ,0 };zstd_out_buffer out_buf = {NULL ,0 ,0 };struct z_erofs_zstd *strm; -const char *reason =NULL ;zstd_dstream *stream; -int zerr, err; +const char *reason; +int zerr;/* 1. get the exact compressed size */ dctx.kin =kmap_local_page (*rq->in); - err =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in, + reason =z_erofs_fixup_insize (rq, dctx.kin + rq->pageofs_in,min (rq->inputsize, sb->s_blocksize - rq->pageofs_in)); -if (err) { +if (reason) {kunmap_local (dctx.kin); -return ERR_PTR (err); +return reason; }/* 2. get an available ZSTD context */
@@ -162,7 +162,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,/* 3. multi-call decompress */ stream =zstd_init_dstream (z_erofs_zstd_max_dictsize, strm->wksp, strm->wkspsz);if (!stream) { - err = -ENOMEM ; + reason =ERR_PTR (-ENOMEM ); goto failed_zinit; }
@@ -208,7 +208,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, z_erofs_zstd_head = strm;spin_unlock (&z_erofs_zstd_lock);wake_up (&z_erofs_zstd_wq); -return reason ?:ERR_PTR (err); +return reason; }const struct z_erofs_decompressor z_erofs_zstd_decomp = {
Signature · 1 line
2.30.2