public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/3] libmtd: perform device checking first
@ 2012-02-08 21:26 Brian Norris
  2012-02-08 21:26 ` [PATCH 2/3] libmtd_legacy: don't open device in R/W Brian Norris
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Brian Norris @ 2012-02-08 21:26 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Brian Foster, Brian Norris, linux-mtd

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 <computersforpeace@gmail.com>
---
 lib/libmtd.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/libmtd.c b/lib/libmtd.c
index ecf182f..2bb4e57 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -733,12 +733,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;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-02-09 18:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-08 21:26 [PATCH 1/3] libmtd: perform device checking first Brian Norris
2012-02-08 21:26 ` [PATCH 2/3] libmtd_legacy: don't open device in R/W Brian Norris
2012-02-08 21:26 ` [PATCH 3/3] libmtd: fix segmentation fault on lib->mtd Brian Norris
2012-02-09 12:05 ` [PATCH 1/3] libmtd: perform device checking first Artem Bityutskiy
2012-02-09 12:07   ` Artem Bityutskiy
2012-02-09 18:14     ` Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox