Browse Source

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>
tags/2020-06-01
Thomas Huth 5 years ago
committed by Tom Rini
parent
commit
310ae37edb
5 changed files with 5 additions and 5 deletions
  1. +1
    -1
      board/samsung/origen/tools/mkorigenspl.c
  2. +1
    -1
      board/samsung/smdkv310/tools/mksmdkv310spl.c
  3. +1
    -1
      drivers/hwmon/lm81.c
  4. +1
    -1
      tools/fit_check_sign.c
  5. +1
    -1
      tools/mkexynosspl.c

+ 1
- 1
board/samsung/origen/tools/mkorigenspl.c View 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)


+ 1
- 1
board/samsung/smdkv310/tools/mksmdkv310spl.c View 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)


+ 1
- 1
drivers/hwmon/lm81.c View 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);


+ 1
- 1
tools/fit_check_sign.c View 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);


+ 1
- 1
tools/mkexynosspl.c View 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);