dm: device mapper code cleanup.
Subsystems (2)
I've prepared patch-set which i hope makes dm code safer and better :)
- First tree patches fix various leaks.
- Last five patches just convert kmalloc + memset couple to single kzalloc (probably it should be folded to one commit).
PATCH 1/8 dm: Add missing 'kfree' to dm-crypt target constructor.
--- drivers/md/dm-crypt.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/md/dm-crypt.c +1 -0
@@ -175,6 +175,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,if (err) { ti->error ="Error calculating hash in ESSIV" ; +kfree (salt);return err; }
Signature · 1 line
1.5.2.2
PATCH 2/8 dm: Fix workqueue leak for raid5
In reply to Dmitry Monakhov--- drivers/md/raid5.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/md/raid5.c +2 -0
@@ -4985,6 +4985,8 @@ static int run(mddev_t *mddev) abort:if (conf) {print_raid5_conf (conf); +if (conf->workqueue) +destroy_workqueue (conf->workqueue);safe_put_page (conf->spare_page);kfree (conf->disks);kfree (conf->stripe_hashtbl);
Signature · 1 line
1.5.2.2
Re: [PATCH 2/8] dm: Fix workqueue leak for raid5
Quoted 10 lines · Dmitry Monakhov
Signed-off-by Dmitry Monakhov <[email protected]>--- drivers/md/raid5.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)drivers/md/raid5.c +0
-0
drivers/md/raid5.c static int run(mddev_t *mddev)
Quoted 9 lines
drivers/md/raid5.c +2
-1@@ -4985,6 +4985,8 @@ static int run(mddev_t *mddev) abort:if (conf) {print_raid5_conf (conf); +if (conf->workqueue) +destroy_workqueue (conf->workqueue);safe_put_page (conf->spare_page);kfree (conf->disks);kfree (conf->stripe_hashtbl); --
I assume this patch is against -mm. I will fold it into:
git://lost.foo-projects.org/~dwillia2/git/iop md-for-linus
Thanks,
Dan
PATCH 3/8 dm: dm-raid1 resource leaks fixes.
In reply to Dmitry Monakhov- Add missing 'dm_io_client_destroy' to alloc_context error path.
- Reorganize mirror constructor error path in order to prevent workqueue leakage.
--- drivers/md/dm-raid1.c | 28 +++++++++++++++------------- 1 files changed, 15 insertions(+), 13 deletions(-)
drivers/md/dm-raid1.c +15 -13
@@ -974,6 +974,7 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,if (rh_init (&ms->rh, ms, dl, region_size, ms->nr_regions)) { ti->error ="Error creating dirty region hash" ; +dm_io_client_destroy (ms->io_client);kfree (ms);return NULL ; }
@@ -1163,16 +1164,14 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) ms->kmirrord_wq =create_singlethread_workqueue ("kmirrord" );if (!ms->kmirrord_wq) {DMERR ("couldn't start kmirrord" ); -free_context (ms, ti, m); -return -ENOMEM ; + r = -ENOMEM ; + goto out_free_context; }INIT_WORK (&ms->kmirrord_work, do_mirror); r =parse_features (ms, argc, argv, &args_used); -if (r) { -free_context (ms, ti, ms->nr_mirrors); -return r; - } +if (r) + goto out_destroy_wq; argv += args_used; argc -= args_used;
@@ -1188,19 +1187,22 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)if (argc) { ti->error ="Too many mirror arguments" ; -free_context (ms, ti, ms->nr_mirrors); -return -EINVAL ; + r = -EINVAL ; + goto out_destroy_wq; } r =kcopyd_client_create (DM_IO_PAGES , &ms->kcopyd_client); -if (r) { -destroy_workqueue (ms->kmirrord_wq); -free_context (ms, ti, ms->nr_mirrors); -return r; - } +if (r) + goto out_destroy_wq;wake (ms);return 0 ; + +out_destroy_wq: +destroy_workqueue (ms->kmirrord_wq); +out_free_context: +free_context (ms, ti, ms->nr_mirrors); +return r; }static void mirror_dtr (struct dm_target *ti)
Signature · 1 line
1.5.2.2
PATCH 4/8 dm:dm-hw-handler.c Convert kmalloc + memset to kzalloc
In reply to Dmitry Monakhov--- drivers/md/dm-hw-handler.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-hw-handler.c +2 -4
@@ -91,12 +91,10 @@ void dm_put_hw_handler(struct hw_handler_type *hwht)static struct hwh_internal *_alloc_hw_handler (struct hw_handler_type *hwht) { -struct hwh_internal *hwhi =kmalloc (sizeof (*hwhi),GFP_KERNEL ); +struct hwh_internal *hwhi =kzalloc (sizeof (*hwhi),GFP_KERNEL ); -if (hwhi) { -memset (hwhi,0 ,sizeof (*hwhi)); +if (hwhi) hwhi->hwht = *hwht; - }return hwhi; }
Signature · 1 line
1.5.2.2
PATCH 5/8 dm: dm-table.c Convert kmalloc + memset to kzalloc
In reply to Dmitry Monakhov--- drivers/md/dm-table.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/md/dm-table.c +1 -2
@@ -213,12 +213,11 @@ static int alloc_targets(struct dm_table *t, unsigned int num)int dm_table_create (struct dm_table **result,int mode,unsigned num_targets,struct mapped_device *md) { -struct dm_table *t =kmalloc (sizeof (*t),GFP_KERNEL ); +struct dm_table *t =kzalloc (sizeof (*t),GFP_KERNEL );if (!t)return -ENOMEM ; -memset (t,0 ,sizeof (*t));INIT_LIST_HEAD (&t->devices);atomic_set (&t->holders,1 );
Signature · 1 line
1.5.2.2
PATCH 6/8 dm: dm-emc.c Convert kmalloc + memset to kzalloc
In reply to Dmitry Monakhov--- drivers/md/dm-emc.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-emc.c +2 -4
@@ -224,12 +224,10 @@ fail_path:static struct emc_handler *alloc_emc_handler (void ) { -struct emc_handler *h =kmalloc (sizeof (*h),GFP_KERNEL ); +struct emc_handler *h =kzalloc (sizeof (*h),GFP_KERNEL ); -if (h) { -memset (h,0 ,sizeof (*h)); +if (h)spin_lock_init (&h->lock); - }return h; }
Signature · 1 line
1.5.2.2
PATCH 7/8 dm: dm-path-selector.c Convert kmalloc + memset to kzalloc
In reply to Dmitry Monakhov--- drivers/md/dm-path-selector.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-path-selector.c +2 -4
@@ -94,12 +94,10 @@ out:static struct ps_internal *_alloc_path_selector (struct path_selector_type *pst) { -struct ps_internal *psi =kmalloc (sizeof (*psi),GFP_KERNEL ); +struct ps_internal *psi =kzalloc (sizeof (*psi),GFP_KERNEL ); -if (psi) { -memset (psi,0 ,sizeof (*psi)); +if (psi) psi->pst = *pst; - }return psi; }
Signature · 1 line
1.5.2.2
PATCH 8/8 dm: dm-target.c Convert kmalloc + memset to kzalloc
In reply to Dmitry Monakhov--- drivers/md/dm-target.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-target.c +2 -4
@@ -88,12 +88,10 @@ void dm_put_target_type(struct target_type *t)static struct tt_internal *alloc_target (struct target_type *t) { -struct tt_internal *ti =kmalloc (sizeof (*ti),GFP_KERNEL ); +struct tt_internal *ti =kzalloc (sizeof (*ti),GFP_KERNEL ); -if (ti) { -memset (ti,0 ,sizeof (*ti)); +if (ti) ti->tt = *t; - }return ti; }
Signature · 1 line
1.5.2.2