Message ID | 1410361000-4821-1-git-send-email-guido@vanguardiasur.com.ar |
---|---|
State | Accepted |
Headers | show |
On Wed, Sep 10, 2014 at 11:56:40AM -0300, Guido Martínez wrote: > 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> Pushed to mtd-utils.git. Thanks! Brian
diff --git a/lib/libmtd.c b/lib/libmtd.c index 2089373..aff4c8b 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -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);
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> --- lib/libmtd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)