file: ensure cleanup

Brown paper bag time. This is a silly oversight where I missed to drop
the error condition checking to ensure we clean up on early error
returns. I have an internal unit testset coming up for this which will
catch all such issues going forward.

Reported-by: Chris Mason <clm@fb.com>
Reported-by: Jeff Layton <jlayton@kernel.org>
Fixes: 011703a9acd7 ("file: add FD_{ADD,PREPARE}()")
Signed-off-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Christian Brauner and committed by Linus Torvalds d2ea4d25 d552fc63

+6 -7
+6 -7
include/linux/file.h
··· 161 /* Do not use directly. */ 162 static inline void class_fd_prepare_destructor(const struct fd_prepare *fdf) 163 { 164 - if (unlikely(fdf->err)) { 165 - if (likely(fdf->__fd >= 0)) 166 - put_unused_fd(fdf->__fd); 167 - if (unlikely(!IS_ERR_OR_NULL(fdf->__file))) 168 - fput(fdf->__file); 169 - } 170 } 171 172 /* Do not use directly. */ ··· 228 VFS_WARN_ON_ONCE(fdp->__fd < 0); \ 229 VFS_WARN_ON_ONCE(IS_ERR_OR_NULL(fdp->__file)); \ 230 fd_install(fdp->__fd, fdp->__file); \ 231 - fdp->__fd; \ 232 }) 233 234 /* Do not use directly. */
··· 161 /* Do not use directly. */ 162 static inline void class_fd_prepare_destructor(const struct fd_prepare *fdf) 163 { 164 + if (unlikely(fdf->__fd >= 0)) 165 + put_unused_fd(fdf->__fd); 166 + if (unlikely(!IS_ERR_OR_NULL(fdf->__file))) 167 + fput(fdf->__file); 168 } 169 170 /* Do not use directly. */ ··· 230 VFS_WARN_ON_ONCE(fdp->__fd < 0); \ 231 VFS_WARN_ON_ONCE(IS_ERR_OR_NULL(fdp->__file)); \ 232 fd_install(fdp->__fd, fdp->__file); \ 233 + retain_and_null_ptr(fdp->__file); \ 234 + take_fd(fdp->__fd); \ 235 }) 236 237 /* Do not use directly. */