Skip to contentSkip to conversation

zram: check comp algorithm availability earlier

PATCH In review Sergey Senozhatsky 2 participants 2 messages May 27, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 zram: check comp algorithm availability earlier

Improvement idea by Marcin Jabrzyk.

comp_algorithm_store() silently accepts any supplied algorithm name, because zram performs algorithm availability check later, during the device configuration phase in disksize_store() and emits the following error:
"zram: Cannot initialise %s compressing backend"

this error line is somewhat generic and, besides, can indicate a failed attempt to allocate compression backend's working buffers.

add algorithm availability check to comp_algorithm_store():

echo lzz > /sys/block/zram0/comp_algorithm
-bash: echo: write error: Invalid argument

---
 drivers/block/zram/zcomp.c    | 5 +++++
 drivers/block/zram/zcomp.h    | 1 +
 drivers/block/zram/zram_drv.c | 3 +++
 3 files changed, 9 insertions(+)
drivers/block/zram/zcomp.c +5 -0
index a1a8b8e..965d1af 100644
@@ -286,6 +286,11 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
 	return sz;
 }
 
+bool zcomp_available_algorithm(const char *comp)
+{
+	return find_backend(comp) != NULL;
+}
+
 bool zcomp_set_max_streams(struct zcomp *comp, int num_strm)
 {
 	return comp->set_max_streams(comp, num_strm);
drivers/block/zram/zcomp.h +1 -0
index c59d1fc..46e2b9f 100644
@@ -51,6 +51,7 @@ struct zcomp {
 };
 
 ssize_t zcomp_available_show(const char *comp, char *buf);
+bool zcomp_available_algorithm(const char *comp);
 
 struct zcomp *zcomp_create(const char *comp, int max_strm);
 void zcomp_destroy(struct zcomp *comp);
drivers/block/zram/zram_drv.c +3 -0
index 28f6e46..1cd8ade 100644
@@ -378,6 +378,9 @@ static ssize_t comp_algorithm_store(struct device *dev,
 	if (sz > 0 && zram->compressor[sz - 1] == '\n')
 		zram->compressor[sz - 1] = 0x00;
 
+	if (!zcomp_available_algorithm(zram->compressor))
+		len = -EINVAL;
+
 	up_write(&zram->init_lock);
 	return len;
 }
Signature · 1 line
2.4.1.314.g9532ead
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 12 lines · Sergey Senozhatsky

Improvement idea by Marcin Jabrzyk.

comp_algorithm_store() silently accepts any supplied algorithm name, because zram performs algorithm availability check later, during the device configuration phase in disksize_store() and emits the following error:
"zram: Cannot initialise %s compressing backend"

this error line is somewhat generic and, besides, can indicate a failed attempt to allocate compression backend's working buffers.

Quoted 7 lines

add algorithm availability check to comp_algorithm_store():

echo lzz > /sys/block/zram0/comp_algorithm
-bash: echo: write error: Invalid argument

Thanks.

Signature · 2 lines
Kind regards,
Minchan Kim