From 483887d651ebea298740f7fe895dd948df452d9f Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 23 Jun 2022 12:54:22 -0700 Subject: [PATCH] ANDROID: Incremental fs: Use ERR_CAST in handle_mapped_file() When building android-mainline with a version of clang that supports CONFIG_RANDSTRUCT, there are errors about casts from randomized structures to non-randomized structures: fs/incfs/data_mgmt.c:240:10: error: casting from randomized structure pointer type 'struct dentry *' to 'struct data_file *' return (struct data_file *)index_file_dentry; ^ fs/incfs/data_mgmt.c:257:12: error: casting from randomized structure pointer type 'struct file *' to 'struct data_file *' result = (struct data_file *)bf; ^ 2 errors generated. As suggested by Kees on aosp/1995750, these casts should actually be using the ERR_CAST macro, which is a more proper way to pass error pointers around. Change-Id: Iab73ac7503235f1147154a01a22ab8608e3daf8b Fixes: 3f4938108a7a ("ANDROID: Incremental fs: Create mapped file") Link: https://github.com/ClangBuiltLinux/linux/issues/1652 Suggested-by: Kees Cook Signed-off-by: Nathan Chancellor --- fs/incfs/data_mgmt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/incfs/data_mgmt.c b/fs/incfs/data_mgmt.c index 7d8b25954c98..01ee5d286554 100644 --- a/fs/incfs/data_mgmt.c +++ b/fs/incfs/data_mgmt.c @@ -237,7 +237,7 @@ static struct data_file *handle_mapped_file(struct mount_info *mi, if (!index_file_dentry) return ERR_PTR(-ENOENT); if (IS_ERR(index_file_dentry)) - return (struct data_file *)index_file_dentry; + return ERR_CAST(index_file_dentry); if (!d_really_is_positive(index_file_dentry)) { result = ERR_PTR(-ENOENT); goto out; @@ -254,7 +254,7 @@ static struct data_file *handle_mapped_file(struct mount_info *mi, revert_creds(old_cred); if (IS_ERR(bf)) { - result = (struct data_file *)bf; + result = ERR_CAST(bf); goto out; }