]> git.baikalelectronics.ru Git - kernel.git/commitdiff
dm era: Fix bitset memory leaks
authorNikos Tsironis <ntsironis@arrikto.com>
Fri, 22 Jan 2021 15:25:54 +0000 (17:25 +0200)
committerMike Snitzer <snitzer@redhat.com>
Wed, 10 Feb 2021 18:32:03 +0000 (13:32 -0500)
Deallocate the memory allocated for the in-core bitsets when destroying
the target and in error paths.

Fixes: b83b01ee643a86 ("dm: add era target")
Cc: stable@vger.kernel.org # v3.15+
Signed-off-by: Nikos Tsironis <ntsironis@arrikto.com>
Reviewed-by: Ming-Hung Tsai <mtsai@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-era-target.c

index da3d8ace23980cf57f16315130f840bdb1790f06..1abd280ff8dce0135ee7fc0a385f62877fb49b99 100644 (file)
@@ -47,6 +47,7 @@ struct writeset {
 static void writeset_free(struct writeset *ws)
 {
        vfree(ws->bits);
+       ws->bits = NULL;
 }
 
 static int setup_on_disk_bitset(struct dm_disk_bitset *info,
@@ -811,6 +812,8 @@ static struct era_metadata *metadata_open(struct block_device *bdev,
 
 static void metadata_close(struct era_metadata *md)
 {
+       writeset_free(&md->writesets[0]);
+       writeset_free(&md->writesets[1]);
        destroy_persistent_data_objects(md);
        kfree(md);
 }
@@ -848,6 +851,7 @@ static int metadata_resize(struct era_metadata *md, void *arg)
        r = writeset_alloc(&md->writesets[1], *new_size);
        if (r) {
                DMERR("%s: writeset_alloc failed for writeset 1", __func__);
+               writeset_free(&md->writesets[0]);
                return r;
        }
 
@@ -858,6 +862,8 @@ static int metadata_resize(struct era_metadata *md, void *arg)
                            &value, &md->era_array_root);
        if (r) {
                DMERR("%s: dm_array_resize failed", __func__);
+               writeset_free(&md->writesets[0]);
+               writeset_free(&md->writesets[1]);
                return r;
        }