Skip to content

Commit 4645187

Browse files
Coly Liaxboe
authored andcommitted
bcache: fix error setting writeback_rate through sysfs interface
Commit ea8c535 ("bcache: set max writeback rate when I/O request is idle") changes struct bch_ratelimit member rate from uint32_t to atomic_long_t and uses atomic_long_set() in drivers/md/bcache/sysfs.c to set new writeback rate, after the input is converted from memory buf to long int by sysfs_strtoul_clamp(). The above change has a problem because there is an implicit return inside sysfs_strtoul_clamp() so the following atomic_long_set() won't be called. This error is detected by 0day system with following snipped smatch warnings: drivers/md/bcache/sysfs.c:271 __cached_dev_store() error: uninitialized symbol 'v'. 270 sysfs_strtoul_clamp(writeback_rate, v, 1, INT_MAX); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @271 atomic_long_set(&dc->writeback_rate.rate, v); This patch fixes the above error by using strtoul_safe_clamp() to convert the input buffer into a long int type result. Fixes: ea8c535 ("bcache: set max writeback rate when I/O request is idle") Cc: Kai Krakow <kai@kaishome.de> Cc: Stefan Priebe <s.priebe@profihost.ag> Signed-off-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 61884de commit 4645187

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/md/bcache/sysfs.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,17 @@ STORE(__cached_dev)
265265
sysfs_strtoul_clamp(writeback_percent, dc->writeback_percent, 0, 40);
266266

267267
if (attr == &sysfs_writeback_rate) {
268-
int v;
268+
ssize_t ret;
269+
long int v = atomic_long_read(&dc->writeback_rate.rate);
270+
271+
ret = strtoul_safe_clamp(buf, v, 1, INT_MAX);
269272

270-
sysfs_strtoul_clamp(writeback_rate, v, 1, INT_MAX);
271-
atomic_long_set(&dc->writeback_rate.rate, v);
273+
if (!ret) {
274+
atomic_long_set(&dc->writeback_rate.rate, v);
275+
ret = size;
276+
}
277+
278+
return ret;
272279
}
273280

274281
sysfs_strtoul_clamp(writeback_rate_update_seconds,

0 commit comments

Comments
 (0)