From patchwork Tue Aug 18 15:17:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Marcos Costa X-Patchwork-Id: 1347027 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BWF0t3Mh2z9sVf for ; Wed, 19 Aug 2020 01:18:22 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D301E82274; Tue, 18 Aug 2020 17:17:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 238E882250; Tue, 18 Aug 2020 17:17:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS,SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0C76F8222C for ; Tue, 18 Aug 2020 17:17:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joaomarcos.costa@bootlin.com X-Originating-IP: 46.193.64.106 Received: from localhost.localdomain (eth-east-parth2-46-193-64-106.wb.wifirst.net [46.193.64.106]) (Authenticated sender: joaomarcos.costa@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPA id 399C82000C; Tue, 18 Aug 2020 15:17:27 +0000 (UTC) From: Joao Marcos Costa To: u-boot@lists.denx.de Cc: joaomarcos.costa@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com Subject: [PATCH v4 2/5] fs/squashfs: replace sqfs_decompress() parameter Date: Tue, 18 Aug 2020 17:17:22 +0200 Message-Id: <20200818151725.11293-3-joaomarcos.costa@bootlin.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200818151725.11293-1-joaomarcos.costa@bootlin.com> References: <20200818151725.11293-1-joaomarcos.costa@bootlin.com> 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.102.3 at phobos.denx.de X-Virus-Status: Clean Replace 'u16 comp_type' by a reference to squashfs_ctxt structure. Signed-off-by: Joao Marcos Costa --- Changes in v4: - This patch was not present in the previous version. fs/squashfs/sqfs.c | 25 +++++++++---------------- fs/squashfs/sqfs_decompressor.c | 5 +++-- fs/squashfs/sqfs_decompressor.h | 4 ++-- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 598b42cd34..9bd7b98d88 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -104,9 +104,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index, struct squashfs_super_block *sblk = ctxt.sblk; unsigned long dest_len; int block, offset, ret; - u16 header, comp_type; - - comp_type = get_unaligned_le16(&sblk->compression); + u16 header; if (inode_fragment_index >= get_unaligned_le32(&sblk->fragments)) return -EINVAL; @@ -165,7 +163,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index, if (SQFS_COMPRESSED_METADATA(header)) { src_len = SQFS_METADATA_SIZE(header); dest_len = SQFS_METADATA_BLOCK_SIZE; - ret = sqfs_decompress(comp_type, entries, &dest_len, metadata, + ret = sqfs_decompress(&ctxt, entries, &dest_len, metadata, src_len); if (ret) { ret = -EINVAL; @@ -629,13 +627,12 @@ static int sqfs_read_inode_table(unsigned char **inode_table) { struct squashfs_super_block *sblk = ctxt.sblk; u64 start, n_blks, table_offset, table_size; - int j, ret = 0, metablks_count, comp_type; + int j, ret = 0, metablks_count; unsigned char *src_table, *itb; u32 src_len, dest_offset = 0; unsigned long dest_len; bool compressed; - comp_type = get_unaligned_le16(&sblk->compression); table_size = get_unaligned_le64(&sblk->directory_table_start) - get_unaligned_le64(&sblk->inode_table_start); start = get_unaligned_le64(&sblk->inode_table_start) / @@ -680,7 +677,7 @@ static int sqfs_read_inode_table(unsigned char **inode_table) sqfs_read_metablock(itb, table_offset, &compressed, &src_len); if (compressed) { dest_len = SQFS_METADATA_BLOCK_SIZE; - ret = sqfs_decompress(comp_type, *inode_table + + ret = sqfs_decompress(&ctxt, *inode_table + dest_offset, &dest_len, src_table, src_len); if (ret) { @@ -711,15 +708,13 @@ free_itb: static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list) { u64 start, n_blks, table_offset, table_size; - int j, ret = 0, metablks_count = -1, comp_type; struct squashfs_super_block *sblk = ctxt.sblk; + int j, ret = 0, metablks_count = -1; unsigned char *src_table, *dtb; u32 src_len, dest_offset = 0; unsigned long dest_len; bool compressed; - comp_type = get_unaligned_le16(&sblk->compression); - /* DIRECTORY TABLE */ table_size = get_unaligned_le64(&sblk->fragment_table_start) - get_unaligned_le64(&sblk->directory_table_start); @@ -773,7 +768,7 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list) sqfs_read_metablock(dtb, table_offset, &compressed, &src_len); if (compressed) { dest_len = SQFS_METADATA_BLOCK_SIZE; - ret = sqfs_decompress(comp_type, *dir_table + + ret = sqfs_decompress(&ctxt, *dir_table + (j * SQFS_METADATA_BLOCK_SIZE), &dest_len, src_table, src_len); if (ret) { @@ -1197,7 +1192,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, char *dir, *fragment_block, *datablock = NULL, *data_buffer = NULL; char *fragment, *file, *resolved, *data; u64 start, n_blks, table_size, data_offset, table_offset; - int ret, j, i_number, comp_type, datablk_count = 0; + int ret, j, i_number, datablk_count = 0; struct squashfs_super_block *sblk = ctxt.sblk; struct squashfs_fragment_block_entry frag_entry; struct squashfs_file_info finfo = {0}; @@ -1213,8 +1208,6 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, *actread = 0; - comp_type = get_unaligned_le16(&sblk->compression); - /* * sqfs_opendir will uncompress inode and directory tables, and will * return a pointer to the directory that contains the requested file. @@ -1346,7 +1339,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, /* Load the data */ if (SQFS_COMPRESSED_BLOCK(finfo.blk_sizes[j])) { dest_len = get_unaligned_le32(&sblk->block_size); - ret = sqfs_decompress(comp_type, datablock, &dest_len, + ret = sqfs_decompress(&ctxt, datablock, &dest_len, data, table_size); if (ret) goto free_buffer; @@ -1396,7 +1389,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, goto free_fragment; } - ret = sqfs_decompress(comp_type, fragment_block, &dest_len, + ret = sqfs_decompress(&ctxt, fragment_block, &dest_len, (void *)fragment + table_offset, frag_entry.size); if (ret) { diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c index 633a8a1818..cf388ace58 100644 --- a/fs/squashfs/sqfs_decompressor.c +++ b/fs/squashfs/sqfs_decompressor.c @@ -62,9 +62,10 @@ static void zlib_decompression_status(int ret) } #endif -int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, - void *source, u32 src_len) +int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest, + unsigned long *dest_len, void *source, u32 src_len) { + u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression); int ret = 0; switch (comp_type) { diff --git a/fs/squashfs/sqfs_decompressor.h b/fs/squashfs/sqfs_decompressor.h index 450257e5ce..892cfb6974 100644 --- a/fs/squashfs/sqfs_decompressor.h +++ b/fs/squashfs/sqfs_decompressor.h @@ -53,8 +53,8 @@ union squashfs_compression_opts { struct squashfs_lzo_opts *lzo; }; -int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, - void *source, u32 lenp); +int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest, + unsigned long *dest_len, void *source, u32 src_len); int sqfs_decompressor_init(struct squashfs_ctxt *ctxt); void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt);