Skip to content

Commit 3a991f7

Browse files
committed
erofs: enable error reporting for z_erofs_stream_switch_bufs()
Enable propagation of detailed errors to callers. Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 83564b0 commit 3a991f7

5 files changed

Lines changed: 18 additions & 23 deletions

File tree

fs/erofs/compress.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ struct z_erofs_stream_dctx {
7070
bool bounced; /* is the bounce buffer used now? */
7171
};
7272

73-
int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
74-
void **src, struct page **pgpl);
73+
const char *z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx,
74+
void **dst, void **src, struct page **pgpl);
7575
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
7676
unsigned int padbufsize);
7777
int __init z_erofs_init_decompressor(void);

fs/erofs/decompressor.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,16 @@ static const char *z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
342342
return NULL;
343343
}
344344

345-
int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
346-
void **src, struct page **pgpl)
345+
const char *z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx,
346+
void **dst, void **src, struct page **pgpl)
347347
{
348348
struct z_erofs_decompress_req *rq = dctx->rq;
349-
struct super_block *sb = rq->sb;
350349
struct page **pgo, *tmppage;
351350
unsigned int j;
352351

353352
if (!dctx->avail_out) {
354-
if (++dctx->no >= rq->outpages || !rq->outputsize) {
355-
erofs_err(sb, "insufficient space for decompressed data");
356-
return -EFSCORRUPTED;
357-
}
353+
if (++dctx->no >= rq->outpages || !rq->outputsize)
354+
return "insufficient space for decompressed data";
358355

359356
if (dctx->kout)
360357
kunmap_local(dctx->kout);
@@ -365,7 +362,7 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
365362
*pgo = erofs_allocpage(pgpl, rq->gfp);
366363
if (!*pgo) {
367364
dctx->kout = NULL;
368-
return -ENOMEM;
365+
return ERR_PTR(-ENOMEM);
369366
}
370367
set_page_private(*pgo, Z_EROFS_SHORTLIVED_PAGE);
371368
}
@@ -379,10 +376,8 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
379376
}
380377

381378
if (dctx->inbuf_pos == dctx->inbuf_sz && rq->inputsize) {
382-
if (++dctx->ni >= rq->inpages) {
383-
erofs_err(sb, "invalid compressed data");
384-
return -EFSCORRUPTED;
385-
}
379+
if (++dctx->ni >= rq->inpages)
380+
return "invalid compressed data";
386381
if (dctx->kout) /* unlike kmap(), take care of the orders */
387382
kunmap_local(dctx->kout);
388383
kunmap_local(dctx->kin);
@@ -417,12 +412,12 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
417412
continue;
418413
tmppage = erofs_allocpage(pgpl, rq->gfp);
419414
if (!tmppage)
420-
return -ENOMEM;
415+
return ERR_PTR(-ENOMEM);
421416
set_page_private(tmppage, Z_EROFS_SHORTLIVED_PAGE);
422417
copy_highpage(tmppage, rq->in[j]);
423418
rq->in[j] = tmppage;
424419
}
425-
return 0;
420+
return NULL;
426421
}
427422

428423
const struct z_erofs_decompressor *z_erofs_decomp[] = {

fs/erofs/decompressor_deflate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r
144144
while (1) {
145145
dctx.avail_out = strm->z.avail_out;
146146
dctx.inbuf_sz = strm->z.avail_in;
147-
err = z_erofs_stream_switch_bufs(&dctx,
147+
reason = z_erofs_stream_switch_bufs(&dctx,
148148
(void **)&strm->z.next_out,
149149
(void **)&strm->z.next_in, pgpl);
150-
if (err)
150+
if (reason)
151151
break;
152152
strm->z.avail_out = dctx.avail_out;
153153
strm->z.avail_in = dctx.inbuf_sz;

fs/erofs/decompressor_lzma.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
189189
dctx.avail_out = buf.out_size - buf.out_pos;
190190
dctx.inbuf_sz = buf.in_size;
191191
dctx.inbuf_pos = buf.in_pos;
192-
err = z_erofs_stream_switch_bufs(&dctx, (void **)&buf.out,
193-
(void **)&buf.in, pgpl);
194-
if (err)
192+
reason = z_erofs_stream_switch_bufs(&dctx, (void **)&buf.out,
193+
(void **)&buf.in, pgpl);
194+
if (reason)
195195
break;
196196

197197
if (buf.out_size == buf.out_pos) {

fs/erofs/decompressor_zstd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
175175
do {
176176
dctx.inbuf_sz = in_buf.size;
177177
dctx.inbuf_pos = in_buf.pos;
178-
err = z_erofs_stream_switch_bufs(&dctx, &out_buf.dst,
178+
reason = z_erofs_stream_switch_bufs(&dctx, &out_buf.dst,
179179
(void **)&in_buf.src, pgpl);
180-
if (err)
180+
if (reason)
181181
break;
182182

183183
if (out_buf.size == out_buf.pos) {

0 commit comments

Comments
 (0)