@@ -371,40 +371,28 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
371371 return 0 ;
372372}
373373
374- const struct z_erofs_decompressor erofs_decompressors [] = {
375- [Z_EROFS_COMPRESSION_SHIFTED ] = {
374+ const struct z_erofs_decompressor * z_erofs_decomp [] = {
375+ [Z_EROFS_COMPRESSION_SHIFTED ] = & ( const struct z_erofs_decompressor ) {
376376 .decompress = z_erofs_transform_plain ,
377377 .name = "shifted"
378378 },
379- [Z_EROFS_COMPRESSION_INTERLACED ] = {
379+ [Z_EROFS_COMPRESSION_INTERLACED ] = & ( const struct z_erofs_decompressor ) {
380380 .decompress = z_erofs_transform_plain ,
381381 .name = "interlaced"
382382 },
383- [Z_EROFS_COMPRESSION_LZ4 ] = {
383+ [Z_EROFS_COMPRESSION_LZ4 ] = & ( const struct z_erofs_decompressor ) {
384384 .config = z_erofs_load_lz4_config ,
385385 .decompress = z_erofs_lz4_decompress ,
386386 .name = "lz4"
387387 },
388388#ifdef CONFIG_EROFS_FS_ZIP_LZMA
389- [Z_EROFS_COMPRESSION_LZMA ] = {
390- .config = z_erofs_load_lzma_config ,
391- .decompress = z_erofs_lzma_decompress ,
392- .name = "lzma"
393- },
389+ [Z_EROFS_COMPRESSION_LZMA ] = & z_erofs_lzma_decomp ,
394390#endif
395391#ifdef CONFIG_EROFS_FS_ZIP_DEFLATE
396- [Z_EROFS_COMPRESSION_DEFLATE ] = {
397- .config = z_erofs_load_deflate_config ,
398- .decompress = z_erofs_deflate_decompress ,
399- .name = "deflate"
400- },
392+ [Z_EROFS_COMPRESSION_DEFLATE ] = & z_erofs_deflate_decomp ,
401393#endif
402394#ifdef CONFIG_EROFS_FS_ZIP_ZSTD
403- [Z_EROFS_COMPRESSION_ZSTD ] = {
404- .config = z_erofs_load_zstd_config ,
405- .decompress = z_erofs_zstd_decompress ,
406- .name = "zstd"
407- },
395+ [Z_EROFS_COMPRESSION_ZSTD ] = & z_erofs_zstd_decomp ,
408396#endif
409397};
410398
@@ -432,6 +420,7 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
432420 offset = EROFS_SUPER_OFFSET + sbi -> sb_size ;
433421 alg = 0 ;
434422 for (algs = sbi -> available_compr_algs ; algs ; algs >>= 1 , ++ alg ) {
423+ const struct z_erofs_decompressor * dec = z_erofs_decomp [alg ];
435424 void * data ;
436425
437426 if (!(algs & 1 ))
@@ -443,16 +432,13 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
443432 break ;
444433 }
445434
446- if (alg >= ARRAY_SIZE (erofs_decompressors ) ||
447- !erofs_decompressors [alg ].config ) {
435+ if (alg < Z_EROFS_COMPRESSION_MAX && dec && dec -> config ) {
436+ ret = dec -> config (sb , dsb , data , size );
437+ } else {
448438 erofs_err (sb , "algorithm %d isn't enabled on this kernel" ,
449439 alg );
450440 ret = - EOPNOTSUPP ;
451- } else {
452- ret = erofs_decompressors [alg ].config (sb ,
453- dsb , data , size );
454441 }
455-
456442 kfree (data );
457443 if (ret )
458444 break ;
0 commit comments