]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix switching compression levels on older SystemZ machines
authorIlya Leoshkevich <iii@linux.ibm.com>
Tue, 21 Jul 2020 11:35:58 +0000 (13:35 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 21 Aug 2020 19:54:12 +0000 (21:54 +0200)
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.

arch/s390/dfltcc_deflate.c

index ba93eee3e1a67427d93b26fa8a522b4e743b4b69..c2c5f1be1f9c9a0ceb21d0f8bcde9b4e112f3da3 100644 (file)
 #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 */