Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4344359pxk; Tue, 29 Sep 2020 23:52:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj9PIgvWQWKfmeIZkLPd9ZTR3W5JY4a1lQTrifOxCPgaPmT9Gz/f4dJMBgS/VNa2NV0GUZ X-Received: by 2002:aa7:c648:: with SMTP id z8mr1143916edr.239.1601448737994; Tue, 29 Sep 2020 23:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601448737; cv=none; d=google.com; s=arc-20160816; b=OWigiqrCqwuyZWsM2UZBQ4QmtA0vA/K7zHAzWIhht0w42Fc0rVzhuRb8XUJZFZWqvW rNkPNnbem//dezJei/d//L0z+xYBguc4Lm159wCeCl6stCJIzX1uhFkJA9K5xxgeTv+A pzdxu5JLDOC3jy4jZun4sXHim21+5GUIvz9FJfi8XWrxlUSXQ1U2gAfP4lvpaRGekYSe Ee5EMdEGv6eGmSvb2H4z+qKrTcGH6n3Y0evbY8hk19hfZfLcIOvqAm31DxDblGcIkSLt 88gADguP+km/EY8/TVusVSapPyk4gtM+y5+ivqfSkyjlX5+ULjgreKYqn43U8wV/W+V1 UTmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=krGpYOVpUat0gERMlMR1P1lhK//ROWK8HUHnVTxyKd4=; b=OaT5Uz+7Uc/1Tv6Lb5bkqQr9Robfnt3j8gcI9rtexluzCSyHd6Fa1FMgMnWz9Fb9PP 2EJ4bEj/raDipJrAxhYrDliYPssxboTa1Adj5+6GOQCntA24aYQxJXZn8xOnZtspRkll bjYdxDfoaLAMrnGTNeTGGuOHTmsIBdsdslilivbXNkd2EG7UuXkjQs41lH9UisXTaHbT O8J6Sl5RTbhH3XXUSLjHCHQiomvZkih3bAsA5VgwD1oyRCwKmK7c6kfefLjD646f0Sqo XzngOVWgIOAz6ucPHpxe/hk/uftGnmIHvkg+GCBWfVDeP1/oxo6YxoPkrDnrvY0jnDYI G3xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Wu1wW7kG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd11si547466ejb.184.2020.09.29.23.51.54; Tue, 29 Sep 2020 23:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Wu1wW7kG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728501AbgI3Guk (ORCPT + 99 others); Wed, 30 Sep 2020 02:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725798AbgI3GuS (ORCPT ); Wed, 30 Sep 2020 02:50:18 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68EF9C061755; Tue, 29 Sep 2020 23:50:17 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id x5so421236plo.6; Tue, 29 Sep 2020 23:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=krGpYOVpUat0gERMlMR1P1lhK//ROWK8HUHnVTxyKd4=; b=Wu1wW7kGVUX2hnBN6KUwy3RNOwJdKCSWkRfqt1BdsxEV1wgVF6VdZ8NL/HbGwWmxHw AdAXq8grvCkSPFY+1tDKWNvtsGuzSzgeuPhxb1wFZYdMsiAq9SID+Pql3YPWUloILMJf fcUgmzRPqruLLP93zxemu5YuwJIqfYbUJwWg4cfweSSj6P+zHCTe7pWXONkForHoTIUb RMvm4XvDYv4ejTDvAOt+BCRBzgm2Q97XU1LRQvw2P9NOmrBsJd0sCY7wgBy71PLCEqLB Ek484Owhn5P/s0GF9eKQUFYGK2LO7RhES17Vo4zbqACdtEKX26qKGsx+lV1bKUlbxuEI J6OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=krGpYOVpUat0gERMlMR1P1lhK//ROWK8HUHnVTxyKd4=; b=aKZQSz25XoPNg2Ea3w86hyQoZ8NAo2V78gEULshXPtqxrfcRVdw80EeX1scdbNvxS2 uLy9bOIo+BV2uoKIvWc4LTPas5i4Zc9gxo4sr9T8mlQg61hMuNV/wWMxtpJejDZWtnDI 5wFFun9DMsA1aJyV4K2wQZwuMLyg/wRffG79fM0LVvueSdbHBYBpxyKAd3J1M08qO8Ux Uqm612LoDs21PdDD3W86djwA82NMrjmTj37FYhG8ku1mQ7cGkH3AiRenbRpFGbY4sn65 igee+qQEo4uEsCGLHu3QYpaBRaFlxtxb6wqxyTIKTz3sUHxZMrwSC2igYwIUwY0sAb/y NHOw== X-Gm-Message-State: AOAM530obE50/cgpfeZDMg37iF+B52IDY1eRRAiWVLIVJFyGzvzPETHo 15DtMy+ZS7MIHHW5pTl4bYc= X-Received: by 2002:a17:902:ee06:b029:d1:8c50:b1ba with SMTP id z6-20020a170902ee06b02900d18c50b1bamr1160641plb.35.1601448616906; Tue, 29 Sep 2020 23:50:16 -0700 (PDT) Received: from nickserv.localdomain (c-98-33-101-203.hsd1.ca.comcast.net. [98.33.101.203]) by smtp.gmail.com with ESMTPSA id 190sm1100865pfy.22.2020.09.29.23.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 23:50:16 -0700 (PDT) From: Nick Terrell To: Herbert Xu Cc: linux-crypto@vger.kernel.org, linux-btrfs@vger.kernel.org, squashfs-devel@lists.sourceforge.net, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Kernel Team , Nick Terrell , Nick Terrell , Chris Mason , Petr Malat , Johannes Weiner , Niket Agarwal , Yann Collet , Christoph Hellwig Subject: [PATCH v4 8/9] lib: unzstd: Switch to the zstd-1.4.6 API Date: Tue, 29 Sep 2020 23:53:17 -0700 Message-Id: <20200930065318.3326526-9-nickrterrell@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200930065318.3326526-1-nickrterrell@gmail.com> References: <20200930065318.3326526-1-nickrterrell@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Nick Terrell Move away from the compatibility wrapper to the zstd-1.4.6 API. This code is functionally equivalent. Signed-off-by: Nick Terrell --- lib/decompress_unzstd.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/decompress_unzstd.c b/lib/decompress_unzstd.c index a79f705f236d..d4685df0e120 100644 --- a/lib/decompress_unzstd.c +++ b/lib/decompress_unzstd.c @@ -73,7 +73,8 @@ #include #include -#include +#include +#include /* 128MB is the maximum window size supported by zstd. */ #define ZSTD_WINDOWSIZE_MAX (1 << ZSTD_WINDOWLOG_MAX) @@ -120,9 +121,9 @@ static int INIT decompress_single(const u8 *in_buf, long in_len, u8 *out_buf, long out_len, long *in_pos, void (*error)(char *x)) { - const size_t wksp_size = ZSTD_DCtxWorkspaceBound(); + const size_t wksp_size = ZSTD_estimateDCtxSize(); void *wksp = large_malloc(wksp_size); - ZSTD_DCtx *dctx = ZSTD_initDCtx(wksp, wksp_size); + ZSTD_DCtx *dctx = ZSTD_initStaticDCtx(wksp, wksp_size); int err; size_t ret; @@ -165,7 +166,6 @@ static int INIT __unzstd(unsigned char *in_buf, long in_len, { ZSTD_inBuffer in; ZSTD_outBuffer out; - ZSTD_frameParams params; void *in_allocated = NULL; void *out_allocated = NULL; void *wksp = NULL; @@ -229,36 +229,24 @@ static int INIT __unzstd(unsigned char *in_buf, long in_len, out.size = out_len; /* - * We need to know the window size to allocate the ZSTD_DStream. - * Since we are streaming, we need to allocate a buffer for the sliding - * window. The window size varies from 1 KB to ZSTD_WINDOWSIZE_MAX - * (8 MB), so it is important to use the actual value so as not to - * waste memory when it is smaller. + * Zstd determines the workspace size from the window size written + * into the frame header. This ensures that we use the minimum value + * possible, since the window size varies from 1 KB to ZSTD_WINDOWSIZE_MAX + * (1 GB), so it is very important to use the actual value. */ - ret = ZSTD_getFrameParams(¶ms, in.src, in.size); + wksp_size = ZSTD_estimateDStreamSize_fromFrame(in.src, in.size); err = handle_zstd_error(ret, error); if (err) goto out; - if (ret != 0) { - error("ZSTD-compressed data has an incomplete frame header"); - err = -1; - goto out; - } - if (params.windowSize > ZSTD_WINDOWSIZE_MAX) { - error("ZSTD-compressed data has too large a window size"); + wksp = large_malloc(wksp_size); + if (wksp == NULL) { + error("Out of memory while allocating ZSTD_DStream"); err = -1; goto out; } - - /* - * Allocate the ZSTD_DStream now that we know how much memory is - * required. - */ - wksp_size = ZSTD_DStreamWorkspaceBound(params.windowSize); - wksp = large_malloc(wksp_size); - dstream = ZSTD_initDStream(params.windowSize, wksp, wksp_size); + dstream = ZSTD_initStaticDStream(wksp, wksp_size); if (dstream == NULL) { - error("Out of memory while allocating ZSTD_DStream"); + error("ZSTD_initStaticDStream failed"); err = -1; goto out; } -- 2.28.0