This fixes the following SIGSEGV that occurs when compression fails:

in __erofs_bflush (bmgr=0x7ffff695c010, bb=0x0, abort=true) at cache.c:482
482                             ret = bh->op->flush(bh, abort);
 0  0x0000000000413860 in __erofs_bflush (bmgr=0x7ffff695c010, bb=0x0, 
abort=true) at cache.c:482
 1  0x0000000000413cbe in erofs_buffer_exit (bmgr=0x7ffff695c010) at cache.c:549
 2  0x0000000000414f72 in erofs_put_super (sbi=0x493270 <g_sbi>) at super.c:193
 3  0x000000000040718d in main (argc=6, argv=0x7fffffffd628) at main.c:2165

Signed-off-by: Gao Xiang <[email protected]>
---
 lib/compress.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/compress.c b/lib/compress.c
index 995bc602b145..7e8142a48ae5 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -1388,12 +1388,10 @@ int erofs_commit_compressed_file(struct 
z_erofs_compress_ictx *ictx,
        erofs_info("compressed %s (%llu bytes) into %llu bytes",
                   inode->i_srcpath, inode->i_size | 0ULL, ptotal | 0ULL);
 
-       if (inode->idata_size) {
-               bh->op = &erofs_skip_write_bhops;
+       if (inode->idata_size)
                inode->bh_data = bh;
-       } else {
+       else
                erofs_bdrop(bh, false);
-       }
 
        inode->u.i_blocks = BLK_ROUND_UP(sbi, ptotal);
 
@@ -1690,7 +1688,7 @@ int erofs_mt_write_compressed_file(struct 
z_erofs_compress_ictx *ictx)
                ret = PTR_ERR(bh);
                goto out;
        }
-
+       bh->op = &erofs_skip_write_bhops;
        DBG_BUGON(!head);
        pstart = erofs_pos(sbi, erofs_mapbh(NULL, bh->block));
 
@@ -1985,6 +1983,7 @@ int erofs_write_compressed_file(struct 
z_erofs_compress_ictx *ictx)
                ret = PTR_ERR(bh);
                goto err_free_idata;
        }
+       bh->op = &erofs_skip_write_bhops;
        pstart = erofs_pos(sbi, erofs_mapbh(NULL, bh->block));
 
        ictx->seg_num = 1;
-- 
2.43.5


Reply via email to