Skip to contentSkip to conversation

block: Fine-tuning for five function implementations

PATCH In review SF Markus Elfring 3 participants 15 messages Jan 22, 2017 – Jan 23, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover block: Fine-tuning for five function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 23:00:00 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
Move three assignments for the variable "ret" in tg_set_max() Move an assignment for the variable "ret" in tg_set_conf() Adjust two function calls together with a variable assignment Move an assignment for the variable "ret" in __cfqg_set_weight_device() Adjust one function call together with a variable assignment

 block/blk-throttle.c | 34 ++++++++++++++++++++--------------
 block/cfq-iosched.c  | 11 +++++++----
 2 files changed, 27 insertions(+), 18 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

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

From: Markus Elfring <[email protected]>
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.

---
 block/blk-throttle.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
block/blk-throttle.c +13 -10
index 6f4c96e5f86b..51d112deb02e 100644
@@ -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];
Signature · 1 line
2.11.0
#7 lore raw

PATCH 2/5 blk-throttle: Move an assignment for the variable "ret" in tg_set_conf()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 21:40:38 +0100

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

This issue was detected by using the Coccinelle software.

---
 block/blk-throttle.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
block/blk-throttle.c +3 -2
index 51d112deb02e..b392b48310ba 100644
@@ -1191,9 +1191,10 @@ static ssize_t tg_set_conf(struct kernfs_open_file *of,
 	if (ret)
 		return ret;
 
-	ret = -EINVAL;
-	if (sscanf(ctx.body, "%llu", &v) != 1)
+	if (sscanf(ctx.body, "%llu", &v) != 1) {
+		ret = -EINVAL;
 		goto out_finish;
+	}
 	if (!v)
 		v = -1;
 
Signature · 1 line
2.11.0
#9 lore raw

PATCH 3/5 blk-throttle: Adjust two function calls together with a variable assignment

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 22:15:33 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

---
 block/blk-throttle.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-throttle.c +4 -2
index b392b48310ba..3cf7472fbba2 100644
@@ -866,10 +866,12 @@ static void tg_update_disptime(struct throtl_grp *tg)
 	unsigned long read_wait = -1, write_wait = -1, min_wait = -1, disptime;
 	struct bio *bio;
 
-	if ((bio = throtl_peek_queued(&sq->queued[READ])))
+	bio = throtl_peek_queued(&sq->queued[READ]);
+	if (bio)
 		tg_may_dispatch(tg, bio, &read_wait);
 
-	if ((bio = throtl_peek_queued(&sq->queued[WRITE])))
+	bio = throtl_peek_queued(&sq->queued[WRITE]);
+	if (bio)
 		tg_may_dispatch(tg, bio, &write_wait);
 
 	min_wait = min(read_wait, write_wait);
Signature · 1 line
2.11.0
#12 lore raw

PATCH 4/5 cfq-iosched: Move an assignment for the variable "ret" in __cfqg_set_weight_device()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 22:26:38 +0100

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

This issue was detected by using the Coccinelle software.

---
 block/cfq-iosched.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
block/cfq-iosched.c +3 -2
index c73a6fcaeb9d..454297fe8fd6 100644
@@ -1788,9 +1788,10 @@ static ssize_t __cfqg_set_weight_device(struct kernfs_open_file *of,
 
 	if (sscanf(ctx.body, "%llu", &v) = 1) {
 		/* require "default" on dfl */
-		ret = -ERANGE;
-		if (!v && on_dfl)
+		if (!v && on_dfl) {
+			ret = -ERANGE;
 			goto out_finish;
+		}
 	} else if (!strcmp(strim(ctx.body), "default")) {
 		v = 0;
 	} else {
Signature · 1 line
2.11.0
#13 lore raw

PATCH 5/5 cfq-iosched: Adjust one function call together with a variable assignment

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 22:44:07 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code place.

---
 block/cfq-iosched.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/cfq-iosched.c +4 -2
index 454297fe8fd6..8c405eaa2806 100644
@@ -2750,9 +2750,11 @@ static struct cfq_queue *cfq_get_next_queue_forced(struct cfq_data *cfqd)
 	if (!cfqg)
 		return NULL;
 
-	for_each_cfqg_st(cfqg, i, j, st)
-		if ((cfqq = cfq_rb_first(st)) != NULL)
+	for_each_cfqg_st(cfqg, i, j, st) {
+		cfqq = cfq_rb_first(st);
+		if (cfqq)
 			return cfqq;
+	}
 	return NULL;
 }
 
Signature · 1 line
2.11.0
#2 lore raw

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

In reply to SF Markus Elfring
Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 block/blk-throttle.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
block/blk-throttle.c +0 -0
index 6f4c96e5f86b..51d112deb02e 100644
@@ -1327,27 +1327,30 @@ static ssize_t tg_set_max(struct kernfs_open_file *of,
 			break;

block/blk-throttle.c static ssize_t tg_set_max(struct kernfs_open_file *of, · line 1335

Quoted 10 lines
block/blk-throttle.c +3 -2
 		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;
+		}

Sorry, I don't like this patch. We know the next error if we encounter one will be EINVAL until we change it. Your patch doesn't introduce a functual change and doesn't improve readability, so I don't really see a point for it.

Byte,
Johannes

Signature · 10 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

Re: [PATCH 2/5] blk-throttle: Move an assignment for the variable "ret" in tg_set_conf()

In reply to SF Markus Elfring
Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 21:40:38 +0100

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

This issue was detected by using the Coccinelle software.

---

See my answer to the last patch.

Signature · 10 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v1 3/5
#10 lore raw

Re: [PATCH 3/5] blk-throttle: Adjust two function calls together with a variable assignment

In reply to SF Markus Elfring
Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 22:15:33 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

---

if Jens wants doesn't mind.

Signature · 10 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v1 5/5
#14 lore raw

Re: [PATCH 5/5] cfq-iosched: Adjust one function call together with a variable assignment

In reply to SF Markus Elfring
Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 22:44:07 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code place.

---

Signature · 10 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

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

In reply to Johannes Thumshirn
Quoted 4 lines
Quoted 4 lines
block/blk-throttle.c +0 -0
@@ -1327,27 +1327,30 @@ static ssize_t tg_set_max(struct kernfs_open_file *of,
 			break;
 		ctx.body += len;
 
Quoted 11 lines

block/blk-throttle.c static ssize_t tg_set_max(struct kernfs_open_file *of, · line 1335

Quoted 8 lines
block/blk-throttle.c +3 -2
-		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;
+		}

Sorry, I don't like this patch. We know the next error if we encounter one will be EINVAL until we change it.

Thanks for your constructive feedback.

Quoted 2 lines

Your patch doesn't introduce a functual change and doesn't improve readability, so I don't really see a point for it.

We have got different preferences for the placement of error code settings. Do you care about run time changes there?

Regards,
Markus

#4 lore raw

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

Quoted 16 lines · SF Markus Elfring
Quoted 4 lines
Quoted 4 lines
block/blk-throttle.c +0 -0
@@ -1327,27 +1327,30 @@ static ssize_t tg_set_max(struct kernfs_open_file *of,
 			break;
 		ctx.body += len;
 
Quoted 11 lines

block/blk-throttle.c static ssize_t tg_set_max(struct kernfs_open_file *of, · line 1335

Quoted 8 lines
block/blk-throttle.c +3 -2
-		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;
+		}

Sorry, I don't like this patch. We know the next error if we encounter one will be EINVAL until we change it.

Quoted 7 lines

Thanks for your constructive feedback.

Quoted 2 lines

Your patch doesn't introduce a functual change and doesn't improve readability, so I don't really see a point for it.

We have got different preferences for the placement of error code settings.

Yes we do, so what's the point? Both are OK. Please don't go down that road it opens so much potential for needless bikeshedding and waste all of our (including your) time.

Thanks,
Johannes

Signature · 10 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

Re: blk-throttle: Move three assignments for the variable "ret" in tg_set_max()

Quoted 2 lines
Quoted 1 line

We have got different preferences for the placement of error code settings.

Yes we do, so what's the point? Both are OK.

Can a function implementation be executed a bit faster in the case that error codes will usually only matter if they would be set after a concrete software failure

Quoted 2 lines

Please don't go down that road it opens so much potential for needless bikeshedding and waste all of our (including your) time.

I would appreciate to clarify involved run time consequences a bit more.

Regards,
Markus

maintainer
#11 lore raw

Re: [PATCH 3/5] blk-throttle: Adjust two function calls together with a variable assignment

In reply to Johannes Thumshirn
Quoted 8 lines · Johannes Thumshirn
Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Jan 2017 22:15:33 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Quoted 7 lines
Quoted 4 lines

Thus fix the affected source code places.

---

if Jens wants doesn't mind.

I don't mind these, but I completely agree on the patches for moving the 'error' assignment. What ends up happening for those cases is that someone adds a new section and forgets to set 'error', and then all hell breaks lose.

So Markus, don't bother sending those patches again for the block layer or drivers, I'm not going to take them.

Signature · 1 line
Jens Axboe
maintainer
#6 lore raw

Re: blk-throttle: Move three assignments for the variable "ret" in tg_set_max()

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring
Quoted 2 lines
Quoted 1 line

We have got different preferences for the placement of error code settings.

Yes we do, so what's the point? Both are OK.

Can a function implementation be executed a bit faster in the case that error codes will usually only matter if they would be set after a concrete software failure

Don't turn this into a troll fest. Maintainability trumps performance. Every time. See previous email for reasoning for that.

Quoted 4 lines
Quoted 2 lines

Please don't go down that road it opens so much potential for needless bikeshedding and waste all of our (including your) time.

I would appreciate to clarify involved run time consequences a bit more.

How about you go and benchmark the before and after, and present some compelling evidence based on those tests for why the change should be made? The onus is on the submitter here, not the reviewer.

As I said in the previous email, don't bother sending these types of patches for the block layer again. They are just going to be ignored.

Signature · 1 line
Jens Axboe