[PATCH 1/5] blk-throttle: Move three assignments for the variable "ret" in tg_set_max()

From: SF Markus Elfring
Date: Sun Jan 22 2017 - 03:31:46 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 21 Jan 2017 21:23:06 +0100

A local variable was set to an error code before a concrete error situation
was detected. Thus move the corresponding assignments into if branches
to indicate a software failure there.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
block/blk-throttle.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 6f4c96e5f86b..51d112deb02e 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1327,27 +1327,30 @@ static ssize_t tg_set_max(struct kernfs_open_file *of,
break;
ctx.body += len;

- ret = -EINVAL;
p = tok;
strsep(&p, "=");
- if (!p || (sscanf(p, "%llu", &val) != 1 && strcmp(p, "max")))
+ if (!p || (sscanf(p, "%llu", &val) != 1 && strcmp(p, "max"))) {
+ ret = -EINVAL;
goto out_finish;
+ }

- ret = -ERANGE;
- if (!val)
+ if (!val) {
+ ret = -ERANGE;
goto out_finish;
+ }

- ret = -EINVAL;
- if (!strcmp(tok, "rbps"))
+ if (!strcmp(tok, "rbps")) {
v[0] = val;
- else if (!strcmp(tok, "wbps"))
+ } else if (!strcmp(tok, "wbps")) {
v[1] = val;
- else if (!strcmp(tok, "riops"))
+ } else if (!strcmp(tok, "riops")) {
v[2] = min_t(u64, val, UINT_MAX);
- else if (!strcmp(tok, "wiops"))
+ } else if (!strcmp(tok, "wiops")) {
v[3] = min_t(u64, val, UINT_MAX);
- else
+ } else {
+ ret = -EINVAL;
goto out_finish;
+ }
}

tg->bps[READ] = v[0];
--
2.11.0