Skip to contentSkip to conversation

Fix bad return value checks (detected with Coccinelle)

PATCH In review Thomas Huth 3 participants 4 messages Aug 25, 2015 – Oct 24, 2015

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

PATCH 1/1 Fix bad return value checks (detected with Coccinelle)

In the "Getting Started with Coccinelle - KVM edition" presentation that has been held by Julia Lawall at the KVM forum 2015 (see the slides at
http://events.linuxfoundation.org/sites/events/files/slides/tutorial_kvm_0.pdf),
she pointed out some bad return value checks in U-Boot that can be detected with Coccinelle by using the following config file:

@@
identifier x,y;
identifier f;
statement S;
@@
x = f(...);
(
if (x < 0) S
|
if (
- y
+ x
< 0) S
)

This patch now fixes these issues.

---
Note: I haven't tested this patch at all, so please review carefully. I just wanted to let you know about these issues in case you haven't been aware of them yet. And in case if somebody else already reported them, please excuse the double information, I wasn't reading the u-boot mailing list so far yet.

board/samsung/origen/tools/mkorigenspl.c +1 -1
diff -u -p a/board/samsung/origen/tools/mkorigenspl.c b/board/samsung/origen/tools/mkorigenspl.c
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
 	}
 
 	ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
-	if (ifd < 0) {
+	if (ofd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			argv[0], argv[2], strerror(errno));
 		if (ifd)
board/samsung/smdkv310/tools/mksmdkv310spl.c +1 -1
diff -u -p a/board/samsung/smdkv310/tools/mksmdkv310spl.c b/board/samsung/smdkv310/tools/mksmdkv310spl.c
@@ -50,7 +50,7 @@ int main(int argc, char **argv)
 	}
 
 	ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
-	if (ifd < 0) {
+	if (ofd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			argv[0], argv[2], strerror(errno));
 		if (ifd)
drivers/hwmon/lm81.c +1 -1
diff -u -p a/drivers/hwmon/lm81.c b/drivers/hwmon/lm81.c
@@ -90,7 +90,7 @@ int dtt_init_one(int sensor)
 	if (adr < 0)
 		return 1;
 	rev = dtt_read (sensor, DTT_REV);
-	if (adr < 0)
+	if (rev < 0)
 		return 1;
 
 	debug ("DTT:   Found LM81@%x Rev: %d\n", adr, rev);
tools/fit_check_sign.c +1 -1
diff -u -p a/tools/fit_check_sign.c b/tools/fit_check_sign.c
@@ -75,7 +75,7 @@ int main(int argc, char **argv)
 	if (ffd < 0)
 		return EXIT_FAILURE;
 	kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf, false);
-	if (ffd < 0)
+	if (kfd < 0)
 		return EXIT_FAILURE;
 
 	image_set_host_blob(key_blob);
tools/mkexynosspl.c +1 -1
diff -u -p a/tools/mkexynosspl.c b/tools/mkexynosspl.c
@@ -110,7 +110,7 @@ int main(int argc, char **argv)
 	}
 
 	ofd = open(argv[of_index], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
-	if (ifd < 0) {
+	if (ofd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			prog_name, argv[of_index], strerror(errno));
 		exit(EXIT_FAILURE);
#1 lore raw

PATCH 1/1 Fix bad return value checks (detected with Coccinelle)

Am Tue, 25 Aug 2015 17:09:40 +0200
schrieb Thomas Huth <[email protected]>:

Quoted 93 lines

In the "Getting Started with Coccinelle - KVM edition" presentation that has been held by Julia Lawall at the KVM forum 2015 (see the slides at
http://events.linuxfoundation.org/sites/events/files/slides/tutorial_kvm_0.pdf),
she pointed out some bad return value checks in U-Boot that can be detected with Coccinelle by using the following config file:

@@
identifier x,y;
identifier f;
statement S;
@@
x = f(...);
(
if (x < 0) S
|
if (

(quoted diff) +1 -1
-     y
+     x
 < 0) S

)

This patch now fixes these issues.

---
Note: I haven't tested this patch at all, so please review carefully. I just wanted to let you know about these issues in case you haven't been aware of them yet. And in case if somebody else already reported them, please excuse the double information, I wasn't reading the u-boot mailing list so far yet.

diff -u -p a/board/samsung/origen/tools/mkorigenspl.c b/board/samsung/origen/tools/mkorigenspl.c --- a/board/samsung/origen/tools/mkorigenspl.c +++ b/board/samsung/origen/tools/mkorigenspl.c @@ -52,7 +52,7 @@ int main(int argc, char **argv) }

board/samsung/origen/tools/mkorigenspl.c +1 -1
 	ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
-	if (ifd < 0) {
+	if (ofd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			argv[0], argv[2], strerror(errno));
 		if (ifd)

diff -u -p a/board/samsung/smdkv310/tools/mksmdkv310spl.c b/board/samsung/smdkv310/tools/mksmdkv310spl.c --- a/board/samsung/smdkv310/tools/mksmdkv310spl.c +++ b/board/samsung/smdkv310/tools/mksmdkv310spl.c @@ -50,7 +50,7 @@ int main(int argc, char **argv) }

board/samsung/origen/tools/mkorigenspl.c +1 -1
 	ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
-	if (ifd < 0) {
+	if (ofd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			argv[0], argv[2], strerror(errno));
 		if (ifd)

diff -u -p a/drivers/hwmon/lm81.c b/drivers/hwmon/lm81.c

drivers/hwmon/lm81.c +1 -1
@@ -90,7 +90,7 @@ int dtt_init_one(int sensor)
 	if (adr < 0)
 		return 1;
 	rev = dtt_read (sensor, DTT_REV);
-	if (adr < 0)
+	if (rev < 0)
 		return 1;
 
 	debug ("DTT:   Found LM81@%x Rev: %d\n", adr, rev);

diff -u -p a/tools/fit_check_sign.c b/tools/fit_check_sign.c

tools/fit_check_sign.c +1 -1
@@ -75,7 +75,7 @@ int main(int argc, char **argv)
 	if (ffd < 0)
 		return EXIT_FAILURE;
 	kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf,
 false);
-	if (ffd < 0)
+	if (kfd < 0)
 		return EXIT_FAILURE;
 

image_set_host_blob(key_blob);
diff -u -p a/tools/mkexynosspl.c b/tools/mkexynosspl.c

tools/mkexynosspl.c +1 -1
@@ -110,7 +110,7 @@ int main(int argc, char **argv)
 	}
 
 	ofd = open(argv[of_index], O_WRONLY | O_CREAT | O_TRUNC,
 FILE_PERM);
-	if (ifd < 0) {
+	if (ofd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			prog_name, argv[of_index], strerror(errno));
Quoted 1 line

exit(EXIT_FAILURE);

ping ... now with maintainers on CC: :-)

Regards,
Thomas

#2 lore raw

PATCH 1/1 Fix bad return value checks (detected with Coccinelle)

In reply to Thomas Huth
Quoted 9 lines · Thomas Huth

This patch now fixes these issues.

---
Note: I haven't tested this patch at all, so please review carefully. I just wanted to let you know about these issues in case you haven't been aware of them yet. And in case if somebody else already reported them, please excuse the double information, I wasn't reading the u-boot mailing list so far yet.

You should split these changes into multiple patches.

Regards,

Fabio Estevam

#3 lore raw
In reply to Thomas Huth
Quoted 21 lines · Thomas Huth

In the "Getting Started with Coccinelle - KVM edition" presentation that has been held by Julia Lawall at the KVM forum 2015 (see the slides at
http://events.linuxfoundation.org/sites/events/files/slides/tutorial_kvm_0.pdf),
she pointed out some bad return value checks in U-Boot that can be detected with Coccinelle by using the following config file:

@@
identifier x,y;
identifier f;
statement S;
@@
x = f(...);
(
if (x < 0) S
|
if (

(quoted diff) +1 -1
-     y
+     x
 < 0) S

)

Quoted 3 lines

This patch now fixes these issues.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151024/410a70ca/attachment.sig>