Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

coda: use param->file for FSCONFIG_SET_FD

While the old code did support FSCONFIG_SET_FD, there's no need to
re-get the file the fs_context infrastructure already grabbed for us.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Link: https://lore.kernel.org/r/20240731-fsconfig-fsparam_fd-fixes-v2-2-e7c472224417@cyphar.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Aleksa Sarai and committed by
Christian Brauner
66e5cfee 6a64c522

+30 -13
+30 -13
fs/coda/inode.c
··· 119 119 {} 120 120 }; 121 121 122 - static int coda_parse_fd(struct fs_context *fc, int fd) 122 + static int coda_set_idx(struct fs_context *fc, struct file *file) 123 123 { 124 124 struct coda_fs_context *ctx = fc->fs_private; 125 - struct fd f; 126 125 struct inode *inode; 127 126 int idx; 128 127 129 - f = fdget(fd); 130 - if (!f.file) 131 - return -EBADF; 132 - inode = file_inode(f.file); 128 + inode = file_inode(file); 133 129 if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) { 134 - fdput(f); 135 - return invalf(fc, "code: Not coda psdev"); 130 + return invalf(fc, "coda: Not coda psdev"); 136 131 } 137 - 138 132 idx = iminor(inode); 139 - fdput(f); 140 - 141 133 if (idx < 0 || idx >= MAX_CODADEVS) 142 134 return invalf(fc, "coda: Bad minor number"); 143 135 ctx->idx = idx; 144 136 return 0; 137 + } 138 + 139 + static int coda_parse_fd(struct fs_context *fc, struct fs_parameter *param, 140 + struct fs_parse_result *result) 141 + { 142 + struct file *file; 143 + int err; 144 + 145 + if (param->type == fs_value_is_file) { 146 + file = param->file; 147 + param->file = NULL; 148 + } else { 149 + file = fget(result->uint_32); 150 + } 151 + if (!file) 152 + return -EBADF; 153 + 154 + err = coda_set_idx(fc, file); 155 + fput(file); 156 + return err; 145 157 } 146 158 147 159 static int coda_parse_param(struct fs_context *fc, struct fs_parameter *param) ··· 167 155 168 156 switch (opt) { 169 157 case Opt_fd: 170 - return coda_parse_fd(fc, result.uint_32); 158 + return coda_parse_fd(fc, param, &result); 171 159 } 172 160 173 161 return 0; ··· 179 167 */ 180 168 static int coda_parse_monolithic(struct fs_context *fc, void *_data) 181 169 { 170 + struct file *file; 182 171 struct coda_mount_data *data = _data; 183 172 184 173 if (!data) ··· 188 175 if (data->version != CODA_MOUNT_VERSION) 189 176 return invalf(fc, "coda: Bad mount version"); 190 177 191 - coda_parse_fd(fc, data->fd); 178 + file = fget(data->fd); 179 + if (file) { 180 + coda_set_idx(fc, file); 181 + fput(file); 182 + } 192 183 return 0; 193 184 } 194 185