* [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
* [PATCH 2/3] libmtd_legacy: don't open device in R/W
2012-02-08 21:26 [PATCH 1/3] libmtd: perform device checking first Brian Norris
@ 2012-02-08 21:26 ` 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
2 siblings, 0 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
On legacy kernels with ROM devices, we can get mtdinfo errors like:
libmtd: error!: cannot open "/dev/mtd4"
error 13 (Permission denied)
mtdinfo: error!: libmtd failed get MTD device 4 information
error 13 (Permission denied)
We don't need O_RDRW access for informational ioctls(), so make this
O_RDONLY.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
lib/libmtd_legacy.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
index d3f1672..1ae9946 100644
--- a/lib/libmtd_legacy.c
+++ b/lib/libmtd_legacy.c
@@ -262,7 +262,7 @@ int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd)
mtd->mtd_num = mtd->minor / 2;
- fd = open(node, O_RDWR);
+ fd = open(node, O_RDONLY);
if (fd == -1)
return sys_errmsg("cannot open \"%s\"", node);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] libmtd: fix segmentation fault on lib->mtd
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 ` Brian Norris
2012-02-09 12:05 ` [PATCH 1/3] libmtd: perform device checking first Artem Bityutskiy
2 siblings, 0 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
Legacy systems do not initialize lib->mtd, so we shouldn't perform
strlen(lib->mtd); this produces a segmentation fault. As this code isn't
used in the legacy codepath, we can just move it down to an 'else' branch.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
lib/libmtd.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 2bb4e57..fb4586c 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -644,13 +644,15 @@ void libmtd_close(libmtd_t desc)
int mtd_dev_present(libmtd_t desc, int mtd_num) {
struct stat st;
struct libmtd *lib = (struct libmtd *)desc;
- char file[strlen(lib->mtd) + 10];
if (!lib->sysfs_supported)
return legacy_dev_present(mtd_num);
+ else {
+ char file[strlen(lib->mtd) + 10];
- sprintf(file, lib->mtd, mtd_num);
- return !stat(file, &st);
+ sprintf(file, lib->mtd, mtd_num);
+ return !stat(file, &st);
+ }
}
int mtd_get_info(libmtd_t desc, struct mtd_info *info)
--
1.7.5.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] libmtd: perform device checking first
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 ` Artem Bityutskiy
2012-02-09 12:07 ` Artem Bityutskiy
2 siblings, 1 reply; 6+ messages in thread
From: Artem Bityutskiy @ 2012-02-09 12:05 UTC (permalink / raw)
To: Brian Norris; +Cc: Brian Foster, linux-mtd
[-- Attachment #1: Type: text/plain, Size: 714 bytes --]
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.
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] libmtd: perform device checking first
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
0 siblings, 1 reply; 6+ messages in thread
From: Artem Bityutskiy @ 2012-02-09 12:07 UTC (permalink / raw)
To: Brian Norris; +Cc: Brian Foster, linux-mtd
[-- Attachment #1: Type: text/plain, Size: 885 bytes --]
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?
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] libmtd: perform device checking first
2012-02-09 12:07 ` Artem Bityutskiy
@ 2012-02-09 18:14 ` Brian Norris
0 siblings, 0 replies; 6+ messages in thread
From: Brian Norris @ 2012-02-09 18:14 UTC (permalink / raw)
To: dedekind1; +Cc: Brian Foster, linux-mtd
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
^ permalink raw reply [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