* [PATCH] block: Fix a memory leak in bdev_open_by_dev()
@ 2023-12-24 17:36 Christophe JAILLET
2023-12-26 8:40 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christophe JAILLET @ 2023-12-24 17:36 UTC (permalink / raw)
To: Jens Axboe, Jan Kara, Christian Brauner
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-block
If we early exit here, 'handle' needs to be freed, or some memory leaks.
Fixes: ed5cc702d311 ("block: Add config option to not allow writing to mounted devices")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
The code could also be re-arranged to delay the memory allocation.
This would be cleaner IMHO.
---
block/bdev.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 6f73b02d549c..e9f1b12bd75c 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -830,8 +830,10 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
goto free_handle;
/* Blocking writes requires exclusive opener */
- if (mode & BLK_OPEN_RESTRICT_WRITES && !holder)
- return ERR_PTR(-EINVAL);
+ if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) {
+ ret = -EINVAL;
+ goto free_handle;
+ }
bdev = blkdev_get_no_open(dev);
if (!bdev) {
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] block: Fix a memory leak in bdev_open_by_dev()
2023-12-24 17:36 [PATCH] block: Fix a memory leak in bdev_open_by_dev() Christophe JAILLET
@ 2023-12-26 8:40 ` Christoph Hellwig
2023-12-26 16:27 ` Jens Axboe
2023-12-28 10:48 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2023-12-26 8:40 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Jens Axboe, Jan Kara, Christian Brauner, linux-kernel,
kernel-janitors, linux-block
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] block: Fix a memory leak in bdev_open_by_dev()
2023-12-24 17:36 [PATCH] block: Fix a memory leak in bdev_open_by_dev() Christophe JAILLET
2023-12-26 8:40 ` Christoph Hellwig
@ 2023-12-26 16:27 ` Jens Axboe
2023-12-28 10:48 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2023-12-26 16:27 UTC (permalink / raw)
To: Christophe JAILLET, Jan Kara, Christian Brauner
Cc: linux-kernel, kernel-janitors, linux-block
On 12/24/23 10:36 AM, Christophe JAILLET wrote:
> If we early exit here, 'handle' needs to be freed, or some memory leaks.
Reviewed-by: Jens Axboe <axboe@kernel.dk>
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] block: Fix a memory leak in bdev_open_by_dev()
2023-12-24 17:36 [PATCH] block: Fix a memory leak in bdev_open_by_dev() Christophe JAILLET
2023-12-26 8:40 ` Christoph Hellwig
2023-12-26 16:27 ` Jens Axboe
@ 2023-12-28 10:48 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2023-12-28 10:48 UTC (permalink / raw)
To: Jens Axboe, Jan Kara, Christophe JAILLET
Cc: Christian Brauner, linux-kernel, kernel-janitors, linux-block
On Sun, 24 Dec 2023 18:36:42 +0100, Christophe JAILLET wrote:
> If we early exit here, 'handle' needs to be freed, or some memory leaks.
>
>
Applied to the vfs.super branch of the vfs/vfs.git tree.
Patches in the vfs.super branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.super
[1/1] block: Fix a memory leak in bdev_open_by_dev()
https://git.kernel.org/vfs/vfs/c/8ff363ade395
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-12-28 10:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-24 17:36 [PATCH] block: Fix a memory leak in bdev_open_by_dev() Christophe JAILLET
2023-12-26 8:40 ` Christoph Hellwig
2023-12-26 16:27 ` Jens Axboe
2023-12-28 10:48 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox