From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3285CC433EF for ; Sat, 25 Sep 2021 13:04:23 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A602E610D1 for ; Sat, 25 Sep 2021 13:04:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A602E610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 463D48353F; Sat, 25 Sep 2021 15:04:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="XUo59DhW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1B86F834F7; Sat, 25 Sep 2021 15:03:52 +0200 (CEST) Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C90678350F for ; Sat, 25 Sep 2021 15:03:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x332.google.com with SMTP id l16-20020a9d6a90000000b0053b71f7dc83so17095704otq.7 for ; Sat, 25 Sep 2021 06:03:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AZMLR2YM1XO17D4m4Ty/KBD0j1RBNwXeY6ejt2Yvh+A=; b=XUo59DhWnfMIju4TnDUuHaKTiqsts3VCzp/c6JgyUZgeqmz95VuvXu/r/4Kzp0x5yR L/FpvBfnrhP7cT62zdjK4pcNAzkXI9EC+pjWd42u+XU31W4EH9WwCtiph6wPpmMMo6Ch PT92M7eU7qI9oZPJM3vX6OtCozaUArKbkO+kA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AZMLR2YM1XO17D4m4Ty/KBD0j1RBNwXeY6ejt2Yvh+A=; b=IOP5RYfki+h1sxP9ItQeP8InUpc0mXie1SGAx7uWjr7fhESeCKlD3Kvl7eK9JGVf6t wk/hJP5ayk/h1TqGgNd6opHkJ3gNiL7rmeeKzYmOQrbggGxAbY2nvM/d4Wb4548gbzAR UH6Ql6OIlpl/8y5LhfbC5AXvUPjAJrpfiqyvUmqnmRfiPc+UHwt/hqBafM7tZ4bSvhxQ jSt1Fl7uelSAgeEpIBOEfoh7sxDusMxviGxTL8+cSMuW8nRAs6RkrsE13Qri4ZJi5+dR /aG+U810gTjTmb9JjvgA/G29PhiIgh7ue681jo2vYLXqvqWJ+wJ2ionfCadq3vHN2tAf K6Yg== X-Gm-Message-State: AOAM530eGBEiFHV8huySxEhd3PmAlrpqgITs8SUubojQjOeI5H41ZbyE dZ6JRZV//fSFKug3haY1DMlxLKJAwXpHAw== X-Google-Smtp-Source: ABdhPJz2D3rzN5MobfF6vw0YFPKv7bXcbpUsrymgjZyE6AMZqHl4+kRx8nlDNMha4n+ghe4lrtXSZA== X-Received: by 2002:a05:6830:452:: with SMTP id d18mr8941611otc.364.1632575023166; Sat, 25 Sep 2021 06:03:43 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id f61sm2770018otf.73.2021.09.25.06.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Sep 2021 06:03:42 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Alexandru Gagniuc , Bin Meng , Tom Rini , Simon Glass , Qu Wenruo Subject: [PATCH v4 05/15] btrfs: Use U-Boot API for decompression Date: Sat, 25 Sep 2021 07:03:10 -0600 Message-Id: <20210925070255.v4.5.Id825318e5d23be3df49050827e4b0f071647b3a8@changeid> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog In-Reply-To: <20210925130320.7824-1-sjg@chromium.org> References: <20210925130320.7824-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Use the common function to avoid code duplication. Acked-by: Qu Wenruo Signed-off-by: Simon Glass --- (no changes since v1) fs/btrfs/compression.c | 51 +++++------------------------------------- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 23efefa1997..7adfbb04a7c 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -6,6 +6,7 @@ */ #include "btrfs.h" +#include #include #include #include @@ -136,54 +137,12 @@ static u32 decompress_zlib(const u8 *_cbuf, u32 clen, u8 *dbuf, u32 dlen) static u32 decompress_zstd(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen) { - ZSTD_DStream *dstream; - ZSTD_inBuffer in_buf; - ZSTD_outBuffer out_buf; - void *workspace; - size_t wsize; - u32 res = -1; - - wsize = ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT); - workspace = malloc(wsize); - if (!workspace) { - debug("%s: cannot allocate workspace of size %zu\n", __func__, - wsize); - return -1; - } - - dstream = ZSTD_initDStream(ZSTD_BTRFS_MAX_INPUT, workspace, wsize); - if (!dstream) { - printf("%s: ZSTD_initDStream failed\n", __func__); - goto err_free; - } + struct abuf in, out; - in_buf.src = cbuf; - in_buf.pos = 0; - in_buf.size = clen; + abuf_init_set(&in, (u8 *)cbuf, clen); + abuf_init_set(&out, dbuf, dlen); - out_buf.dst = dbuf; - out_buf.pos = 0; - out_buf.size = dlen; - - while (1) { - size_t ret; - - ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf); - if (ZSTD_isError(ret)) { - printf("%s: ZSTD_decompressStream error %d\n", __func__, - ZSTD_getErrorCode(ret)); - goto err_free; - } - - if (in_buf.pos >= clen || !ret) - break; - } - - res = out_buf.pos; - -err_free: - free(workspace); - return res; + return zstd_decompress(&in, &out); } u32 btrfs_decompress(u8 type, const char *c, u32 clen, char *d, u32 dlen) -- 2.33.0.685.g46640cef36-goog