* [PATCH] block-map: added error handling for bio_copy_kern()
[not found] <CGME20210928063420epcms2p8f0cad25e1b820169755962ff4555d3ac@epcms2p1>
@ 2021-09-28 6:39 ` Jinyoung CHOI
2021-10-12 6:24 ` Christoph Hellwig
[not found] ` <CGME20210928063420epcms2p8f0cad25e1b820169755962ff4555d3ac@epcms2p6>
0 siblings, 2 replies; 3+ messages in thread
From: Jinyoung CHOI @ 2021-09-28 6:39 UTC (permalink / raw)
To: axboe, linux-block, linux-kernel
When new pages are allocated to bio through alloc_page() in
bio_copy_kern(), the pages must be freed in error handling after that.
There is little chance of an error occurring in blk_rq_append_bio(), but
in the code flow, pages additionally allocated to bio must be released.
Signed-off-by: Jinyoung Choi <j-young.choi@samsung.com>
---
block/blk-map.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/block/blk-map.c b/block/blk-map.c
index 4526adde0156..584369a7837f 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -628,6 +628,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
int reading = rq_data_dir(rq) == READ;
unsigned long addr = (unsigned long) kbuf;
struct bio *bio;
+ int do_copy = 0;
int ret;
if (len > (queue_max_hw_sectors(q) << 9))
@@ -635,8 +636,9 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
if (!len || !kbuf)
return -EINVAL;
- if (!blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) ||
- blk_queue_may_bounce(q))
+ do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) ||
+ blk_queue_may_bounce(q);
+ if (do_copy)
bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
else
bio = bio_map_kern(q, kbuf, len, gfp_mask);
@@ -648,8 +650,11 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
bio->bi_opf |= req_op(rq);
ret = blk_rq_append_bio(rq, bio);
- if (unlikely(ret))
+ if (unlikely(ret)) {
+ if (do_copy)
+ bio_free_pages(bio);
bio_put(bio);
+ }
return ret;
}
EXPORT_SYMBOL(blk_rq_map_kern);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block-map: added error handling for bio_copy_kern()
2021-09-28 6:39 ` [PATCH] block-map: added error handling for bio_copy_kern() Jinyoung CHOI
@ 2021-10-12 6:24 ` Christoph Hellwig
[not found] ` <CGME20210928063420epcms2p8f0cad25e1b820169755962ff4555d3ac@epcms2p6>
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-10-12 6:24 UTC (permalink / raw)
To: Jinyoung CHOI; +Cc: axboe, linux-block, linux-kernel
> + int do_copy = 0;
Please make this a bool. Otherwise the patch looks good.
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] block-map: added error handling for bio_copy_kern()
[not found] ` <CGME20210928063420epcms2p8f0cad25e1b820169755962ff4555d3ac@epcms2p6>
@ 2021-10-12 8:55 ` Jinyoung CHOI
0 siblings, 0 replies; 3+ messages in thread
From: Jinyoung CHOI @ 2021-10-12 8:55 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: axboe, linux-block, linux-kernel
Hi, Christoph.
Thanks for your review.
>> + int do_copy = 0;
>
>Please make this a bool. Otherwise the patch looks good.
Yes, bool is better. Will update in the next version. Thanks.
Best Regards,
Jinyoung Choi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-12 8:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20210928063420epcms2p8f0cad25e1b820169755962ff4555d3ac@epcms2p1>
2021-09-28 6:39 ` [PATCH] block-map: added error handling for bio_copy_kern() Jinyoung CHOI
2021-10-12 6:24 ` Christoph Hellwig
[not found] ` <CGME20210928063420epcms2p8f0cad25e1b820169755962ff4555d3ac@epcms2p6>
2021-10-12 8:55 ` Jinyoung CHOI
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.