Commit 1345b1d8 authored by NeilBrown's avatar NeilBrown Committed by Linus Torvalds

[PATCH] md: define and use safe_put_page for md

md sometimes call put_page on NULL pointers (treating it like kfree).  This is
not safe, so define and use a 'safe_put_page' which checks for NULL.
Signed-off-by: default avatarNeil Brown <neilb@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 7dd5d34c
...@@ -626,8 +626,7 @@ static void bitmap_file_unmap(struct bitmap *bitmap) ...@@ -626,8 +626,7 @@ static void bitmap_file_unmap(struct bitmap *bitmap)
kfree(map); kfree(map);
kfree(attr); kfree(attr);
if (sb_page) safe_put_page(sb_page);
put_page(sb_page);
} }
static void bitmap_stop_daemon(struct bitmap *bitmap); static void bitmap_stop_daemon(struct bitmap *bitmap);
......
...@@ -136,7 +136,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data) ...@@ -136,7 +136,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
out_free_pages: out_free_pages:
for (i=0; i < RESYNC_PAGES ; i++) for (i=0; i < RESYNC_PAGES ; i++)
for (j=0 ; j < pi->raid_disks; j++) for (j=0 ; j < pi->raid_disks; j++)
put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page); safe_put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page);
j = -1; j = -1;
out_free_bio: out_free_bio:
while ( ++j < pi->raid_disks ) while ( ++j < pi->raid_disks )
...@@ -156,7 +156,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data) ...@@ -156,7 +156,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data)
if (j == 0 || if (j == 0 ||
r1bio->bios[j]->bi_io_vec[i].bv_page != r1bio->bios[j]->bi_io_vec[i].bv_page !=
r1bio->bios[0]->bi_io_vec[i].bv_page) r1bio->bios[0]->bi_io_vec[i].bv_page)
put_page(r1bio->bios[j]->bi_io_vec[i].bv_page); safe_put_page(r1bio->bios[j]->bi_io_vec[i].bv_page);
} }
for (i=0 ; i < pi->raid_disks; i++) for (i=0 ; i < pi->raid_disks; i++)
bio_put(r1bio->bios[i]); bio_put(r1bio->bios[i]);
...@@ -381,7 +381,7 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int ...@@ -381,7 +381,7 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
/* free extra copy of the data pages */ /* free extra copy of the data pages */
int i = bio->bi_vcnt; int i = bio->bi_vcnt;
while (i--) while (i--)
put_page(bio->bi_io_vec[i].bv_page); safe_put_page(bio->bi_io_vec[i].bv_page);
} }
/* clear the bitmap if all writes complete successfully */ /* clear the bitmap if all writes complete successfully */
bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector, bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
...@@ -1907,7 +1907,7 @@ static int run(mddev_t *mddev) ...@@ -1907,7 +1907,7 @@ static int run(mddev_t *mddev)
if (conf->r1bio_pool) if (conf->r1bio_pool)
mempool_destroy(conf->r1bio_pool); mempool_destroy(conf->r1bio_pool);
kfree(conf->mirrors); kfree(conf->mirrors);
put_page(conf->tmppage); safe_put_page(conf->tmppage);
kfree(conf->poolinfo); kfree(conf->poolinfo);
kfree(conf); kfree(conf);
mddev->private = NULL; mddev->private = NULL;
......
...@@ -132,10 +132,10 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data) ...@@ -132,10 +132,10 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
out_free_pages: out_free_pages:
for ( ; i > 0 ; i--) for ( ; i > 0 ; i--)
put_page(bio->bi_io_vec[i-1].bv_page); safe_put_page(bio->bi_io_vec[i-1].bv_page);
while (j--) while (j--)
for (i = 0; i < RESYNC_PAGES ; i++) for (i = 0; i < RESYNC_PAGES ; i++)
put_page(r10_bio->devs[j].bio->bi_io_vec[i].bv_page); safe_put_page(r10_bio->devs[j].bio->bi_io_vec[i].bv_page);
j = -1; j = -1;
out_free_bio: out_free_bio:
while ( ++j < nalloc ) while ( ++j < nalloc )
...@@ -155,7 +155,7 @@ static void r10buf_pool_free(void *__r10_bio, void *data) ...@@ -155,7 +155,7 @@ static void r10buf_pool_free(void *__r10_bio, void *data)
struct bio *bio = r10bio->devs[j].bio; struct bio *bio = r10bio->devs[j].bio;
if (bio) { if (bio) {
for (i = 0; i < RESYNC_PAGES; i++) { for (i = 0; i < RESYNC_PAGES; i++) {
put_page(bio->bi_io_vec[i].bv_page); safe_put_page(bio->bi_io_vec[i].bv_page);
bio->bi_io_vec[i].bv_page = NULL; bio->bi_io_vec[i].bv_page = NULL;
} }
bio_put(bio); bio_put(bio);
...@@ -2042,7 +2042,7 @@ static int run(mddev_t *mddev) ...@@ -2042,7 +2042,7 @@ static int run(mddev_t *mddev)
out_free_conf: out_free_conf:
if (conf->r10bio_pool) if (conf->r10bio_pool)
mempool_destroy(conf->r10bio_pool); mempool_destroy(conf->r10bio_pool);
put_page(conf->tmppage); safe_put_page(conf->tmppage);
kfree(conf->mirrors); kfree(conf->mirrors);
kfree(conf); kfree(conf);
mddev->private = NULL; mddev->private = NULL;
......
...@@ -2072,8 +2072,7 @@ static int run(mddev_t *mddev) ...@@ -2072,8 +2072,7 @@ static int run(mddev_t *mddev)
abort: abort:
if (conf) { if (conf) {
print_raid6_conf(conf); print_raid6_conf(conf);
if (conf->spare_page) safe_put_page(conf->spare_page);
put_page(conf->spare_page);
kfree(conf->stripe_hashtbl); kfree(conf->stripe_hashtbl);
kfree(conf); kfree(conf);
} }
......
...@@ -324,5 +324,10 @@ do { \ ...@@ -324,5 +324,10 @@ do { \
__wait_event_lock_irq(wq, condition, lock, cmd); \ __wait_event_lock_irq(wq, condition, lock, cmd); \
} while (0) } while (0)
static inline void safe_put_page(struct page *p)
{
if (p) put_page(p);
}
#endif #endif
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