aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2006-01-06 03:20:32 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-06 11:34:05 -0500
commit9ffae0cf3ea02f75d163922accfd3e592d87adde (patch)
tree4974727e9f36e1b618b68d2789644ee3a0d7a371 /drivers
parent2d1f3b5d1b2cd11a162eb29645df749ec0036413 (diff)
[PATCH] md: convert md to use kzalloc throughout
Replace multiple kmalloc/memset pairs with kzalloc calls. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/bitmap.c11
-rw-r--r--drivers/md/linear.c3
-rw-r--r--drivers/md/md.c10
-rw-r--r--drivers/md/multipath.c10
-rw-r--r--drivers/md/raid0.c9
-rw-r--r--drivers/md/raid1.c20
-rw-r--r--drivers/md/raid10.c6
-rw-r--r--drivers/md/raid5.c8
8 files changed, 24 insertions, 53 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index fc05d1205aa0..c3faa6a43de1 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -887,12 +887,10 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
887 if (!bitmap->filemap) 887 if (!bitmap->filemap)
888 goto out; 888 goto out;
889 889
890 bitmap->filemap_attr = kmalloc(sizeof(long) * num_pages, GFP_KERNEL); 890 bitmap->filemap_attr = kzalloc(sizeof(long) * num_pages, GFP_KERNEL);
891 if (!bitmap->filemap_attr) 891 if (!bitmap->filemap_attr)
892 goto out; 892 goto out;
893 893
894 memset(bitmap->filemap_attr, 0, sizeof(long) * num_pages);
895
896 oldindex = ~0L; 894 oldindex = ~0L;
897 895
898 for (i = 0; i < chunks; i++) { 896 for (i = 0; i < chunks; i++) {
@@ -1557,12 +1555,10 @@ int bitmap_create(mddev_t *mddev)
1557 1555
1558 BUG_ON(file && mddev->bitmap_offset); 1556 BUG_ON(file && mddev->bitmap_offset);
1559 1557
1560 bitmap = kmalloc(sizeof(*bitmap), GFP_KERNEL); 1558 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL);
1561 if (!bitmap) 1559 if (!bitmap)
1562 return -ENOMEM; 1560 return -ENOMEM;
1563 1561
1564 memset(bitmap, 0, sizeof(*bitmap));
1565
1566 spin_lock_init(&bitmap->lock); 1562 spin_lock_init(&bitmap->lock);
1567 bitmap->mddev = mddev; 1563 bitmap->mddev = mddev;
1568 1564
@@ -1603,12 +1599,11 @@ int bitmap_create(mddev_t *mddev)
1603#ifdef INJECT_FATAL_FAULT_1 1599#ifdef INJECT_FATAL_FAULT_1
1604 bitmap->bp = NULL; 1600 bitmap->bp = NULL;
1605#else 1601#else
1606 bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); 1602 bitmap->bp = kzalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL);
1607#endif 1603#endif
1608 err = -ENOMEM; 1604 err = -ENOMEM;
1609 if (!bitmap->bp) 1605 if (!bitmap->bp)
1610 goto error; 1606 goto error;
1611 memset(bitmap->bp, 0, pages * sizeof(*bitmap->bp));
1612 1607
1613 bitmap->flags |= BITMAP_ACTIVE; 1608 bitmap->flags |= BITMAP_ACTIVE;
1614 1609
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 946efef3a8f5..f46c98d05b44 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -121,11 +121,10 @@ static int linear_run (mddev_t *mddev)
121 sector_t curr_offset; 121 sector_t curr_offset;
122 struct list_head *tmp; 122 struct list_head *tmp;
123 123
124 conf = kmalloc (sizeof (*conf) + mddev->raid_disks*sizeof(dev_info_t), 124 conf = kzalloc (sizeof (*conf) + mddev->raid_disks*sizeof(dev_info_t),
125 GFP_KERNEL); 125 GFP_KERNEL);
126 if (!conf) 126 if (!conf)
127 goto out; 127 goto out;
128 memset(conf, 0, sizeof(*conf) + mddev->raid_disks*sizeof(dev_info_t));
129 mddev->private = conf; 128 mddev->private = conf;
130 129
131 cnt = 0; 130 cnt = 0;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index c3ac67cffe62..8c378b62a676 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -228,12 +228,10 @@ static mddev_t * mddev_find(dev_t unit)
228 } 228 }
229 spin_unlock(&all_mddevs_lock); 229 spin_unlock(&all_mddevs_lock);
230 230
231 new = (mddev_t *) kmalloc(sizeof(*new), GFP_KERNEL); 231 new = kzalloc(sizeof(*new), GFP_KERNEL);
232 if (!new) 232 if (!new)
233 return NULL; 233 return NULL;
234 234
235 memset(new, 0, sizeof(*new));
236
237 new->unit = unit; 235 new->unit = unit;
238 if (MAJOR(unit) == MD_MAJOR) 236 if (MAJOR(unit) == MD_MAJOR)
239 new->md_minor = MINOR(unit); 237 new->md_minor = MINOR(unit);
@@ -1620,12 +1618,11 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
1620 mdk_rdev_t *rdev; 1618 mdk_rdev_t *rdev;
1621 sector_t size; 1619 sector_t size;
1622 1620
1623 rdev = (mdk_rdev_t *) kmalloc(sizeof(*rdev), GFP_KERNEL); 1621 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
1624 if (!rdev) { 1622 if (!rdev) {
1625 printk(KERN_ERR "md: could not alloc mem for new device!\n"); 1623 printk(KERN_ERR "md: could not alloc mem for new device!\n");
1626 return ERR_PTR(-ENOMEM); 1624 return ERR_PTR(-ENOMEM);
1627 } 1625 }
1628 memset(rdev, 0, sizeof(*rdev));
1629 1626
1630 if ((err = alloc_disk_sb(rdev))) 1627 if ((err = alloc_disk_sb(rdev)))
1631 goto abort_free; 1628 goto abort_free;
@@ -3505,11 +3502,10 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
3505{ 3502{
3506 mdk_thread_t *thread; 3503 mdk_thread_t *thread;
3507 3504
3508 thread = kmalloc(sizeof(mdk_thread_t), GFP_KERNEL); 3505 thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL);
3509 if (!thread) 3506 if (!thread)
3510 return NULL; 3507 return NULL;
3511 3508
3512 memset(thread, 0, sizeof(mdk_thread_t));
3513 init_waitqueue_head(&thread->wqueue); 3509 init_waitqueue_head(&thread->wqueue);
3514 3510
3515 thread->run = run; 3511 thread->run = run;
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 145cdc5ad008..97a56aaaef6d 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -41,9 +41,7 @@ static mdk_personality_t multipath_personality;
41static void *mp_pool_alloc(gfp_t gfp_flags, void *data) 41static void *mp_pool_alloc(gfp_t gfp_flags, void *data)
42{ 42{
43 struct multipath_bh *mpb; 43 struct multipath_bh *mpb;
44 mpb = kmalloc(sizeof(*mpb), gfp_flags); 44 mpb = kzalloc(sizeof(*mpb), gfp_flags);
45 if (mpb)
46 memset(mpb, 0, sizeof(*mpb));
47 return mpb; 45 return mpb;
48} 46}
49 47
@@ -444,7 +442,7 @@ static int multipath_run (mddev_t *mddev)
444 * should be freed in multipath_stop()] 442 * should be freed in multipath_stop()]
445 */ 443 */
446 444
447 conf = kmalloc(sizeof(multipath_conf_t), GFP_KERNEL); 445 conf = kzalloc(sizeof(multipath_conf_t), GFP_KERNEL);
448 mddev->private = conf; 446 mddev->private = conf;
449 if (!conf) { 447 if (!conf) {
450 printk(KERN_ERR 448 printk(KERN_ERR
@@ -452,9 +450,8 @@ static int multipath_run (mddev_t *mddev)
452 mdname(mddev)); 450 mdname(mddev));
453 goto out; 451 goto out;
454 } 452 }
455 memset(conf, 0, sizeof(*conf));
456 453
457 conf->multipaths = kmalloc(sizeof(struct multipath_info)*mddev->raid_disks, 454 conf->multipaths = kzalloc(sizeof(struct multipath_info)*mddev->raid_disks,
458 GFP_KERNEL); 455 GFP_KERNEL);
459 if (!conf->multipaths) { 456 if (!conf->multipaths) {
460 printk(KERN_ERR 457 printk(KERN_ERR
@@ -462,7 +459,6 @@ static int multipath_run (mddev_t *mddev)
462 mdname(mddev)); 459 mdname(mddev));
463 goto out_free_conf; 460 goto out_free_conf;
464 } 461 }
465 memset(conf->multipaths, 0, sizeof(struct multipath_info)*mddev->raid_disks);
466 462
467 conf->working_disks = 0; 463 conf->working_disks = 0;
468 ITERATE_RDEV(mddev,rdev,tmp) { 464 ITERATE_RDEV(mddev,rdev,tmp) {
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index a2c2e184c0ac..b4eaa67fabde 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -113,21 +113,16 @@ static int create_strip_zones (mddev_t *mddev)
113 } 113 }
114 printk("raid0: FINAL %d zones\n", conf->nr_strip_zones); 114 printk("raid0: FINAL %d zones\n", conf->nr_strip_zones);
115 115
116 conf->strip_zone = kmalloc(sizeof(struct strip_zone)* 116 conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
117 conf->nr_strip_zones, GFP_KERNEL); 117 conf->nr_strip_zones, GFP_KERNEL);
118 if (!conf->strip_zone) 118 if (!conf->strip_zone)
119 return 1; 119 return 1;
120 conf->devlist = kmalloc(sizeof(mdk_rdev_t*)* 120 conf->devlist = kzalloc(sizeof(mdk_rdev_t*)*
121 conf->nr_strip_zones*mddev->raid_disks, 121 conf->nr_strip_zones*mddev->raid_disks,
122 GFP_KERNEL); 122 GFP_KERNEL);
123 if (!conf->devlist) 123 if (!conf->devlist)
124 return 1; 124 return 1;
125 125
126 memset(conf->strip_zone, 0,sizeof(struct strip_zone)*
127 conf->nr_strip_zones);
128 memset(conf->devlist, 0,
129 sizeof(mdk_rdev_t*) * conf->nr_strip_zones * mddev->raid_disks);
130
131 /* The first zone must contain all devices, so here we check that 126 /* The first zone must contain all devices, so here we check that
132 * there is a proper alignment of slots to devices and find them all 127 * there is a proper alignment of slots to devices and find them all
133 */ 128 */
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index bbe0b817572b..c42ef1c99fa0 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -61,10 +61,8 @@ static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
61 int size = offsetof(r1bio_t, bios[pi->raid_disks]); 61 int size = offsetof(r1bio_t, bios[pi->raid_disks]);
62 62
63 /* allocate a r1bio with room for raid_disks entries in the bios array */ 63 /* allocate a r1bio with room for raid_disks entries in the bios array */
64 r1_bio = kmalloc(size, gfp_flags); 64 r1_bio = kzalloc(size, gfp_flags);
65 if (r1_bio) 65 if (!r1_bio)
66 memset(r1_bio, 0, size);
67 else
68 unplug_slaves(pi->mddev); 66 unplug_slaves(pi->mddev);
69 67
70 return r1_bio; 68 return r1_bio;
@@ -711,13 +709,11 @@ static struct page **alloc_behind_pages(struct bio *bio)
711{ 709{
712 int i; 710 int i;
713 struct bio_vec *bvec; 711 struct bio_vec *bvec;
714 struct page **pages = kmalloc(bio->bi_vcnt * sizeof(struct page *), 712 struct page **pages = kzalloc(bio->bi_vcnt * sizeof(struct page *),
715 GFP_NOIO); 713 GFP_NOIO);
716 if (unlikely(!pages)) 714 if (unlikely(!pages))
717 goto do_sync_io; 715 goto do_sync_io;
718 716
719 memset(pages, 0, bio->bi_vcnt * sizeof(struct page *));
720
721 bio_for_each_segment(bvec, bio, i) { 717 bio_for_each_segment(bvec, bio, i) {
722 pages[i] = alloc_page(GFP_NOIO); 718 pages[i] = alloc_page(GFP_NOIO);
723 if (unlikely(!pages[i])) 719 if (unlikely(!pages[i]))
@@ -1770,19 +1766,16 @@ static int run(mddev_t *mddev)
1770 * bookkeeping area. [whatever we allocate in run(), 1766 * bookkeeping area. [whatever we allocate in run(),
1771 * should be freed in stop()] 1767 * should be freed in stop()]
1772 */ 1768 */
1773 conf = kmalloc(sizeof(conf_t), GFP_KERNEL); 1769 conf = kzalloc(sizeof(conf_t), GFP_KERNEL);
1774 mddev->private = conf; 1770 mddev->private = conf;
1775 if (!conf) 1771 if (!conf)
1776 goto out_no_mem; 1772 goto out_no_mem;
1777 1773
1778 memset(conf, 0, sizeof(*conf)); 1774 conf->mirrors = kzalloc(sizeof(struct mirror_info)*mddev->raid_disks,
1779 conf->mirrors = kmalloc(sizeof(struct mirror_info)*mddev->raid_disks,
1780 GFP_KERNEL); 1775 GFP_KERNEL);
1781 if (!conf->mirrors) 1776 if (!conf->mirrors)
1782 goto out_no_mem; 1777 goto out_no_mem;
1783 1778
1784 memset(conf->mirrors, 0, sizeof(struct mirror_info)*mddev->raid_disks);
1785
1786 conf->tmppage = alloc_page(GFP_KERNEL); 1779 conf->tmppage = alloc_page(GFP_KERNEL);
1787 if (!conf->tmppage) 1780 if (!conf->tmppage)
1788 goto out_no_mem; 1781 goto out_no_mem;
@@ -1992,13 +1985,12 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
1992 kfree(newpoolinfo); 1985 kfree(newpoolinfo);
1993 return -ENOMEM; 1986 return -ENOMEM;
1994 } 1987 }
1995 newmirrors = kmalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL); 1988 newmirrors = kzalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL);
1996 if (!newmirrors) { 1989 if (!newmirrors) {
1997 kfree(newpoolinfo); 1990 kfree(newpoolinfo);
1998 mempool_destroy(newpool); 1991 mempool_destroy(newpool);
1999 return -ENOMEM; 1992 return -ENOMEM;
2000 } 1993 }
2001 memset(newmirrors, 0, sizeof(struct mirror_info)*raid_disks);
2002 1994
2003 raise_barrier(conf); 1995 raise_barrier(conf);
2004 1996
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index ce729d6daf78..254b50e32135 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -59,10 +59,8 @@ static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data)
59 int size = offsetof(struct r10bio_s, devs[conf->copies]); 59 int size = offsetof(struct r10bio_s, devs[conf->copies]);
60 60
61 /* allocate a r10bio with room for raid_disks entries in the bios array */ 61 /* allocate a r10bio with room for raid_disks entries in the bios array */
62 r10_bio = kmalloc(size, gfp_flags); 62 r10_bio = kzalloc(size, gfp_flags);
63 if (r10_bio) 63 if (!r10_bio)
64 memset(r10_bio, 0, size);
65 else
66 unplug_slaves(conf->mddev); 64 unplug_slaves(conf->mddev);
67 65
68 return r10_bio; 66 return r10_bio;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index ec5186fd510a..9fc50487e2ed 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1827,12 +1827,12 @@ static int run(mddev_t *mddev)
1827 return -EIO; 1827 return -EIO;
1828 } 1828 }
1829 1829
1830 mddev->private = kmalloc (sizeof (raid5_conf_t) 1830 mddev->private = kzalloc(sizeof (raid5_conf_t)
1831 + mddev->raid_disks * sizeof(struct disk_info), 1831 + mddev->raid_disks * sizeof(struct disk_info),
1832 GFP_KERNEL); 1832 GFP_KERNEL);
1833 if ((conf = mddev->private) == NULL) 1833 if ((conf = mddev->private) == NULL)
1834 goto abort; 1834 goto abort;
1835 memset (conf, 0, sizeof (*conf) + mddev->raid_disks * sizeof(struct disk_info) ); 1835
1836 conf->mddev = mddev; 1836 conf->mddev = mddev;
1837 1837
1838 if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL) 1838 if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL)