bcache: Correct return value for sysfs attach errors
authorTony Asleson <tasleson@redhat.com>
Wed, 6 Sep 2017 06:25:57 +0000 (14:25 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 6 Sep 2017 14:17:33 +0000 (08:17 -0600)
If you encounter any errors in bch_cached_dev_attach it will return
a negative error code.  The variable 'v' which stores the result is
unsigned, thus user space sees a very large value returned for bytes
written which can cause incorrect user space behavior.  Utilize 1
signed variable to use throughout the function to preserve error return
capability.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
Acked-by: Coly Li <colyli@suse.de>
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/sysfs.c

index 09295c07ea88c3e3b4253263817fc42efe6e221d..104c57cd666ce7873912ac48be51d32a14b37a01 100644 (file)
@@ -192,7 +192,7 @@ STORE(__cached_dev)
 {
        struct cached_dev *dc = container_of(kobj, struct cached_dev,
                                             disk.kobj);
-       unsigned v = size;
+       ssize_t v = size;
        struct cache_set *c;
        struct kobj_uevent_env *env;
 
@@ -227,7 +227,7 @@ STORE(__cached_dev)
                bch_cached_dev_run(dc);
 
        if (attr == &sysfs_cache_mode) {
-               ssize_t v = bch_read_string_list(buf, bch_cache_modes + 1);
+               v = bch_read_string_list(buf, bch_cache_modes + 1);
 
                if (v < 0)
                        return v;