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

Commit 8dfee8c4 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim
Browse files

f2fs: clean up hash codes



f2fs_chksum and f2fs_crc32 use the same 'crc32' crypto engine, also
their implementation are almost the same, except with different
shash description context.

Introduce __f2fs_crc32 to wrap the common codes, and reuse it in
f2fs_chksum and f2fs_crc32.

Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 5d81acf5
Loading
Loading
Loading
Loading
+19 −24
Original line number Original line Diff line number Diff line
@@ -1353,30 +1353,7 @@ static inline bool is_idle(struct f2fs_sb_info *sbi)
/*
/*
 * Inline functions
 * Inline functions
 */
 */
static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc,
			   unsigned int length)
{
	SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver);
	u32 *ctx = (u32 *)shash_desc_ctx(shash);
	int err;

	shash->tfm = sbi->s_chksum_driver;
	shash->flags = 0;
	*ctx = F2FS_SUPER_MAGIC;

	err = crypto_shash_update(shash, address, length);
	BUG_ON(err);

	return *ctx;
}

static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
				  void *buf, size_t buf_size)
{
	return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
}

static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
			      const void *address, unsigned int length)
			      const void *address, unsigned int length)
{
{
	struct {
	struct {
@@ -1397,6 +1374,24 @@ static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
	return *(u32 *)desc.ctx;
	return *(u32 *)desc.ctx;
}
}


static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
			   unsigned int length)
{
	return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length);
}

static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
				  void *buf, size_t buf_size)
{
	return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
}

static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
			      const void *address, unsigned int length)
{
	return __f2fs_crc32(sbi, crc, address, length);
}

static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
{
{
	return container_of(inode, struct f2fs_inode_info, vfs_inode);
	return container_of(inode, struct f2fs_inode_info, vfs_inode);