Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp758563pxk; Wed, 23 Sep 2020 15:40:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXTBZWvyojAw1TBrxMwGPUSp5UCd76hO4T8KPbMCVpOPmxtCeN4QgCb+LfYB38ie9HrTgn X-Received: by 2002:a17:906:ca8f:: with SMTP id js15mr1863561ejb.175.1600900857382; Wed, 23 Sep 2020 15:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600900857; cv=none; d=google.com; s=arc-20160816; b=WHDt1kyh+BpmL7ydHiTB75bZr00eMB+BKeT949erPhkX5yThlKLOcDnwWqXEJU+Qhd cmhP1BTTU9AgynB7J7PE0NAvD79MFFLl2aCsqTW5aMsrC+74nhm+ohfn7cjbC4UrlioG c6IG0eHHgjs1iMHbufxJiVDWmeEWVuNwvouWgUb1o7aiOQdN1iHeMqa4gLCyHu9oMWrI IRJ4wmgYo5TwY/N6pZmSUZhdWczqeAPt0wSmkg6Fpe/17Qyiuub+qOUXc301iFmxw3ao P0b0cpO8kbWGel/eQ96JZXQwqwDP7snPHLUHjqhGi/1/Gf3puE6i+JDEONt/qY9frOp6 Xpuw== 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=wTTZHqC13YBiTeGBG2EUXuQH+szEiZCcwoaXpEP61XtI055qzLzgVDi+L/13pz2YA4 s0j9yfXeVuf/dLqW7Hw9+16hAM3KcIk/pdI0fb0OPFa96iIUuJLsxKE0LsZWMbVgwkxF I+l0kvSYj5qOcnMxOOEwEURMZDS5I6EsLR6viwlp5CUVhMc7cW/Zt4pg1ek1HWxgYlFk i5D5dfjGz+0XmGyfD7VEjrdYGxfZ6E5z1TDXMxN5yqubYeXvHC+W1mgHBw+4gyGuIv6L i1i3eIccExkIz2kKE5+HXDx0Dp+H8eQ4JiVIUYc2MhZD08WlRCrKP8HJyUwfzuI9LoHs VNUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TRVB6YoA; 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 f9si861814edt.429.2020.09.23.15.40.34; Wed, 23 Sep 2020 15:40:57 -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=TRVB6YoA; 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 S1726830AbgIWWja (ORCPT + 99 others); Wed, 23 Sep 2020 18:39:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbgIWWj0 (ORCPT ); Wed, 23 Sep 2020 18:39:26 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46602C0613CE; Wed, 23 Sep 2020 15:39:26 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id r19so533386pls.1; Wed, 23 Sep 2020 15:39:26 -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=TRVB6YoAJ0whsK+JjLavKdJGY910o0e55vCsOmMG9xOulamN8dC7oZ8uJso8ou7iIh cT2++GvOks3i+kEPb27o/tjpP5i8/0VtKYd912AYbMhR99Yh4EV3Bt5n6fwG1TkqFiFE 76h+nTXm95grDzfW+KAOQfJbQcORBGoQkmsSayb2HokQQQDDts/vhCWaDr1ax2j6qtgh 4C1IjOzK7SUrwd2plPI5/2zb3R2vHAROky+6r9P1JTlZamQzzJQCmhhLtFbxgAXWVFl/ mq3Vs56RuvFxfUY2iXYJoaxw1OCuLjRoRYQL3XPjXqCFVGm39zPt1BxZZFPvt0XM+JSD PUMg== 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=fyaRDnyPAiKLfD6Q5jlxTxITfz+sFN/LdFYcufTGIZiU5OzynS/gaLo8J02W1kCLGD tC9gfdh2sxSQACFP3VExkTb3SstoQ+2BtN5WhvI5LH73+PG28z3+mLBc6dbRMj8P+hud /iWYaWIJEm6ekwc6xvJPYIjHL6Wx58m+2plGVHWb1t5sKF2uaDzGetzSADCu4wt402xH JosVTp4nNBlN+40j1SVdlzOJI/SXAfEV8gPmLY5MJAUYl7tJC8aBc1IkkcJutJhfdzOo dh90FTDuAwpbENYd6kGrYGdEtlb8C0WnCs9Wb8a+YsngSRAGGjXRWb4JmayXOk4fMJcM 5uXg== X-Gm-Message-State: AOAM532jymGncwwrRF8comvXBEXw6ob03UrBaLW42cJZCMj0ivWQebKX vrd/Ew/Ti9jwt/z5P1JlEAw= X-Received: by 2002:a17:90a:ff92:: with SMTP id hf18mr1341818pjb.51.1600900765752; Wed, 23 Sep 2020 15:39:25 -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 d20sm417964pjv.39.2020.09.23.15.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 15:39:25 -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 v3 8/9] lib: unzstd: Switch to the zstd-1.4.6 API Date: Wed, 23 Sep 2020 15:42:05 -0700 Message-Id: <20200923224206.68968-9-nickrterrell@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200923224206.68968-1-nickrterrell@gmail.com> References: <20200923224206.68968-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