提交 9ffae0cf 编写于 作者: N NeilBrown 提交者: Linus Torvalds

[PATCH] md: convert md to use kzalloc throughout

Replace multiple kmalloc/memset pairs with kzalloc calls.
Signed-off-by: NNeil Brown <neilb@suse.de>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 2d1f3b5d
...@@ -887,12 +887,10 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) ...@@ -887,12 +887,10 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
if (!bitmap->filemap) if (!bitmap->filemap)
goto out; goto out;
bitmap->filemap_attr = kmalloc(sizeof(long) * num_pages, GFP_KERNEL); bitmap->filemap_attr = kzalloc(sizeof(long) * num_pages, GFP_KERNEL);
if (!bitmap->filemap_attr) if (!bitmap->filemap_attr)
goto out; goto out;
memset(bitmap->filemap_attr, 0, sizeof(long) * num_pages);
oldindex = ~0L; oldindex = ~0L;
for (i = 0; i < chunks; i++) { for (i = 0; i < chunks; i++) {
...@@ -1557,12 +1555,10 @@ int bitmap_create(mddev_t *mddev) ...@@ -1557,12 +1555,10 @@ int bitmap_create(mddev_t *mddev)
BUG_ON(file && mddev->bitmap_offset); BUG_ON(file && mddev->bitmap_offset);
bitmap = kmalloc(sizeof(*bitmap), GFP_KERNEL); bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL);
if (!bitmap) if (!bitmap)
return -ENOMEM; return -ENOMEM;
memset(bitmap, 0, sizeof(*bitmap));
spin_lock_init(&bitmap->lock); spin_lock_init(&bitmap->lock);
bitmap->mddev = mddev; bitmap->mddev = mddev;
...@@ -1603,12 +1599,11 @@ int bitmap_create(mddev_t *mddev) ...@@ -1603,12 +1599,11 @@ int bitmap_create(mddev_t *mddev)
#ifdef INJECT_FATAL_FAULT_1 #ifdef INJECT_FATAL_FAULT_1
bitmap->bp = NULL; bitmap->bp = NULL;
#else #else
bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); bitmap->bp = kzalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL);
#endif #endif
err = -ENOMEM; err = -ENOMEM;
if (!bitmap->bp) if (!bitmap->bp)
goto error; goto error;
memset(bitmap->bp, 0, pages * sizeof(*bitmap->bp));
bitmap->flags |= BITMAP_ACTIVE; bitmap->flags |= BITMAP_ACTIVE;
......
...@@ -121,11 +121,10 @@ static int linear_run (mddev_t *mddev) ...@@ -121,11 +121,10 @@ static int linear_run (mddev_t *mddev)
sector_t curr_offset; sector_t curr_offset;
struct list_head *tmp; struct list_head *tmp;
conf = kmalloc (sizeof (*conf) + mddev->raid_disks*sizeof(dev_info_t), conf = kzalloc (sizeof (*conf) + mddev->raid_disks*sizeof(dev_info_t),
GFP_KERNEL); GFP_KERNEL);
if (!conf) if (!conf)
goto out; goto out;
memset(conf, 0, sizeof(*conf) + mddev->raid_disks*sizeof(dev_info_t));
mddev->private = conf; mddev->private = conf;
cnt = 0; cnt = 0;
......
...@@ -228,12 +228,10 @@ static mddev_t * mddev_find(dev_t unit) ...@@ -228,12 +228,10 @@ static mddev_t * mddev_find(dev_t unit)
} }
spin_unlock(&all_mddevs_lock); spin_unlock(&all_mddevs_lock);
new = (mddev_t *) kmalloc(sizeof(*new), GFP_KERNEL); new = kzalloc(sizeof(*new), GFP_KERNEL);
if (!new) if (!new)
return NULL; return NULL;
memset(new, 0, sizeof(*new));
new->unit = unit; new->unit = unit;
if (MAJOR(unit) == MD_MAJOR) if (MAJOR(unit) == MD_MAJOR)
new->md_minor = MINOR(unit); 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,12 +1618,11 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
sector_t size; sector_t size;
rdev = (mdk_rdev_t *) kmalloc(sizeof(*rdev), GFP_KERNEL); rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
if (!rdev) { if (!rdev) {
printk(KERN_ERR "md: could not alloc mem for new device!\n"); printk(KERN_ERR "md: could not alloc mem for new device!\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
memset(rdev, 0, sizeof(*rdev));
if ((err = alloc_disk_sb(rdev))) if ((err = alloc_disk_sb(rdev)))
goto abort_free; goto abort_free;
...@@ -3505,11 +3502,10 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, ...@@ -3505,11 +3502,10 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
{ {
mdk_thread_t *thread; mdk_thread_t *thread;
thread = kmalloc(sizeof(mdk_thread_t), GFP_KERNEL); thread = kzalloc(sizeof(mdk_thread_t), GFP_KERNEL);
if (!thread) if (!thread)
return NULL; return NULL;
memset(thread, 0, sizeof(mdk_thread_t));
init_waitqueue_head(&thread->wqueue); init_waitqueue_head(&thread->wqueue);
thread->run = run; thread->run = run;
......
...@@ -41,9 +41,7 @@ static mdk_personality_t multipath_personality; ...@@ -41,9 +41,7 @@ static mdk_personality_t multipath_personality;
static void *mp_pool_alloc(gfp_t gfp_flags, void *data) static void *mp_pool_alloc(gfp_t gfp_flags, void *data)
{ {
struct multipath_bh *mpb; struct multipath_bh *mpb;
mpb = kmalloc(sizeof(*mpb), gfp_flags); mpb = kzalloc(sizeof(*mpb), gfp_flags);
if (mpb)
memset(mpb, 0, sizeof(*mpb));
return mpb; return mpb;
} }
...@@ -444,7 +442,7 @@ static int multipath_run (mddev_t *mddev) ...@@ -444,7 +442,7 @@ static int multipath_run (mddev_t *mddev)
* should be freed in multipath_stop()] * should be freed in multipath_stop()]
*/ */
conf = kmalloc(sizeof(multipath_conf_t), GFP_KERNEL); conf = kzalloc(sizeof(multipath_conf_t), GFP_KERNEL);
mddev->private = conf; mddev->private = conf;
if (!conf) { if (!conf) {
printk(KERN_ERR printk(KERN_ERR
...@@ -452,9 +450,8 @@ static int multipath_run (mddev_t *mddev) ...@@ -452,9 +450,8 @@ static int multipath_run (mddev_t *mddev)
mdname(mddev)); mdname(mddev));
goto out; goto out;
} }
memset(conf, 0, sizeof(*conf));
conf->multipaths = kmalloc(sizeof(struct multipath_info)*mddev->raid_disks, conf->multipaths = kzalloc(sizeof(struct multipath_info)*mddev->raid_disks,
GFP_KERNEL); GFP_KERNEL);
if (!conf->multipaths) { if (!conf->multipaths) {
printk(KERN_ERR printk(KERN_ERR
...@@ -462,7 +459,6 @@ static int multipath_run (mddev_t *mddev) ...@@ -462,7 +459,6 @@ static int multipath_run (mddev_t *mddev)
mdname(mddev)); mdname(mddev));
goto out_free_conf; goto out_free_conf;
} }
memset(conf->multipaths, 0, sizeof(struct multipath_info)*mddev->raid_disks);
conf->working_disks = 0; conf->working_disks = 0;
ITERATE_RDEV(mddev,rdev,tmp) { ITERATE_RDEV(mddev,rdev,tmp) {
......
...@@ -113,21 +113,16 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -113,21 +113,16 @@ static int create_strip_zones (mddev_t *mddev)
} }
printk("raid0: FINAL %d zones\n", conf->nr_strip_zones); printk("raid0: FINAL %d zones\n", conf->nr_strip_zones);
conf->strip_zone = kmalloc(sizeof(struct strip_zone)* conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
conf->nr_strip_zones, GFP_KERNEL); conf->nr_strip_zones, GFP_KERNEL);
if (!conf->strip_zone) if (!conf->strip_zone)
return 1; return 1;
conf->devlist = kmalloc(sizeof(mdk_rdev_t*)* conf->devlist = kzalloc(sizeof(mdk_rdev_t*)*
conf->nr_strip_zones*mddev->raid_disks, conf->nr_strip_zones*mddev->raid_disks,
GFP_KERNEL); GFP_KERNEL);
if (!conf->devlist) if (!conf->devlist)
return 1; return 1;
memset(conf->strip_zone, 0,sizeof(struct strip_zone)*
conf->nr_strip_zones);
memset(conf->devlist, 0,
sizeof(mdk_rdev_t*) * conf->nr_strip_zones * mddev->raid_disks);
/* The first zone must contain all devices, so here we check that /* The first zone must contain all devices, so here we check that
* there is a proper alignment of slots to devices and find them all * there is a proper alignment of slots to devices and find them all
*/ */
......
...@@ -61,10 +61,8 @@ static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data) ...@@ -61,10 +61,8 @@ static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
int size = offsetof(r1bio_t, bios[pi->raid_disks]); int size = offsetof(r1bio_t, bios[pi->raid_disks]);
/* allocate a r1bio with room for raid_disks entries in the bios array */ /* allocate a r1bio with room for raid_disks entries in the bios array */
r1_bio = kmalloc(size, gfp_flags); r1_bio = kzalloc(size, gfp_flags);
if (r1_bio) if (!r1_bio)
memset(r1_bio, 0, size);
else
unplug_slaves(pi->mddev); unplug_slaves(pi->mddev);
return r1_bio; return r1_bio;
...@@ -711,13 +709,11 @@ static struct page **alloc_behind_pages(struct bio *bio) ...@@ -711,13 +709,11 @@ static struct page **alloc_behind_pages(struct bio *bio)
{ {
int i; int i;
struct bio_vec *bvec; struct bio_vec *bvec;
struct page **pages = kmalloc(bio->bi_vcnt * sizeof(struct page *), struct page **pages = kzalloc(bio->bi_vcnt * sizeof(struct page *),
GFP_NOIO); GFP_NOIO);
if (unlikely(!pages)) if (unlikely(!pages))
goto do_sync_io; goto do_sync_io;
memset(pages, 0, bio->bi_vcnt * sizeof(struct page *));
bio_for_each_segment(bvec, bio, i) { bio_for_each_segment(bvec, bio, i) {
pages[i] = alloc_page(GFP_NOIO); pages[i] = alloc_page(GFP_NOIO);
if (unlikely(!pages[i])) if (unlikely(!pages[i]))
...@@ -1770,19 +1766,16 @@ static int run(mddev_t *mddev) ...@@ -1770,19 +1766,16 @@ static int run(mddev_t *mddev)
* bookkeeping area. [whatever we allocate in run(), * bookkeeping area. [whatever we allocate in run(),
* should be freed in stop()] * should be freed in stop()]
*/ */
conf = kmalloc(sizeof(conf_t), GFP_KERNEL); conf = kzalloc(sizeof(conf_t), GFP_KERNEL);
mddev->private = conf; mddev->private = conf;
if (!conf) if (!conf)
goto out_no_mem; goto out_no_mem;
memset(conf, 0, sizeof(*conf)); conf->mirrors = kzalloc(sizeof(struct mirror_info)*mddev->raid_disks,
conf->mirrors = kmalloc(sizeof(struct mirror_info)*mddev->raid_disks,
GFP_KERNEL); GFP_KERNEL);
if (!conf->mirrors) if (!conf->mirrors)
goto out_no_mem; goto out_no_mem;
memset(conf->mirrors, 0, sizeof(struct mirror_info)*mddev->raid_disks);
conf->tmppage = alloc_page(GFP_KERNEL); conf->tmppage = alloc_page(GFP_KERNEL);
if (!conf->tmppage) if (!conf->tmppage)
goto out_no_mem; goto out_no_mem;
...@@ -1992,13 +1985,12 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks) ...@@ -1992,13 +1985,12 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
kfree(newpoolinfo); kfree(newpoolinfo);
return -ENOMEM; return -ENOMEM;
} }
newmirrors = kmalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL); newmirrors = kzalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL);
if (!newmirrors) { if (!newmirrors) {
kfree(newpoolinfo); kfree(newpoolinfo);
mempool_destroy(newpool); mempool_destroy(newpool);
return -ENOMEM; return -ENOMEM;
} }
memset(newmirrors, 0, sizeof(struct mirror_info)*raid_disks);
raise_barrier(conf); raise_barrier(conf);
......
...@@ -59,10 +59,8 @@ static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data) ...@@ -59,10 +59,8 @@ static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data)
int size = offsetof(struct r10bio_s, devs[conf->copies]); int size = offsetof(struct r10bio_s, devs[conf->copies]);
/* allocate a r10bio with room for raid_disks entries in the bios array */ /* allocate a r10bio with room for raid_disks entries in the bios array */
r10_bio = kmalloc(size, gfp_flags); r10_bio = kzalloc(size, gfp_flags);
if (r10_bio) if (!r10_bio)
memset(r10_bio, 0, size);
else
unplug_slaves(conf->mddev); unplug_slaves(conf->mddev);
return r10_bio; return r10_bio;
......
...@@ -1827,12 +1827,12 @@ static int run(mddev_t *mddev) ...@@ -1827,12 +1827,12 @@ static int run(mddev_t *mddev)
return -EIO; return -EIO;
} }
mddev->private = kmalloc (sizeof (raid5_conf_t) mddev->private = kzalloc(sizeof (raid5_conf_t)
+ mddev->raid_disks * sizeof(struct disk_info), + mddev->raid_disks * sizeof(struct disk_info),
GFP_KERNEL); GFP_KERNEL);
if ((conf = mddev->private) == NULL) if ((conf = mddev->private) == NULL)
goto abort; goto abort;
memset (conf, 0, sizeof (*conf) + mddev->raid_disks * sizeof(struct disk_info) );
conf->mddev = mddev; conf->mddev = mddev;
if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL) if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册