]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
Fix bad return value checks (detected with Coccinelle)
authorThomas Huth <huth@tuxfamily.org>
Tue, 25 Aug 2015 15:09:40 +0000 (17:09 +0200)
committerTom Rini <trini@konsulko.com>
Sat, 24 Oct 2015 17:50:30 +0000 (13:50 -0400)
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.

Signed-off-by: Thomas Huth <huth@tuxfamily.org>
board/samsung/origen/tools/mkorigenspl.c
board/samsung/smdkv310/tools/mksmdkv310spl.c
drivers/hwmon/lm81.c
tools/fit_check_sign.c
tools/mkexynosspl.c

index 3ed20efce35ef2218411ad8c79cd4ec48a259d3f..8b0c3ac4bd5232ba166f2e12b4769403f3c1deb8 100644 (file)
@@ -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)
index 9a64ca6ad6e26caf22ad84e048d33151520180c9..ea61635db5e234e32a2126df6787eb43cd3df32f 100644 (file)
@@ -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)
index c1fc42a83321d002f4c971844e956a447a88916b..bcc8d3293b5639b6b6e97c21d6653127835a1410 100644 (file)
@@ -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);
index 69e99c0d179e048231b8c6ef0429e47e54ec3cfe..d9361b00950c7a699c714d224adddcaec7a13dbe 100644 (file)
@@ -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);
index 32b786c724b205a5097fd2ece9291710b922926e..46195aad55ad0fd5e5c3dd56d77f2640063b6095 100644 (file)
@@ -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);