Commit 310ae37edb3becedf5da904201f3439ea42ab12f

Authored by Thomas Huth
Committed by Tom Rini
1 parent bff78567da

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.

Signed-off-by: Thomas Huth <huth@tuxfamily.org>

Showing 5 changed files with 5 additions and 5 deletions Side-by-side Diff

board/samsung/origen/tools/mkorigenspl.c
... ... @@ -52,7 +52,7 @@
52 52 }
53 53  
54 54 ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
55   - if (ifd < 0) {
  55 + if (ofd < 0) {
56 56 fprintf(stderr, "%s: Can't open %s: %s\n",
57 57 argv[0], argv[2], strerror(errno));
58 58 if (ifd)
board/samsung/smdkv310/tools/mksmdkv310spl.c
... ... @@ -50,7 +50,7 @@
50 50 }
51 51  
52 52 ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
53   - if (ifd < 0) {
  53 + if (ofd < 0) {
54 54 fprintf(stderr, "%s: Can't open %s: %s\n",
55 55 argv[0], argv[2], strerror(errno));
56 56 if (ifd)
drivers/hwmon/lm81.c
... ... @@ -90,7 +90,7 @@
90 90 if (adr < 0)
91 91 return 1;
92 92 rev = dtt_read (sensor, DTT_REV);
93   - if (adr < 0)
  93 + if (rev < 0)
94 94 return 1;
95 95  
96 96 debug ("DTT: Found LM81@%x Rev: %d\n", adr, rev);
tools/fit_check_sign.c
... ... @@ -75,7 +75,7 @@
75 75 if (ffd < 0)
76 76 return EXIT_FAILURE;
77 77 kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf, false);
78   - if (ffd < 0)
  78 + if (kfd < 0)
79 79 return EXIT_FAILURE;
80 80  
81 81 image_set_host_blob(key_blob);
... ... @@ -110,7 +110,7 @@
110 110 }
111 111  
112 112 ofd = open(argv[of_index], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
113   - if (ifd < 0) {
  113 + if (ofd < 0) {
114 114 fprintf(stderr, "%s: Can't open %s: %s\n",
115 115 prog_name, argv[of_index], strerror(errno));
116 116 exit(EXIT_FAILURE);