drivers/block/zram/zram_drv.c | 7 +++++++ 1 file changed, 7 insertions(+)
We need to kfree() secondary algorithms names when reset
zram device that had multi-streams, otherwise we leak memory.
Fixes: 001d92735701 ("zram: add recompression algorithm sysfs knob")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
drivers/block/zram/zram_drv.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index f8206ba6cbbb..ee2a279c5f25 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2115,6 +2115,13 @@ static void zram_destroy_comps(struct zram *zram)
zram->num_active_comps--;
}
+ for (prio = ZRAM_SECONDARY_COMP; prio < ZRAM_MAX_COMPS; prio++) {
+ if (!zram->comp_algs[prio])
+ continue;
+ kfree(zram->comp_algs[prio]);
+ zram->comp_algs[prio] = NULL;
+ }
+
zram_comp_params_reset(zram);
}
--
2.46.0.598.g6f2099f65c-goog
On Wed, 11 Sep 2024 11:54:56 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote: > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -2115,6 +2115,13 @@ static void zram_destroy_comps(struct zram *zram) > zram->num_active_comps--; > } > > + for (prio = ZRAM_SECONDARY_COMP; prio < ZRAM_MAX_COMPS; prio++) { > + if (!zram->comp_algs[prio]) > + continue; We'll probably get emails telling us that this test-for-null is unneeded... > + kfree(zram->comp_algs[prio]); > + zram->comp_algs[prio] = NULL; > + } > + > zram_comp_params_reset(zram); > }
On (24/09/16 07:44), Andrew Morton wrote: > On Wed, 11 Sep 2024 11:54:56 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote: > > > --- a/drivers/block/zram/zram_drv.c > > +++ b/drivers/block/zram/zram_drv.c > > @@ -2115,6 +2115,13 @@ static void zram_destroy_comps(struct zram *zram) > > zram->num_active_comps--; > > } > > > > + for (prio = ZRAM_SECONDARY_COMP; prio < ZRAM_MAX_COMPS; prio++) { > > + if (!zram->comp_algs[prio]) > > + continue; > > We'll probably get emails telling us that this test-for-null is unneeded... Agreed, I also thought about this, let me do v2 quickly.
We need to kfree() secondary algorithms names when reset
zram device that had multi-streams, otherwise we leak memory.
Fixes: 001d92735701 ("zram: add recompression algorithm sysfs knob")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
drivers/block/zram/zram_drv.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index f8206ba6cbbb..c3d245617083 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2115,6 +2115,11 @@ static void zram_destroy_comps(struct zram *zram)
zram->num_active_comps--;
}
+ for (prio = ZRAM_SECONDARY_COMP; prio < ZRAM_MAX_COMPS; prio++) {
+ kfree(zram->comp_algs[prio]);
+ zram->comp_algs[prio] = NULL;
+ }
+
zram_comp_params_reset(zram);
}
--
2.46.0.662.g92d0881bb0-goog
© 2016 - 2024 Red Hat, Inc.