Commit ad1ee2b1 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Fix odd code in bio_add_page

From: Neil Brown <neilb@cse.unsw.edu.au>

With the current code in bio_add_page, if fail_segments is ever set, it
stays set, so bio_add_page will eventually fail having recounted the
segmentation once.

I don't think this is intended.  This patch changes the code to allow
success if the recounting the segments helps.

(Jens has acked this)
parent 36f9e5f4
......@@ -296,7 +296,7 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len,
unsigned int offset)
{
request_queue_t *q = bdev_get_queue(bio->bi_bdev);
int fail_segments = 0, retried_segments = 0;
int retried_segments = 0;
struct bio_vec *bvec;
/*
......@@ -315,18 +315,15 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len,
* we might lose a segment or two here, but rather that than
* make this too complex.
*/
retry_segments:
if (bio_phys_segments(q, bio) >= q->max_phys_segments
|| bio_hw_segments(q, bio) >= q->max_hw_segments)
fail_segments = 1;
if (fail_segments) {
while (bio_phys_segments(q, bio) >= q->max_phys_segments
|| bio_hw_segments(q, bio) >= q->max_hw_segments) {
if (retried_segments)
return 0;
bio->bi_flags &= ~(1 << BIO_SEG_VALID);
retried_segments = 1;
goto retry_segments;
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment