Skip to content

Commit 30e13e4

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

6 files changed

Lines changed: 38 additions & 38 deletions

File tree

fs/erofs/compress.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ struct z_erofs_stream_dctx {
7272

7373
const char *z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx,
7474
void **dst, void **src, struct page **pgpl);
75-
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
76-
unsigned int padbufsize);
75+
const char *z_erofs_fixup_insize(struct z_erofs_decompress_req *rq,
76+
const char *padbuf, unsigned int padbufsize);
7777
int __init z_erofs_init_decompressor(void);
7878
void z_erofs_exit_decompressor(void);
7979
int z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,

fs/erofs/decompressor.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,28 +178,29 @@ static void *z_erofs_lz4_handle_overlap(const struct z_erofs_decompress_req *rq,
178178
}
179179

180180
/*
181-
* Get the exact inputsize with zero_padding feature.
182-
* - For LZ4, it should work if zero_padding feature is on (5.3+);
183-
* - For MicroLZMA, it'd be enabled all the time.
181+
* Get the exact on-disk size of the compressed data:
182+
* - For LZ4, it should apply if the zero_padding feature is on (5.3+);
183+
* - For others, zero_padding is enabled all the time.
184184
*/
185-
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
186-
unsigned int padbufsize)
185+
const char *z_erofs_fixup_insize(struct z_erofs_decompress_req *rq,
186+
const char *padbuf, unsigned int padbufsize)
187187
{
188188
const char *padend;
189189

190190
padend = memchr_inv(padbuf, 0, padbufsize);
191191
if (!padend)
192-
return -EFSCORRUPTED;
192+
return "compressed data start not found";
193193
rq->inputsize -= padend - padbuf;
194194
rq->pageofs_in += padend - padbuf;
195-
return 0;
195+
return NULL;
196196
}
197197

198198
static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst)
199199
{
200200
bool support_0padding = false, may_inplace = false;
201201
unsigned int inputmargin;
202202
u8 *out, *headpage, *src;
203+
const char *reason;
203204
int ret, maptype;
204205

205206
DBG_BUGON(*rq->in == NULL);
@@ -208,12 +209,12 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst
208209
/* LZ4 decompression inplace is only safe if zero_padding is enabled */
209210
if (erofs_sb_has_zero_padding(EROFS_SB(rq->sb))) {
210211
support_0padding = true;
211-
ret = z_erofs_fixup_insize(rq, headpage + rq->pageofs_in,
212+
reason = z_erofs_fixup_insize(rq, headpage + rq->pageofs_in,
212213
min_t(unsigned int, rq->inputsize,
213214
rq->sb->s_blocksize - rq->pageofs_in));
214-
if (ret) {
215+
if (reason) {
215216
kunmap_local(headpage);
216-
return ret;
217+
return IS_ERR(reason) ? PTR_ERR(reason) : -EFSCORRUPTED;
217218
}
218219
may_inplace = !((rq->pageofs_in + rq->inputsize) &
219220
(rq->sb->s_blocksize - 1));

fs/erofs/decompressor_crypto.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ static int __z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,
99
struct sg_table st_src, st_dst;
1010
struct acomp_req *req;
1111
struct crypto_wait wait;
12+
const char *reason;
1213
u8 *headpage;
1314
int ret;
1415

1516
headpage = kmap_local_page(*rq->in);
16-
ret = z_erofs_fixup_insize(rq, headpage + rq->pageofs_in,
17+
reason = z_erofs_fixup_insize(rq, headpage + rq->pageofs_in,
1718
min_t(unsigned int, rq->inputsize,
1819
rq->sb->s_blocksize - rq->pageofs_in));
1920
kunmap_local(headpage);
20-
if (ret)
21-
return ret;
21+
if (reason)
22+
return IS_ERR(reason) ? PTR_ERR(reason) : -EFSCORRUPTED;
2223

2324
req = acomp_request_alloc(tfm);
2425
if (!req)

fs/erofs/decompressor_deflate.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r
103103
struct super_block *sb = rq->sb;
104104
struct z_erofs_stream_dctx dctx = { .rq = rq, .no = -1, .ni = 0 };
105105
struct z_erofs_deflate *strm;
106-
const char *reason = NULL;
107-
int zerr, err;
106+
const char *reason;
107+
int zerr;
108108

109109
/* 1. get the exact DEFLATE compressed size */
110110
dctx.kin = kmap_local_page(*rq->in);
111-
err = z_erofs_fixup_insize(rq, dctx.kin + rq->pageofs_in,
111+
reason = z_erofs_fixup_insize(rq, dctx.kin + rq->pageofs_in,
112112
min(rq->inputsize, sb->s_blocksize - rq->pageofs_in));
113-
if (err) {
113+
if (reason) {
114114
kunmap_local(dctx.kin);
115-
return ERR_PTR(err);
115+
return reason;
116116
}
117117

118118
/* 2. get an available DEFLATE context */
@@ -130,7 +130,7 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r
130130
/* 3. multi-call decompress */
131131
zerr = zlib_inflateInit2(&strm->z, -MAX_WBITS);
132132
if (zerr != Z_OK) {
133-
err = -EINVAL;
133+
reason = ERR_PTR(-EINVAL);
134134
goto failed_zinit;
135135
}
136136

@@ -161,12 +161,11 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r
161161
reason = (zerr == Z_DATA_ERROR ?
162162
"corrupted compressed data" :
163163
"unexpected end of stream");
164-
err = -EFSCORRUPTED;
165164
break;
166165
}
167166
}
168-
if (zlib_inflateEnd(&strm->z) != Z_OK && !err)
169-
err = -EIO;
167+
if (zlib_inflateEnd(&strm->z) != Z_OK && !reason)
168+
reason = ERR_PTR(-EIO);
170169
if (dctx.kout)
171170
kunmap_local(dctx.kout);
172171
failed_zinit:
@@ -177,7 +176,7 @@ static const char *__z_erofs_deflate_decompress(struct z_erofs_decompress_req *r
177176
z_erofs_deflate_head = strm;
178177
spin_unlock(&z_erofs_deflate_lock);
179178
wake_up(&z_erofs_deflate_wq);
180-
return reason ?: ERR_PTR(err);
179+
return reason;
181180
}
182181

183182
static const char *z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,

fs/erofs/decompressor_lzma.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,15 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
154154
struct xz_buf buf = {};
155155
struct z_erofs_lzma *strm;
156156
enum xz_ret xz_err;
157-
const char *reason = NULL;
158-
int err;
157+
const char *reason;
159158

160159
/* 1. get the exact LZMA compressed size */
161160
dctx.kin = kmap_local_page(*rq->in);
162-
err = z_erofs_fixup_insize(rq, dctx.kin + rq->pageofs_in,
161+
reason = z_erofs_fixup_insize(rq, dctx.kin + rq->pageofs_in,
163162
min(rq->inputsize, sb->s_blocksize - rq->pageofs_in));
164-
if (err) {
163+
if (reason) {
165164
kunmap_local(dctx.kin);
166-
return ERR_PTR(err);
165+
return reason;
167166
}
168167

169168
/* 2. get an available lzma context */
@@ -224,7 +223,7 @@ static const char *z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
224223
z_erofs_lzma_head = strm;
225224
spin_unlock(&z_erofs_lzma_lock);
226225
wake_up(&z_erofs_lzma_wq);
227-
return reason ?: ERR_PTR(err);
226+
return reason;
228227
}
229228

230229
const struct z_erofs_decompressor z_erofs_lzma_decomp = {

fs/erofs/decompressor_zstd.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
143143
zstd_in_buffer in_buf = { NULL, 0, 0 };
144144
zstd_out_buffer out_buf = { NULL, 0, 0 };
145145
struct z_erofs_zstd *strm;
146-
const char *reason = NULL;
147146
zstd_dstream *stream;
148-
int zerr, err;
147+
const char *reason;
148+
int zerr;
149149

150150
/* 1. get the exact compressed size */
151151
dctx.kin = kmap_local_page(*rq->in);
152-
err = z_erofs_fixup_insize(rq, dctx.kin + rq->pageofs_in,
152+
reason = z_erofs_fixup_insize(rq, dctx.kin + rq->pageofs_in,
153153
min(rq->inputsize, sb->s_blocksize - rq->pageofs_in));
154-
if (err) {
154+
if (reason) {
155155
kunmap_local(dctx.kin);
156-
return ERR_PTR(err);
156+
return reason;
157157
}
158158

159159
/* 2. get an available ZSTD context */
@@ -162,7 +162,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
162162
/* 3. multi-call decompress */
163163
stream = zstd_init_dstream(z_erofs_zstd_max_dictsize, strm->wksp, strm->wkspsz);
164164
if (!stream) {
165-
err = -ENOMEM;
165+
reason = ERR_PTR(-ENOMEM);
166166
goto failed_zinit;
167167
}
168168

@@ -208,7 +208,7 @@ static const char *z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
208208
z_erofs_zstd_head = strm;
209209
spin_unlock(&z_erofs_zstd_lock);
210210
wake_up(&z_erofs_zstd_wq);
211-
return reason ?: ERR_PTR(err);
211+
return reason;
212212
}
213213

214214
const struct z_erofs_decompressor z_erofs_zstd_decomp = {

0 commit comments

Comments
 (0)