From nobody Sun Feb 8 09:12:45 2026 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BBCA2D8792 for ; Fri, 19 Dec 2025 06:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766126633; cv=none; b=qgbYb0LBWlZDLfdkFA9UqAFGTiHY2ZTq0XZmzoJoggt8v/SNrF54EAc1SHSxrdkrrO62nvZgX8fvItRRvk/0n3CWmoWhxgjkvCDq4LVUqgLv/dTkm6uv4ZCRdT/V+sy5j4lik8S4AFaLOqxPoPUlA9Rwo7gwirBHkR9L1MjlQP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766126633; c=relaxed/simple; bh=VUFqMaH8gzHm1GM6ZJsNa0GdbIioys4F8ytuUJSeINM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bqFPz+HNLWKYWffjqEZk1ab1Cxo2FlnRGEV4znXh6VuQWKiSkSo9vp+9m4Z+19B9uMfUYPYE9N4kof16s3v/C0L511sZmKf4lKDtTfHtezsnzyP7wgoQy/c/O4Jwi2eO1G4IL1SbN9SnZVN6ScSzW2yLUXm0ehAW4ErBQQbLrwA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ntSZsBy2; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ntSZsBy2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1766126621; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=DB9DoLwj8cJ1DkyEcnLVgtFBXXvGE1oUmJ9kmFxl0lE=; b=ntSZsBy2Z0G0CQ67LEoG9x29B070ehWzwYNLscFiZAyDEaML3TpXcybj8/ZiVD5IL+hlhnBTwJ2us9nR20N1zGWMEgJgHUoiLPiSeNrh0wO3iDE6JtbGqaSNgRRVn6CYvFaDT9buoMvwPSo8PSsTgllcKoupQJBllbZKQdk024U= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WvBkRxm_1766126617 cluster:ay36) by smtp.aliyun-inc.com; Fri, 19 Dec 2025 14:43:40 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang Subject: [PATCH] erofs: improve LZ4 error strings Date: Fri, 19 Dec 2025 14:43:36 +0800 Message-ID: <20251219064336.684930-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Just like what was done for other algorithms, let's propagate detailed error reasons for LZ4 instead of just -EFSCORRUPTED to users: "corrupted compressed data": the compressed data is malformed or destination buffer is not large enough "unexpected end of stream": the compressed stream ends normally, but without producing enough decompressed data. "compressed data start not found": can be returned by z_erofs_fixup_insize(). Signed-off-by: Gao Xiang Reviewed-by: Chao Yu --- fs/erofs/decompressor.c | 42 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index d5d090276391..fcbb2502dbf0 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -195,26 +195,25 @@ const char *z_erofs_fixup_insize(struct z_erofs_decom= press_req *rq, return NULL; } =20 -static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u= 8 *dst) +static const char *__z_erofs_lz4_decompress(struct z_erofs_decompress_req = *rq, + u8 *dst) { - bool support_0padding =3D false, may_inplace =3D false; + bool zeropadded =3D erofs_sb_has_zero_padding(EROFS_SB(rq->sb)); + bool may_inplace =3D false; unsigned int inputmargin; u8 *out, *headpage, *src; const char *reason; int ret, maptype; =20 - DBG_BUGON(*rq->in =3D=3D NULL); headpage =3D kmap_local_page(*rq->in); - /* LZ4 decompression inplace is only safe if zero_padding is enabled */ - if (erofs_sb_has_zero_padding(EROFS_SB(rq->sb))) { - support_0padding =3D true; + if (zeropadded) { reason =3D z_erofs_fixup_insize(rq, headpage + rq->pageofs_in, min_t(unsigned int, rq->inputsize, rq->sb->s_blocksize - rq->pageofs_in)); if (reason) { kunmap_local(headpage); - return IS_ERR(reason) ? PTR_ERR(reason) : -EFSCORRUPTED; + return reason; } may_inplace =3D !((rq->pageofs_in + rq->inputsize) & (rq->sb->s_blocksize - 1)); @@ -224,26 +223,24 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_= decompress_req *rq, u8 *dst src =3D z_erofs_lz4_handle_overlap(rq, headpage, dst, &inputmargin, &maptype, may_inplace); if (IS_ERR(src)) - return PTR_ERR(src); + return ERR_CAST(src); =20 out =3D dst + rq->pageofs_out; /* legacy format could compress extra data in a pcluster. */ - if (rq->partial_decoding || !support_0padding) + if (rq->partial_decoding || !zeropadded) ret =3D LZ4_decompress_safe_partial(src + inputmargin, out, rq->inputsize, rq->outputsize, rq->outputsize); else ret =3D LZ4_decompress_safe(src + inputmargin, out, rq->inputsize, rq->outputsize); + if (ret =3D=3D rq->outputsize) + reason =3D NULL; + else if (ret < 0) + reason =3D "corrupted compressed data"; + else + reason =3D "unexpected end of stream"; =20 - if (ret !=3D rq->outputsize) { - if (ret >=3D 0) - memset(out + ret, 0, rq->outputsize - ret); - ret =3D -EFSCORRUPTED; - } else { - ret =3D 0; - } - - if (maptype =3D=3D 0) { + if (!maptype) { kunmap_local(headpage); } else if (maptype =3D=3D 1) { vm_unmap_ram(src, rq->inpages); @@ -251,15 +248,16 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_= decompress_req *rq, u8 *dst z_erofs_put_gbuf(src); } else if (maptype !=3D 3) { DBG_BUGON(1); - return -EFAULT; + return ERR_PTR(-EFAULT); } - return ret; + return reason; } =20 static const char *z_erofs_lz4_decompress(struct z_erofs_decompress_req *r= q, struct page **pagepool) { unsigned int dst_maptype; + const char *reason; void *dst; int ret; =20 @@ -283,12 +281,12 @@ static const char *z_erofs_lz4_decompress(struct z_er= ofs_decompress_req *rq, dst_maptype =3D 2; } } - ret =3D z_erofs_lz4_decompress_mem(rq, dst); + reason =3D __z_erofs_lz4_decompress(rq, dst); if (!dst_maptype) kunmap_local(dst); else if (dst_maptype =3D=3D 2) vm_unmap_ram(dst, rq->outpages); - return ERR_PTR(ret); + return reason; } =20 static const char *z_erofs_transform_plain(struct z_erofs_decompress_req *= rq, --=20 2.43.5