From c3e2250260f9ab7846cea5ae974ddb7379a8fef6 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 8 Feb 2012 13:26:20 -0800 Subject: libmtd: perform device checking first If we don't check for the MTD before calling `legacy_get_dev_info1', we may get errors like: libmtd: MTD subsystem is old and does not support sysfs, so MTD character device nodes have to exist libmtd: error!: "/dev/mtd2" is not a character device mtdinfo: error!: libmtd failed get MTD device 2 information error 22 (Invalid argument) So reverse the order of these two checks. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- lib/libmtd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/libmtd.c b/lib/libmtd.c index 501f3f1..c4836df 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -735,12 +735,11 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd) memset(mtd, 0, sizeof(struct mtd_dev_info)); mtd->mtd_num = mtd_num; - if (!lib->sysfs_supported) - return legacy_get_dev_info1(mtd_num, mtd); - else if (!mtd_dev_present(desc, mtd_num)) { + if (!mtd_dev_present(desc, mtd_num)) { errno = ENODEV; return -1; - } + } else if (!lib->sysfs_supported) + return legacy_get_dev_info1(mtd_num, mtd); if (dev_get_major(lib, mtd_num, &mtd->major, &mtd->minor)) return -1; -- cgit v1.2.3