]> git.baikalelectronics.ru Git - kernel.git/commitdiff
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)
committerMike Snitzer <snitzer@redhat.com>
Wed, 2 Sep 2020 17:38:24 +0000 (13:38 -0400)
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>
drivers/md/dm-cache-metadata.c

index 151aa95775be2daee11c7721eb62dde28ec702b1..af6d4f898e4c1de8d9b72f053beb454d5617a1e8 100644 (file)
@@ -537,12 +537,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;
 }