2014-01-08 01:57:30

by Muthu Kumar

[permalink] [raw]
Subject: [block:for-3.14/core]: bio_endio: Warn and free bio if bi_end_io is not set.

Jens,
In bio_endio if bio doesn't have bi_end_io (should be an error case),
we set bio to NULL and continue silently without freeing the bio. It
would be good to have a WARN and free the bio to avoid memory leak.

If you agree, here is the patch.

---------
bio_endio: Warn and free bio if bi_end_io is not set

Signed-off-by: Muthukumar Ratty <[email protected]>
--------
fs/bio.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/fs/bio.c b/fs/bio.c
index 75c49a3..581806d 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1768,8 +1768,15 @@ void bio_endio(struct bio *bio, int error)
bio_put(bio);
bio = parent;
} else {
- if (bio->bi_end_io)
+ if (likely(bio->bi_end_io)) {
bio->bi_end_io(bio, error);
+ } else {
+ char dev_name[BDEVNAME_SIZE];
+ WARN(1, "bio_endio: bio for device %s without endio\n",
+ bio->bi_bdev ? bdevname(bio->bi_bdev,
dev_name) : "(unknown)");
+ bio_put(bio);
+ }
+
bio = NULL;
}
}

---------------


2014-01-08 16:35:15

by Jens Axboe

[permalink] [raw]
Subject: Re: [block:for-3.14/core]: bio_endio: Warn and free bio if bi_end_io is not set.

On 01/07/2014 06:57 PM, Muthu Kumar wrote:
> Jens,
> In bio_endio if bio doesn't have bi_end_io (should be an error case),
> we set bio to NULL and continue silently without freeing the bio. It
> would be good to have a WARN and free the bio to avoid memory leak.
>
> If you agree, here is the patch.

I don't remember off the top of my head if there are valid uses cases of
it. But leaking it would definitely be problematic. So I think it's a
good idea to queue it up, then we'll see if it triggers anything.

--
Jens Axboe