Patchwork [1/3] libmtd: perform device checking first

login
register
mail settings
Submitter Brian Norris
Date Feb. 8, 2012, 9:26 p.m.
Message ID <1328736382-5798-1-git-send-email-computersforpeace@gmail.com>
Download mbox | patch
Permalink /patch/140262/
State New
Headers show

Comments

Brian Norris - Feb. 8, 2012, 9:26 p.m.
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(-)
Artem Bityutskiy - Feb. 9, 2012, 12:05 p.m.
On Wed, 2012-02-08 at 13:26 -0800, Brian Norris wrote:
> 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>

Looks good, thanks, but could you please send a version which applies to
mtd-utils.git? The 3rd patch in this series does not apply.
Artem Bityutskiy - Feb. 9, 2012, 12:07 p.m.
On Thu, 2012-02-09 at 14:05 +0200, Artem Bityutskiy wrote:
> On Wed, 2012-02-08 at 13:26 -0800, Brian Norris wrote:
> > 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>
> 
> Looks good, thanks, but could you please send a version which applies to
> mtd-utils.git? The 3rd patch in this series does not apply.

Actually, I've pushed patches 1 and 2, would you please re-send the 3rd
one?
Brian Norris - Feb. 9, 2012, 6:14 p.m.
On Thu, Feb 9, 2012 at 4:07 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> On Thu, 2012-02-09 at 14:05 +0200, Artem Bityutskiy wrote:
>> Looks good, thanks, but could you please send a version which applies to
>> mtd-utils.git? The 3rd patch in this series does not apply.
>
> Actually, I've pushed patches 1 and 2, would you please re-send the 3rd
> one?

Perhaps I should have stated in this patch thread: these patches were
meant to be on top of your previous test patch (you asked for
comments, since you compile-tested only).

Also, I do not see patches 1 and 2 in mtd-utils.git.

I will resend your original patch + my "PATCH 3" as a new series.

Brian

Patch

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;