Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * This file is part of UBIFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006-2008 Nokia Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2006, 2007 University of Szeged, Hungary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Authors: Adrian Hunter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *          Artem Bityutskiy (Битюцкий Артём)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *          Zoltan Sogor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * This file provides a single place to access to compression and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * decompression.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "ubifs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* Fake description object for the "none" compressor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static struct ubifs_compressor none_compr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	.compr_type = UBIFS_COMPR_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	.name = "none",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.capi_name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #ifdef CONFIG_UBIFS_FS_LZO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static DEFINE_MUTEX(lzo_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct ubifs_compressor lzo_compr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.compr_type = UBIFS_COMPR_LZO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.comp_mutex = &lzo_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.name = "lzo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.capi_name = "lzo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static struct ubifs_compressor lzo_compr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	.compr_type = UBIFS_COMPR_LZO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.name = "lzo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #ifdef CONFIG_UBIFS_FS_ZLIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static DEFINE_MUTEX(deflate_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static DEFINE_MUTEX(inflate_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static struct ubifs_compressor zlib_compr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.compr_type = UBIFS_COMPR_ZLIB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.comp_mutex = &deflate_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.decomp_mutex = &inflate_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.name = "zlib",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.capi_name = "deflate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static struct ubifs_compressor zlib_compr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.compr_type = UBIFS_COMPR_ZLIB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.name = "zlib",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #ifdef CONFIG_UBIFS_FS_ZSTD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static DEFINE_MUTEX(zstd_enc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static DEFINE_MUTEX(zstd_dec_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static struct ubifs_compressor zstd_compr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.compr_type = UBIFS_COMPR_ZSTD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.comp_mutex = &zstd_enc_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.decomp_mutex = &zstd_dec_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.name = "zstd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.capi_name = "zstd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static struct ubifs_compressor zstd_compr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.compr_type = UBIFS_COMPR_ZSTD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.name = "zstd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) /* All UBIFS compressors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * ubifs_compress - compress data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @in_buf: data to compress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @in_len: length of the data to compress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * @out_buf: output buffer where compressed data should be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * @out_len: output buffer length is returned here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * @compr_type: type of compression to use on enter, actually used compression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *              type on exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * This function compresses input buffer @in_buf of length @in_len and stores
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * the result in the output buffer @out_buf and the resulting length in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * @out_len. If the input buffer does not compress, it is just copied to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * @out_buf. The same happens if @compr_type is %UBIFS_COMPR_NONE or if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * compression error occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * Note, if the input buffer was not compressed, it is copied to the output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * buffer and %UBIFS_COMPR_NONE is returned in @compr_type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		    int in_len, void *out_buf, int *out_len, int *compr_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct ubifs_compressor *compr = ubifs_compressors[*compr_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (*compr_type == UBIFS_COMPR_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto no_compr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* If the input data is small, do not even try to compress it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (in_len < UBIFS_MIN_COMPR_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		goto no_compr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (compr->comp_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		mutex_lock(compr->comp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	err = crypto_comp_compress(compr->cc, in_buf, in_len, out_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				   (unsigned int *)out_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (compr->comp_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		mutex_unlock(compr->comp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		ubifs_warn(c, "cannot compress %d bytes, compressor %s, error %d, leave data uncompressed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			   in_len, compr->name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		goto no_compr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * If the data compressed only slightly, it is better to leave it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 * uncompressed to improve read speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (in_len - *out_len < UBIFS_MIN_COMPRESS_DIFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		goto no_compr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) no_compr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	memcpy(out_buf, in_buf, in_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	*out_len = in_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	*compr_type = UBIFS_COMPR_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * ubifs_decompress - decompress data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * @in_buf: data to decompress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * @in_len: length of the data to decompress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * @out_buf: output buffer where decompressed data should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @out_len: output length is returned here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * @compr_type: type of compression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * This function decompresses data from buffer @in_buf into buffer @out_buf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * The length of the uncompressed data is returned in @out_len. This functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * returns %0 on success or a negative error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		     int in_len, void *out_buf, int *out_len, int compr_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct ubifs_compressor *compr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (unlikely(compr_type < 0 || compr_type >= UBIFS_COMPR_TYPES_CNT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		ubifs_err(c, "invalid compression type %d", compr_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	compr = ubifs_compressors[compr_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (unlikely(!compr->capi_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		ubifs_err(c, "%s compression is not compiled in", compr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (compr_type == UBIFS_COMPR_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		memcpy(out_buf, in_buf, in_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		*out_len = in_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (compr->decomp_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		mutex_lock(compr->decomp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	err = crypto_comp_decompress(compr->cc, in_buf, in_len, out_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				     (unsigned int *)out_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (compr->decomp_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		mutex_unlock(compr->decomp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		ubifs_err(c, "cannot decompress %d bytes, compressor %s, error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			  in_len, compr->name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * compr_init - initialize a compressor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * @compr: compressor description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * This function initializes the requested compressor and returns zero in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * of success or a negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int __init compr_init(struct ubifs_compressor *compr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (compr->capi_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		compr->cc = crypto_alloc_comp(compr->capi_name, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		if (IS_ERR(compr->cc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			pr_err("UBIFS error (pid %d): cannot initialize compressor %s, error %ld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			       current->pid, compr->name, PTR_ERR(compr->cc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			return PTR_ERR(compr->cc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ubifs_compressors[compr->compr_type] = compr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * compr_exit - de-initialize a compressor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * @compr: compressor description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void compr_exit(struct ubifs_compressor *compr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (compr->capi_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		crypto_free_comp(compr->cc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * ubifs_compressors_init - initialize UBIFS compressors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * This function initializes the compressor which were compiled in. Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * zero in case of success and a negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int __init ubifs_compressors_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	err = compr_init(&lzo_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	err = compr_init(&zstd_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		goto out_lzo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	err = compr_init(&zlib_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		goto out_zstd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	ubifs_compressors[UBIFS_COMPR_NONE] = &none_compr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) out_zstd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	compr_exit(&zstd_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) out_lzo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	compr_exit(&lzo_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * ubifs_compressors_exit - de-initialize UBIFS compressors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void ubifs_compressors_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	compr_exit(&lzo_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	compr_exit(&zlib_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	compr_exit(&zstd_compr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }