[PATCH] zram: free secondary algorithms names

Sergey Senozhatsky posted 1 patch 2 months, 2 weeks ago
There is a newer version of this series
drivers/block/zram/zram_drv.c | 7 +++++++
1 file changed, 7 insertions(+)
[PATCH] zram: free secondary algorithms names
Posted by Sergey Senozhatsky 2 months, 2 weeks ago
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
Re: [PATCH] zram: free secondary algorithms names
Posted by Andrew Morton 2 months, 2 weeks ago
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);
>  }
Re: [PATCH] zram: free secondary algorithms names
Posted by Sergey Senozhatsky 2 months, 2 weeks ago
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.
[PATCHv2] zram: free secondary algorithms names
Posted by Sergey Senozhatsky 2 months, 2 weeks ago
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