linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] btrfs: fix for refcount leak in btrfs_do_write_iter()
@ 2022-09-26 16:31 Stefan Roesch
  2022-09-27 12:11 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Roesch @ 2022-09-26 16:31 UTC (permalink / raw)
  To: kernel-team, linux-btrfs
  Cc: shr, axboe, josef, dan.carpenter, dsterba, fdmanana

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(-)

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) {

base-commit: f76349cf41451c5c42a99f18a9163377e4b364ff
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] btrfs: fix for refcount leak in btrfs_do_write_iter()
  2022-09-26 16:31 [PATCH v1] btrfs: fix for refcount leak in btrfs_do_write_iter() Stefan Roesch
@ 2022-09-27 12:11 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2022-09-27 12:11 UTC (permalink / raw)
  To: Stefan Roesch
  Cc: kernel-team, linux-btrfs, axboe, josef, dan.carpenter, dsterba, fdmanana

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-27 12:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 16:31 [PATCH v1] btrfs: fix for refcount leak in btrfs_do_write_iter() Stefan Roesch
2022-09-27 12:11 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).