dm cache metadata: Avoid returning cmd->bm wild pointer on error
authorYe Bin <yebin10@huawei.com>
Tue, 1 Sep 2020 06:25:42 +0000 (14:25 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 9 Sep 2020 17:03:12 +0000 (19:03 +0200)
commit d16ff19e69ab57e08bf908faaacbceaf660249de upstream.

Maybe __create_persistent_data_objects() caller will use PTR_ERR as a
pointer, it will lead to some strange things.

Signed-off-by: Ye Bin <yebin10@huawei.com>
Cc: stable@vger.kernel.org
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/dm-cache-metadata.c

index 394e53afc259391991e8dc3547da53db396fa998..0acd10d3b7bff8ab0477895469ab3aed88cf3929 100644 (file)
@@ -536,12 +536,16 @@ static int __create_persistent_data_objects(struct dm_cache_metadata *cmd,
                                          CACHE_MAX_CONCURRENT_LOCKS);
        if (IS_ERR(cmd->bm)) {
                DMERR("could not create block manager");
-               return PTR_ERR(cmd->bm);
+               r = PTR_ERR(cmd->bm);
+               cmd->bm = NULL;
+               return r;
        }
 
        r = __open_or_format_metadata(cmd, may_format_device);
-       if (r)
+       if (r) {
                dm_block_manager_destroy(cmd->bm);
+               cmd->bm = NULL;
+       }
 
        return r;
 }