Commit 39709c84 authored by tang.junhui's avatar tang.junhui Committed by Sasha Levin

dm table: fix missing dm_put_target_type() in dm_table_add_target()

[ Upstream commit dafa724b ]

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: 36a0456f ("dm table: add immutable feature")
Fixes: cc6cbe14 ("dm table: add always writeable feature")
Fixes: 3791e2fc ("dm table: add singleton feature")
Cc: stable@vger.kernel.org # 3.2+
Signed-off-by: default avatartang.junhui <tang.junhui@zte.com.cn>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
parent c91812c8
...@@ -700,37 +700,32 @@ int dm_table_add_target(struct dm_table *t, const char *type, ...@@ -700,37 +700,32 @@ int dm_table_add_target(struct dm_table *t, const char *type,
tgt->type = dm_get_target_type(type); tgt->type = dm_get_target_type(type);
if (!tgt->type) { if (!tgt->type) {
DMERR("%s: %s: unknown target type", dm_device_name(t->md), DMERR("%s: %s: unknown target type", dm_device_name(t->md), type);
type);
return -EINVAL; return -EINVAL;
} }
if (dm_target_needs_singleton(tgt->type)) { if (dm_target_needs_singleton(tgt->type)) {
if (t->num_targets) { if (t->num_targets) {
DMERR("%s: target type %s must appear alone in table", tgt->error = "singleton target type must appear alone in table";
dm_device_name(t->md), type); goto bad;
return -EINVAL;
} }
t->singleton = 1; t->singleton = 1;
} }
if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) { if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) {
DMERR("%s: target type %s may not be included in read-only tables", tgt->error = "target type may not be included in a read-only table";
dm_device_name(t->md), type); goto bad;
return -EINVAL;
} }
if (t->immutable_target_type) { if (t->immutable_target_type) {
if (t->immutable_target_type != tgt->type) { if (t->immutable_target_type != tgt->type) {
DMERR("%s: immutable target type %s cannot be mixed with other target types", tgt->error = "immutable target type cannot be mixed with other target types";
dm_device_name(t->md), t->immutable_target_type->name); goto bad;
return -EINVAL;
} }
} else if (dm_target_is_immutable(tgt->type)) { } else if (dm_target_is_immutable(tgt->type)) {
if (t->num_targets) { if (t->num_targets) {
DMERR("%s: immutable target type %s cannot be mixed with other target types", tgt->error = "immutable target type cannot be mixed with other target types";
dm_device_name(t->md), tgt->type->name); goto bad;
return -EINVAL;
} }
t->immutable_target_type = tgt->type; t->immutable_target_type = tgt->type;
} }
...@@ -745,7 +740,6 @@ int dm_table_add_target(struct dm_table *t, const char *type, ...@@ -745,7 +740,6 @@ int dm_table_add_target(struct dm_table *t, const char *type,
*/ */
if (!adjoin(t, tgt)) { if (!adjoin(t, tgt)) {
tgt->error = "Gap in table"; tgt->error = "Gap in table";
r = -EINVAL;
goto bad; goto bad;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment