Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1220383
| From | Luis Henriques <luis.henriques@canonical.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] zram: don't copy invalid compression algorithms |
| Date | 2015-09-07 22:50 +0200 |
| Message-ID | <q6bwt-863-9@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
Validate the new compression algorithm before copying it into the zram
'compressor' field, keeping the old one if it's invalid.
The error path code is also slightly refactored.
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
drivers/block/zram/zram_drv.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 9c01f5bfa33f..33551ec9e7f5 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -367,10 +367,15 @@ static ssize_t comp_algorithm_store(struct device *dev,
down_write(&zram->init_lock);
if (init_done(zram)) {
- up_write(&zram->init_lock);
pr_info("Can't change algorithm for initialized device\n");
- return -EBUSY;
+ len = -EBUSY;
+ goto out;
+ }
+ if (!zcomp_available_algorithm(buf)) {
+ len = -EINVAL;
+ goto out;
}
+
strlcpy(zram->compressor, buf, sizeof(zram->compressor));
/* ignore trailing newline */
@@ -378,9 +383,7 @@ 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;
-
+out:
up_write(&zram->init_lock);
return len;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] zram: don't copy invalid compression algorithms Luis Henriques <luis.henriques@canonical.com> - 2015-09-07 22:50 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-09-08 02:00 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Minchan Kim <minchan@kernel.org> - 2015-09-08 03:20 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-09-08 03:40 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-09-08 04:00 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Minchan Kim <minchan@kernel.org> - 2015-09-08 07:00 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-09-08 07:10 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Minchan Kim <minchan@kernel.org> - 2015-09-08 10:20 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-09-08 12:00 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Minchan Kim <minchan@kernel.org> - 2015-09-08 15:40 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2015-09-08 15:50 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Minchan Kim <minchan@kernel.org> - 2015-09-08 16:30 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2015-09-08 17:40 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Luis Henriques <luis.henriques@canonical.com> - 2015-09-08 12:10 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2015-09-08 14:30 +0200
Re: [PATCH] zram: don't copy invalid compression algorithms Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-09-08 07:20 +0200
csiph-web