[PATCH] md: define and use safe_put_page for md
authorNeilBrown <neilb@suse.de>
Fri, 6 Jan 2006 08:20:40 +0000 (00:20 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 6 Jan 2006 16:34:07 +0000 (08:34 -0800)
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: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/md/bitmap.c
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid6main.c
include/linux/raid/md_k.h

index abe415f0c0397dddca68ec8f4777a56685787246..ee4a3424a8a316b2f1888507b5a469fae0fd6f14 100644 (file)
@@ -626,8 +626,7 @@ static void bitmap_file_unmap(struct bitmap *bitmap)
        kfree(map);
        kfree(attr);
 
-       if (sb_page)
-               put_page(sb_page);
+       safe_put_page(sb_page);
 }
 
 static void bitmap_stop_daemon(struct bitmap *bitmap);
index 39c10a65683d8a749a8f11952fe2e07b7377be90..feea4eeca1d9cf520856260a992140375974c2f7 100644 (file)
@@ -136,7 +136,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
 out_free_pages:
        for (i=0; i < RESYNC_PAGES ; i++)
                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;
 out_free_bio:
        while ( ++j < pi->raid_disks )
@@ -156,7 +156,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data)
                        if (j == 0 ||
                            r1bio->bios[j]->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++)
                bio_put(r1bio->bios[i]);
@@ -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 */
                        int i = bio->bi_vcnt;
                        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 */
                bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
@@ -1907,7 +1907,7 @@ out_free_conf:
                if (conf->r1bio_pool)
                        mempool_destroy(conf->r1bio_pool);
                kfree(conf->mirrors);
-               put_page(conf->tmppage);
+               safe_put_page(conf->tmppage);
                kfree(conf->poolinfo);
                kfree(conf);
                mddev->private = NULL;
index 9647ebb0983a58b932d5a4d26b6f5fc3420ef66a..fb952000fae2177d2564407347eeec27ba9bfb41 100644 (file)
@@ -132,10 +132,10 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
 
 out_free_pages:
        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--)
                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;
 out_free_bio:
        while ( ++j < nalloc )
@@ -155,7 +155,7 @@ static void r10buf_pool_free(void *__r10_bio, void *data)
                struct bio *bio = r10bio->devs[j].bio;
                if (bio) {
                        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_put(bio);
@@ -2042,7 +2042,7 @@ static int run(mddev_t *mddev)
 out_free_conf:
        if (conf->r10bio_pool)
                mempool_destroy(conf->r10bio_pool);
-       put_page(conf->tmppage);
+       safe_put_page(conf->tmppage);
        kfree(conf->mirrors);
        kfree(conf);
        mddev->private = NULL;
index 950e5fa6e1f2ffd9348ae81cda34a6e8f37be226..06b32bd671a352d22c152f2302844fbcf525da6c 100644 (file)
@@ -2072,8 +2072,7 @@ static int run(mddev_t *mddev)
 abort:
        if (conf) {
                print_raid6_conf(conf);
-               if (conf->spare_page)
-                       put_page(conf->spare_page);
+               safe_put_page(conf->spare_page);
                kfree(conf->stripe_hashtbl);
                kfree(conf);
        }
index e559fb701aa1c727934191e7135e688be5dee7e2..12b3203e3419f25158b3b004ceafaf3a06529e07 100644 (file)
@@ -324,5 +324,10 @@ do {                                                                       \
        __wait_event_lock_irq(wq, condition, lock, cmd);                \
 } while (0)
 
+static inline void safe_put_page(struct page *p)
+{
+       if (p) put_page(p);
+}
+
 #endif