Message ID | 20220926163150.1535808-1-shr@fb.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v1] btrfs: fix for refcount leak in btrfs_do_write_iter() | expand |
On Mon, Sep 26, 2022 at 09:31:50AM -0700, Stefan Roesch wrote: > The patch "btrfs: enable nowait async buffered writes" introduced a > potential leak in btrfs_do_write_iter() that the count for sync_writers > is increased, but not decreased. > > This commit addresses this problem. > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com> > Signed-off-by: Stefan Roesch <shr@fb.com> Folded to the patch, thanks.
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 16052903fa82..c5ea8e545641 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2106,14 +2106,13 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from, */ if (BTRFS_FS_ERROR(inode->root->fs_info)) return -EROFS; + if (encoded && (iocb->ki_flags & IOCB_NOWAIT)) + return -EOPNOTSUPP; if (sync) atomic_inc(&inode->sync_writers); if (encoded) { - if (iocb->ki_flags & IOCB_NOWAIT) - return -EOPNOTSUPP; - num_written = btrfs_encoded_write(iocb, from, encoded); num_sync = encoded->len; } else if (iocb->ki_flags & IOCB_DIRECT) {
The patch "btrfs: enable nowait async buffered writes" introduced a potential leak in btrfs_do_write_iter() that the count for sync_writers is increased, but not decreased. This commit addresses this problem. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Stefan Roesch <shr@fb.com> --- fs/btrfs/file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) base-commit: f76349cf41451c5c42a99f18a9163377e4b364ff