diff options
| author | tang.junhui <tang.junhui@zte.com.cn> | 2016-10-20 21:35:32 -0400 |
|---|---|---|
| committer | Mike Snitzer <snitzer@redhat.com> | 2016-10-24 11:17:46 -0400 |
| commit | dafa724bf582181d9a7d54f5cb4ca0bf8ef29269 (patch) | |
| tree | 952048cd64778adb6b20056b57912f19ca1eb6a1 /drivers/md | |
| parent | 937fa62e8a00d0b4bc2c0a40567d7c88ab2b2e8d (diff) | |
dm table: fix missing dm_put_target_type() in dm_table_add_target()
dm_get_target_type() was previously called so any error returned from
dm_table_add_target() must first call dm_put_target_type(). Otherwise
the DM target module's reference count will leak and the associated
kernel module will be unable to be removed.
Also, leverage the fact that r is already -EINVAL and remove an extra
newline.
Fixes: 36a0456 ("dm table: add immutable feature")
Fixes: cc6cbe1 ("dm table: add always writeable feature")
Fixes: 3791e2f ("dm table: add singleton feature")
Cc: stable@vger.kernel.org # 3.2+
Signed-off-by: tang.junhui <tang.junhui@zte.com.cn>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md')
| -rw-r--r-- | drivers/md/dm-table.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 3e407a9cde1f..c4b53b332607 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c | |||
| @@ -695,37 +695,32 @@ int dm_table_add_target(struct dm_table *t, const char *type, | |||
| 695 | 695 | ||
| 696 | tgt->type = dm_get_target_type(type); | 696 | tgt->type = dm_get_target_type(type); |
| 697 | if (!tgt->type) { | 697 | if (!tgt->type) { |
| 698 | DMERR("%s: %s: unknown target type", dm_device_name(t->md), | 698 | DMERR("%s: %s: unknown target type", dm_device_name(t->md), type); |
| 699 | type); | ||
| 700 | return -EINVAL; | 699 | return -EINVAL; |
| 701 | } | 700 | } |
| 702 | 701 | ||
| 703 | if (dm_target_needs_singleton(tgt->type)) { | 702 | if (dm_target_needs_singleton(tgt->type)) { |
| 704 | if (t->num_targets) { | 703 | if (t->num_targets) { |
| 705 | DMERR("%s: target type %s must appear alone in table", | 704 | tgt->error = "singleton target type must appear alone in table"; |
| 706 | dm_device_name(t->md), type); | 705 | goto bad; |
| 707 | return -EINVAL; | ||
| 708 | } | 706 | } |
| 709 | t->singleton = true; | 707 | t->singleton = true; |
| 710 | } | 708 | } |
| 711 | 709 | ||
| 712 | if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) { | 710 | if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) { |
| 713 | DMERR("%s: target type %s may not be included in read-only tables", | 711 | tgt->error = "target type may not be included in a read-only table"; |
| 714 | dm_device_name(t->md), type); | 712 | goto bad; |
| 715 | return -EINVAL; | ||
| 716 | } | 713 | } |
| 717 | 714 | ||
| 718 | if (t->immutable_target_type) { | 715 | if (t->immutable_target_type) { |
| 719 | if (t->immutable_target_type != tgt->type) { | 716 | if (t->immutable_target_type != tgt->type) { |
| 720 | DMERR("%s: immutable target type %s cannot be mixed with other target types", | 717 | tgt->error = "immutable target type cannot be mixed with other target types"; |
| 721 | dm_device_name(t->md), t->immutable_target_type->name); | 718 | goto bad; |
| 722 | return -EINVAL; | ||
| 723 | } | 719 | } |
| 724 | } else if (dm_target_is_immutable(tgt->type)) { | 720 | } else if (dm_target_is_immutable(tgt->type)) { |
| 725 | if (t->num_targets) { | 721 | if (t->num_targets) { |
| 726 | DMERR("%s: immutable target type %s cannot be mixed with other target types", | 722 | tgt->error = "immutable target type cannot be mixed with other target types"; |
| 727 | dm_device_name(t->md), tgt->type->name); | 723 | goto bad; |
| 728 | return -EINVAL; | ||
| 729 | } | 724 | } |
| 730 | t->immutable_target_type = tgt->type; | 725 | t->immutable_target_type = tgt->type; |
| 731 | } | 726 | } |
| @@ -740,7 +735,6 @@ int dm_table_add_target(struct dm_table *t, const char *type, | |||
| 740 | */ | 735 | */ |
| 741 | if (!adjoin(t, tgt)) { | 736 | if (!adjoin(t, tgt)) { |
| 742 | tgt->error = "Gap in table"; | 737 | tgt->error = "Gap in table"; |
| 743 | r = -EINVAL; | ||
| 744 | goto bad; | 738 | goto bad; |
| 745 | } | 739 | } |
| 746 | 740 | ||
