]> www.infradead.org Git - mtd-utils.git/commitdiff
libmtd: fix mtd_dev_present return value on legacy systems
authorGuido Martínez <guido@vanguardiasur.com.ar>
Wed, 10 Sep 2014 14:56:40 +0000 (11:56 -0300)
committerBrian Norris <computersforpeace@gmail.com>
Mon, 15 Sep 2014 17:11:02 +0000 (10:11 -0700)
On legacy systems, if "/proc/mtd" doesn't exist or gives a read error,
mtd_dev_present returns -1 (since it calls legacy_dev_present), contrary
to what's specified in the header file.

This causes checks like

  if (mtd_dev_present(n)) {
    ...
  }

to give false positives. Fix this by comparing the return value to 1.

Signed-off-by: Guido Martínez <guido@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
lib/libmtd.c

index 2089373e15eafc562b58855a5fb6f73f338c3c2c..aff4c8be01b5c444aa32681fb0554c8017a38aa6 100644 (file)
@@ -647,9 +647,9 @@ int mtd_dev_present(libmtd_t desc, int mtd_num) {
        struct stat st;
        struct libmtd *lib = (struct libmtd *)desc;
 
-       if (!lib->sysfs_supported)
-               return legacy_dev_present(mtd_num);
-       else {
+       if (!lib->sysfs_supported) {
+               return legacy_dev_present(mtd_num) == 1;
+       else {
                char file[strlen(lib->mtd) + 10];
 
                sprintf(file, lib->mtd, mtd_num);