From patchwork Mon May 25 06:32:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 246457 List-Id: U-Boot discussion From: wqu at suse.com (Qu Wenruo) Date: Mon, 25 May 2020 14:32:45 +0800 Subject: [PATCH U-BOOT v2 18/30] fs: btrfs: inode: Allow next_length() to return value > BTRFS_NAME_LEN In-Reply-To: <20200525063257.46757-1-wqu@suse.com> References: <20200525063257.46757-1-wqu@suse.com> Message-ID: <20200525063257.46757-19-wqu@suse.com> All existing next_length() caller handles return value > BTRFS_NAME_LEN, so there is no need to do BTRFS_NAME_LEN check in next_length(). But still, we want to exit early if we're beyond BTRFS_NAME_LEN, so this patch will make next_length() to exit as soon as we're beyond BTRFS_NAME_LEN. Signed-off-by: Qu Wenruo --- fs/btrfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 007cf32c1603..da2a5e90a1bf 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -217,8 +217,12 @@ static u64 __get_parent_inode(struct __btrfs_root *root, u64 inr, static inline int next_length(const char *path) { int res = 0; - while (*path != '\0' && *path != '/' && res <= BTRFS_NAME_LEN) - ++res, ++path; + while (*path != '\0' && *path != '/') { + ++res; + ++path; + if (res > BTRFS_NAME_LEN) + break; + } return res; }