Skip to content

Commit d2ea4d2

Browse files
braunertorvalds
authored andcommitted
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: 011703a ("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>
1 parent d552fc6 commit d2ea4d2

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

include/linux/file.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,10 @@ typedef struct fd_prepare class_fd_prepare_t;
161161
/* Do not use directly. */
162162
static inline void class_fd_prepare_destructor(const struct fd_prepare *fdf)
163163
{
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-
}
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);
170168
}
171169

172170
/* Do not use directly. */
@@ -230,7 +228,8 @@ static inline int class_fd_prepare_lock_err(const struct fd_prepare *fdf)
230228
VFS_WARN_ON_ONCE(fdp->__fd < 0); \
231229
VFS_WARN_ON_ONCE(IS_ERR_OR_NULL(fdp->__file)); \
232230
fd_install(fdp->__fd, fdp->__file); \
233-
fdp->__fd; \
231+
retain_and_null_ptr(fdp->__file); \
232+
take_fd(fdp->__fd); \
234233
})
235234

236235
/* Do not use directly. */

0 commit comments

Comments
 (0)