Skip to contentSkip to conversation

mmc: vub300: Use common code in __download_offload_pseudocode()

PATCH Applied SF Markus Elfring 3 participants 8 messages Oct 27, 2017 – Oct 31, 2017

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

PATCH 1/1 mmc: vub300: Use common code in __download_offload_pseudocode()

From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 21:21:40 +0200

Add a jump target so that a specific string copy operation is stored only once at the end of this function implementation. Replace two calls of the function "strncpy" by goto statements.

This issue was detected by using the Coccinelle software.

---
 drivers/mmc/host/vub300.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/mmc/host/vub300.c +10 -12
index c1a169843f99..c898a45a84c5 100644
@@ -1244,12 +1244,8 @@ static void __download_offload_pseudocode(struct vub300_mmc_host *vub300,
 						USB_RECIP_DEVICE, 0x0000, 0x0000,
 						xfer_buffer, xfer_length, HZ);
 			kfree(xfer_buffer);
-			if (retval < 0) {
-				strncpy(vub300->vub_name,
-					"SDIO pseudocode download failed",
-					sizeof(vub300->vub_name));
-				return;
-			}
+			if (retval < 0)
+				goto copy_error_message;
 		} else {
 			dev_err(&vub300->udev->dev,
 				"not enough memory for xfer buffer to send"
@@ -1291,12 +1287,8 @@ static void __download_offload_pseudocode(struct vub300_mmc_host *vub300,
 						USB_RECIP_DEVICE, 0x0000, 0x0000,
 						xfer_buffer, xfer_length, HZ);
 			kfree(xfer_buffer);
-			if (retval < 0) {
-				strncpy(vub300->vub_name,
-					"SDIO pseudocode download failed",
-					sizeof(vub300->vub_name));
-				return;
-			}
+			if (retval < 0)
+				goto copy_error_message;
 		} else {
 			dev_err(&vub300->udev->dev,
 				"not enough memory for xfer buffer to send"
@@ -1349,6 +1341,12 @@ static void __download_offload_pseudocode(struct vub300_mmc_host *vub300,
 			sizeof(vub300->vub_name));
 		return;
 	}
+
+	return;
+
+copy_error_message:
+	strncpy(vub300->vub_name, "SDIO pseudocode download failed",
+		sizeof(vub300->vub_name));
 }
 
 /*
Signature · 1 line
2.14.3
Applied
#1 lore raw
Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 21:21:40 +0200

Add a jump target so that a specific string copy operation is stored only once at the end of this function implementation. Replace two calls of the function "strncpy" by goto statements.

This issue was detected by using the Coccinelle software.

Thanks, applied for next!

Kind regards
Uffe

Quoted 54 lines
---
 drivers/mmc/host/vub300.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/mmc/host/vub300.c +10 -13
index c1a169843f99..c898a45a84c5 100644
@@ -1244,12 +1244,8 @@ static void __download_offload_pseudocode(struct vub300_mmc_host *vub300,
                                                USB_RECIP_DEVICE, 0x0000, 0x0000,
                                                xfer_buffer, xfer_length, HZ);
                        kfree(xfer_buffer);
-                       if (retval < 0) {
-                               strncpy(vub300->vub_name,
-                                       "SDIO pseudocode download failed",
-                                       sizeof(vub300->vub_name));
-                               return;
-                       }
+                       if (retval < 0)
+                               goto copy_error_message;
                } else {
                        dev_err(&vub300->udev->dev,
                                "not enough memory for xfer buffer to send"
@@ -1291,12 +1287,8 @@ static void __download_offload_pseudocode(struct vub300_mmc_host *vub300,
                                                USB_RECIP_DEVICE, 0x0000, 0x0000,
                                                xfer_buffer, xfer_length, HZ);
                        kfree(xfer_buffer);
-                       if (retval < 0) {
-                               strncpy(vub300->vub_name,
-                                       "SDIO pseudocode download failed",
-                                       sizeof(vub300->vub_name));
-                               return;
-                       }
+                       if (retval < 0)
+                               goto copy_error_message;
                } else {
                        dev_err(&vub300->udev->dev,
                                "not enough memory for xfer buffer to send"
@@ -1349,6 +1341,12 @@ static void __download_offload_pseudocode(struct vub300_mmc_host *vub300,
                        sizeof(vub300->vub_name));
                return;
        }
+
+       return;
+
+copy_error_message:
+       strncpy(vub300->vub_name, "SDIO pseudocode download failed",
+               sizeof(vub300->vub_name));
 }
 
 /*
--

2.14.3

#2 lore raw
Quoted 9 lines · Ulf Hansson
Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 21:21:40 +0200

Add a jump target so that a specific string copy operation is stored only once at the end of this function implementation. Replace two calls of the function "strncpy" by goto statements.

Quoted 6 lines
Quoted 3 lines

This issue was detected by using the Coccinelle software.

Thanks, applied for next!

What's the advantage of this patch? The new code seems more complicated to me and GCC automatically reuses duplicate constant strings so there is no memory savings.

regards,
dan capenter

#3 lore raw
Quoted 12 lines · Dan Carpenter
Quoted 11 lines · Ulf Hansson
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 21:21:40 +0200

Add a jump target so that a specific string copy operation is stored only once at the end of this function implementation. Replace two calls of the function "strncpy" by goto statements.

This issue was detected by using the Coccinelle software.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Thanks, applied for next!

What's the advantage of this patch? The new code seems more complicated to me and GCC automatically reuses duplicate constant strings so there is no memory savings.

It looked to me that the error path got a bit cleaner. However, I guess it's matter of taste.

If you insist, I can drop it.

Kind regards
Uffe

#4 lore raw
Quoted 18 lines · Ulf Hansson
Quoted 17 lines · Dan Carpenter
Quoted 15 lines · Ulf Hansson
Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 21:21:40 +0200

Add a jump target so that a specific string copy operation is stored only once at the end of this function implementation. Replace two calls of the function "strncpy" by goto statements.

This issue was detected by using the Coccinelle software.

Thanks, applied for next!

Quoted 8 lines
Quoted 3 lines

What's the advantage of this patch? The new code seems more complicated to me and GCC automatically reuses duplicate constant strings so there is no memory savings.

It looked to me that the error path got a bit cleaner. However, I guess it's matter of taste.

If you insist, I can drop it.

I'm on the kernel-janitors list so I am CC'd on all of Markus's patches. It's not my code and I'm tired of being the anti-Markus guy so this patch is fine. Markus has a tool that finds duplicate strings and he uses gotos to avoid them. I don't think duplicate strings are a problem or that it's a good idea to send over a hundred patches using this method. But many people have explained that to Markus already and that's not the bigger picture which is about error handling and labels.

What I like are labels that are necessary and self explanatory. Things like "goto unlock" are a good example, because we know we need to unlock and the goto tells us what the label does. Or here is another example:

	foo = alloc_foo();
	if (!foo)
		return -ENOMEM;

	bar = alloc_bar();
	if (!foo) {
		err = -ENOMEM;
		goto free_foo;
	}

From reading the code, you know that you have to free foo and the label name is clear so you literally don't need to scroll down to the bottom of the function when you're reading this code. A bad label is like this:

	foo = alloc_foo();
	if (!foo)
		goto err;

You're reading along and you're like "what happens at the err" label? So then you have to scroll down to the bottom and read the code, then you have to think about how the variables line up with the variables in the above code, then you have to scroll back and find your place again and by that point you've forgotten what you were doing when you started.

regards,
dan carpenter

#5 lore raw
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

What's the advantage of this patch? The new code seems more complicated to me and GCC automatically reuses duplicate constant strings so there is no memory savings.

It looked to me that the error path got a bit cleaner. However, I guess it's matter of taste.

If you insist, I can drop it.

I'm on the kernel-janitors list so I am CC'd on all of Markus's patches.

Do you want that I omit this address from the list of recipients?

Quoted 1 line

It's not my code and I'm tired of being the anti-Markus guy

Interesting …

But I got the impression that this special relationship resulted also in a few useful side effects.

Quoted 1 line

so this patch is fine.

Thanks for another bit of acceptance.

Quoted 2 lines

Markus has a tool that finds duplicate strings and he uses gotos to avoid them.

Yes. - The script which I am using for the semantic patch language (Coccinelle software) can not only find this implementation detail but also duplicate source code generally to some degree.

Quoted 1 line

I don't think duplicate strings are a problem

They can become an issue for further considerations if inappropriate error messages were used for example.

There are more statement combinations which can be improved a bit more.

Quoted 1 line

or that it's a good idea to send over a hundred patches using this method.

The change acceptance is varying as usual.

Quoted 1 line

But many people have explained that to Markus already

I hope that my contributions can improve the affected software in some areas.

Quoted 2 lines

and that's not the bigger picture which is about error handling and labels. What I like are labels that are necessary and self explanatory.

It seems that this is a topic where you got strong opinions about.

Quoted 1 line

You're reading along and you're like "what happens at the err" label?

Would you accept any further adjustments around questionable jump targets?

Regards,
Markus
--
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

#6 lore raw
In reply to Dan Carpenter
Quoted 59 lines · Dan Carpenter
Quoted 18 lines · Ulf Hansson
Quoted 17 lines · Dan Carpenter
Quoted 15 lines · Ulf Hansson
Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 21:21:40 +0200

Add a jump target so that a specific string copy operation is stored only once at the end of this function implementation. Replace two calls of the function "strncpy" by goto statements.

This issue was detected by using the Coccinelle software.

Thanks, applied for next!

Quoted 8 lines
Quoted 3 lines

What's the advantage of this patch? The new code seems more complicated to me and GCC automatically reuses duplicate constant strings so there is no memory savings.

It looked to me that the error path got a bit cleaner. However, I guess it's matter of taste.

If you insist, I can drop it.

I'm on the kernel-janitors list so I am CC'd on all of Markus's patches. It's not my code and I'm tired of being the anti-Markus guy so this patch is fine. Markus has a tool that finds duplicate strings and he uses gotos to avoid them. I don't think duplicate strings are a problem or that it's a good idea to send over a hundred patches using this method. But many people have explained that to Markus already and that's not the bigger picture which is about error handling and labels.

What I like are labels that are necessary and self explanatory. Things like "goto unlock" are a good example, because we know we need to unlock and the goto tells us what the label does. Or here is another example:

        foo = alloc_foo();
        if (!foo)
                return -ENOMEM;

        bar = alloc_bar();
        if (!foo) {
                err = -ENOMEM;
                goto free_foo;
        }

From reading the code, you know that you have to free foo and the label name is clear so you literally don't need to scroll down to the bottom of the function when you're reading this code. A bad label is like this:

        foo = alloc_foo();
        if (!foo)
                goto err;
Quoted 6 lines

You're reading along and you're like "what happens at the err" label? So then you have to scroll down to the bottom and read the code, then you have to think about how the variables line up with the variables in the above code, then you have to scroll back and find your place again and by that point you've forgotten what you were doing when you started.

Thanks for the details! Much appreciated!

Regarding posts from Markus' I am well aware of the problems.

In my case, it hasn't been much of a hurdle, I simply ignore changes that seems silly to me.

Kind regards
Uffe

#7 lore raw
Quoted 1 line

Regarding posts from Markus' I am well aware of the problems.

Interesting …

Quoted 2 lines

In my case, it hasn't been much of a hurdle, I simply ignore changes that seems silly to me.

* How often did this happen so far?

* Are any update suggestions left over where a constructive feedback will make sense?

Regards,
Markus
--
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