Commit 42c3732f authored by Chuck Lever's avatar Chuck Lever
Browse files

fs: Create a generic is_dot_dotdot() utility



De-duplicate the same functionality in several places by hoisting
the is_dot_dotdot() utility function into linux/fs.h.

Suggested-by: default avatarAmir Goldstein <amir73il@gmail.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 9473c445
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -74,13 +74,7 @@ struct fscrypt_nokey_name {

static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
{
	if (str->len == 1 && str->name[0] == '.')
		return true;

	if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
		return true;

	return false;
	return is_dot_dotdot(str->name, str->len);
}

/**
+0 −10
Original line number Diff line number Diff line
@@ -1949,16 +1949,6 @@ int ecryptfs_encrypt_and_encode_filename(
	return rc;
}

static bool is_dot_dotdot(const char *name, size_t name_size)
{
	if (name_size == 1 && name[0] == '.')
		return true;
	else if (name_size == 2 && name[0] == '.' && name[1] == '.')
		return true;

	return false;
}

/**
 * ecryptfs_decode_and_decrypt_filename - converts the encoded cipher text name to decoded plaintext
 * @plaintext_name: The plaintext name
+0 −10
Original line number Diff line number Diff line
@@ -244,16 +244,6 @@ struct getdents_callback {
	int sequence;		/* sequence counter */
};

/* Copied from lookup_one_common() */
static inline bool is_dot_dotdot(const char *name, size_t len)
{
	if (unlikely(name[0] == '.')) {
		if (len < 2 || (len == 2 && name[1] == '.'))
			return true;
	}
	return false;
}

/*
 * A rather strange filldir function to capture
 * the name matching the specified inode number.
+0 −11
Original line number Diff line number Diff line
@@ -3368,17 +3368,6 @@ static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
	return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
}

static inline bool is_dot_dotdot(const u8 *name, size_t len)
{
	if (len == 1 && name[0] == '.')
		return true;

	if (len == 2 && name[0] == '.' && name[1] == '.')
		return true;

	return false;
}

static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
					size_t size, gfp_t flags)
{
+2 −4
Original line number Diff line number Diff line
@@ -2667,10 +2667,8 @@ static int lookup_one_common(struct mnt_idmap *idmap,
	if (!len)
		return -EACCES;

	if (unlikely(name[0] == '.')) {
		if (len < 2 || (len == 2 && name[1] == '.'))
	if (is_dot_dotdot(name, len))
		return -EACCES;
	}

	while (len--) {
		unsigned int c = *(const unsigned char *)name++;
Loading