zram: cut the trailing new-line in algorithm name
Subsystems (2)
PATCH 1/1 zram: cut the trailing new-line in algorithm name
supplied sysfs values sometimes contain new-line symbols, which we also copy as a compression algorithm name. this works fine, because we use sysfs_streq(), which takes care of new line symbols, when we lookup for compression algorithm. we print its name if zcomp_create() has failed, which unfortunately doesn't lok too good
zram: Cannot initialise LXZ
compressing backend
cut the trailing new-line symbol, so the reporting line will look like
zram: Cannot initialise LXZ compressing backend
we also now can replace sysfs_streq() in zcomp_available_show() with strcmp().
--- drivers/block/zram/zcomp.c | 2 +- drivers/block/zram/zram_drv.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/block/zram/zcomp.c +1 -1
@@ -274,7 +274,7 @@ ssize_t zcomp_available_show(const char *comp, char *buf)int i =0 ;while (backends[i]) { -if (sysfs_streq (comp, backends[i]->name)) +if (!strcmp (comp, backends[i]->name)) sz +=scnprintf (buf + sz,PAGE_SIZE - sz -2 ,"[%s] " , backends[i]->name);else
drivers/block/zram/zram_drv.c +12 -0
@@ -363,6 +363,13 @@ static ssize_t comp_algorithm_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); +size_t sz; + +if (len <=1 ) { +pr_err ("Invalid compression backend name\n" ); +return -EINVAL ; + } +down_write (&zram->init_lock);if (init_done (zram)) {up_write (&zram->init_lock);
@@ -371,6 +378,11 @@ static ssize_t comp_algorithm_store(struct device *dev, }strlcpy (zram->compressor, buf,sizeof (zram->compressor));up_write (&zram->init_lock); + +/* cut the trailing new-line */ + sz =strlen (zram->compressor) -1 ; +if (zram->compressor[sz] =='\n' ) + zram->compressor[sz] =0x00 ;return len; }
Signature · 1 line
2.4.1.168.g1ea28e1
On (05/22/15 18:34), Sergey Senozhatsky wrote:
[..]
drivers/block/zram/zram_drv.c static ssize_t comp_algorithm_store(struct device *dev, · line 385
Quoted 12 lines
drivers/block/zram/zram_drv.c +5
-0down_write (&zram->init_lock);if (init_done (zram)) {up_write (&zram->init_lock);@@ -371,6 +378,11 @@ static ssize_t comp_algorithm_store(struct device *dev, }strlcpy (zram->compressor, buf,sizeof (zram->compressor));up_write (&zram->init_lock); + +/* cut the trailing new-line */ + sz =strlen (zram->compressor) -1 ; +if (zram->compressor[sz] =='\n' ) + zram->compressor[sz] =0x00 ;
oh, how did it escape from the ->init_lock scope... will resend. sorry.
-ss