Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82de647e authored by Phillip Lougher's avatar Phillip Lougher
Browse files

Squashfs: move table allocation into squashfs_read_table()



This eliminates a lot of duplicate code.

Signed-off-by: default avatarPhillip Lougher <phillip@lougher.demon.co.uk>
parent 117a91e0
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -393,19 +393,36 @@ struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *sb,
/*
 * Read a filesystem table (uncompressed sequence of bytes) from disk
 */
int squashfs_read_table(struct super_block *sb, void *buffer, u64 block,
	int length)
void *squashfs_read_table(struct super_block *sb, u64 block, int length)
{
	int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
	int i, res;
	void **data = kcalloc(pages, sizeof(void *), GFP_KERNEL);
	if (data == NULL)
		return -ENOMEM;
	void *table, *buffer, **data;

	table = buffer = kmalloc(length, GFP_KERNEL);
	if (table == NULL)
		return ERR_PTR(-ENOMEM);

	data = kcalloc(pages, sizeof(void *), GFP_KERNEL);
	if (data == NULL) {
		res = -ENOMEM;
		goto failed;
	}

	for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE)
		data[i] = buffer;

	res = squashfs_read_data(sb, data, block, length |
		SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length, pages);

	kfree(data);
	return res;

	if (res < 0)
		goto failed;

	return table;

failed:
	kfree(table);
	return ERR_PTR(res);
}
+1 −18
Original line number Diff line number Diff line
@@ -124,27 +124,10 @@ __le64 *squashfs_read_inode_lookup_table(struct super_block *sb,
		u64 lookup_table_start, unsigned int inodes)
{
	unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(inodes);
	__le64 *inode_lookup_table;
	int err;

	TRACE("In read_inode_lookup_table, length %d\n", length);

	/* Allocate inode lookup table indexes */
	inode_lookup_table = kmalloc(length, GFP_KERNEL);
	if (inode_lookup_table == NULL) {
		ERROR("Failed to allocate inode lookup table\n");
		return ERR_PTR(-ENOMEM);
	}

	err = squashfs_read_table(sb, inode_lookup_table, lookup_table_start,
			length);
	if (err < 0) {
		ERROR("unable to read inode lookup table\n");
		kfree(inode_lookup_table);
		return ERR_PTR(err);
	}

	return inode_lookup_table;
	return squashfs_read_table(sb, lookup_table_start, length);
}


+1 −18
Original line number Diff line number Diff line
@@ -74,23 +74,6 @@ __le64 *squashfs_read_fragment_index_table(struct super_block *sb,
	u64 fragment_table_start, unsigned int fragments)
{
	unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(fragments);
	__le64 *fragment_index;
	int err;

	/* Allocate fragment lookup table indexes */
	fragment_index = kmalloc(length, GFP_KERNEL);
	if (fragment_index == NULL) {
		ERROR("Failed to allocate fragment index table\n");
		return ERR_PTR(-ENOMEM);
	}

	err = squashfs_read_table(sb, fragment_index, fragment_table_start,
			length);
	if (err < 0) {
		ERROR("unable to read fragment index table\n");
		kfree(fragment_index);
		return ERR_PTR(err);
	}

	return fragment_index;
	return squashfs_read_table(sb, fragment_table_start, length);
}
+1 −17
Original line number Diff line number Diff line
@@ -69,24 +69,8 @@ __le64 *squashfs_read_id_index_table(struct super_block *sb,
			u64 id_table_start, unsigned short no_ids)
{
	unsigned int length = SQUASHFS_ID_BLOCK_BYTES(no_ids);
	__le64 *id_table;
	int err;

	TRACE("In read_id_index_table, length %d\n", length);

	/* Allocate id lookup table indexes */
	id_table = kmalloc(length, GFP_KERNEL);
	if (id_table == NULL) {
		ERROR("Failed to allocate id index table\n");
		return ERR_PTR(-ENOMEM);
	}

	err = squashfs_read_table(sb, id_table, id_table_start, length);
	if (err < 0) {
		ERROR("unable to read id index table\n");
		kfree(id_table);
		return ERR_PTR(err);
	}

	return id_table;
	return squashfs_read_table(sb, id_table_start, length);
}
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ extern struct squashfs_cache_entry *squashfs_get_fragment(struct super_block *,
				u64, int);
extern struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *,
				u64, int);
extern int squashfs_read_table(struct super_block *, void *, u64, int);
extern void *squashfs_read_table(struct super_block *, u64, int);

/* decompressor.c */
extern const struct squashfs_decompressor *squashfs_lookup_decompressor(int);
Loading