From: Ilya Leoshkevich Date: Tue, 21 Jul 2020 11:35:58 +0000 (+0200) Subject: Fix switching compression levels on older SystemZ machines X-Git-Tag: 1.9.9-b1~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=206b97fbcc2d234814ed7b6f8712f62edd1bb707;p=thirdparty%2Fzlib-ng.git Fix switching compression levels on older SystemZ machines When switching to a compression level that is in general supported by the hardware accelerator, the code doesn't check whether acceleration is available or enabled. --- diff --git a/arch/s390/dfltcc_deflate.c b/arch/s390/dfltcc_deflate.c index ba93eee3..c2c5f1be 100644 --- a/arch/s390/dfltcc_deflate.c +++ b/arch/s390/dfltcc_deflate.c @@ -20,22 +20,19 @@ #include "dfltcc_deflate.h" #include "dfltcc_detail.h" -static inline int dfltcc_are_params_ok(int level, uInt window_bits, int strategy, uint16_t level_mask, +static inline int dfltcc_can_deflate_with_params(PREFIX3(streamp) strm, int level, uInt window_bits, int strategy, int reproducible) { - return (level_mask & ((uint16_t)1 << level)) != 0 && - (window_bits == HB_BITS) && - (strategy == Z_FIXED || strategy == Z_DEFAULT_STRATEGY) && - !reproducible; -} - - -int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); /* Unsupported compression settings */ - if (!dfltcc_are_params_ok(state->level, state->w_bits, state->strategy, dfltcc_state->level_mask, - state->reproducible)) + if ((dfltcc_state->level_mask & (1 << level)) == 0) + return 0; + if (window_bits != HB_BITS) + return 0; + if (strategy != Z_FIXED && strategy != Z_DEFAULT_STRATEGY) + return 0; + if (reproducible) return 0; /* Unsupported hardware */ @@ -47,6 +44,12 @@ int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) { return 1; } +int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) { + deflate_state *state = (deflate_state *)strm->state; + + return dfltcc_can_deflate_with_params(strm, state->level, state->w_bits, state->strategy, state->reproducible); +} + static inline void dfltcc_gdht(PREFIX3(streamp) strm) { deflate_state *state = (deflate_state *)strm->state; struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param; @@ -284,10 +287,8 @@ static int dfltcc_was_deflate_used(PREFIX3(streamp) strm) { int ZLIB_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int strategy) { deflate_state *state = (deflate_state *)strm->state; - struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state); int could_deflate = dfltcc_can_deflate(strm); - int can_deflate = dfltcc_are_params_ok(level, state->w_bits, strategy, dfltcc_state->level_mask, - state->reproducible); + int can_deflate = dfltcc_can_deflate_with_params(strm, level, state->w_bits, strategy, state->reproducible); if (can_deflate == could_deflate) /* We continue to work in the same mode - no changes needed */