* [PATCH] [MTD] MTD-Utils: fix handling of ioctl return value in nand-utils
@ 2007-03-14 13:17 Frank Haverkamp
2007-03-15 13:10 ` Josh Boyer
0 siblings, 1 reply; 2+ messages in thread
From: Frank Haverkamp @ 2007-03-14 13:17 UTC (permalink / raw)
To: Josh Boyer
Cc: David Woodhouse, Thomas Gleixner, MTD Mailinglist,
Frank Haverkamp
Older kernel do not implement the MTDFILEMODE ioctl. In this case
nandwrite and nanddump should have used MEMGETOOBSEL in combination
with MEMSETOOBSEL. Unfortunately the return value of the unsucessfull
ioctl is not -ENOTTY, but -1 and errno contains ENOTTY. This change
fixes this issue. I have not tested all cornercases. Would be
good if someone could do more careful testing than I did, or maybe
reviewing is sufficient in this case.
Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
---
nanddump.c | 16 ++++++++--------
nandwrite.c | 14 +++++++-------
2 files changed, 15 insertions(+), 15 deletions(-)
--- mtd-utils.git.orig/nandwrite.c
+++ mtd-utils.git/nandwrite.c
@@ -271,9 +271,12 @@ int main(int argc, char **argv)
}
if (noecc) {
- switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) {
-
- case -ENOTTY:
+ ret = ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW);
+ if (ret == 0) {
+ oobinfochanged = 2;
+ } else {
+ switch (errno) {
+ case ENOTTY:
if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
perror ("MEMGETOOBSEL");
close (fd);
@@ -286,14 +289,11 @@ int main(int argc, char **argv)
}
oobinfochanged = 1;
break;
-
- case 0:
- oobinfochanged = 2;
- break;
default:
perror ("MTDFILEMODE");
close (fd);
exit (1);
+ }
}
}
--- mtd-utils.git.orig/nanddump.c
+++ mtd-utils.git/nanddump.c
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
{
unsigned long ofs, end_addr = 0;
unsigned long long blockstart = 1;
- int i, fd, ofd, bs, badblock = 0;
+ int ret, i, fd, ofd, bs, badblock = 0;
struct mtd_oob_buf oob = {0, 16, oobbuf};
mtd_info_t meminfo;
char pretty_buf[80];
@@ -206,9 +206,12 @@ int main(int argc, char **argv)
oob.length = meminfo.oobsize;
if (noecc) {
- switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) {
-
- case -ENOTTY:
+ ret = ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW);
+ if (ret == 0) {
+ oobinfochanged = 2;
+ } else {
+ switch (errno) {
+ case ENOTTY:
if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
perror ("MEMGETOOBSEL");
close (fd);
@@ -221,14 +224,11 @@ int main(int argc, char **argv)
}
oobinfochanged = 1;
break;
-
- case 0:
- oobinfochanged = 2;
- break;
default:
perror ("MTDFILEMODE");
close (fd);
exit (1);
+ }
}
} else {
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] [MTD] MTD-Utils: fix handling of ioctl return value in nand-utils
2007-03-14 13:17 [PATCH] [MTD] MTD-Utils: fix handling of ioctl return value in nand-utils Frank Haverkamp
@ 2007-03-15 13:10 ` Josh Boyer
0 siblings, 0 replies; 2+ messages in thread
From: Josh Boyer @ 2007-03-15 13:10 UTC (permalink / raw)
To: haver; +Cc: David Woodhouse, Thomas Gleixner, MTD Mailinglist
On 3/14/07, Frank Haverkamp <haver@vnet.ibm.com> wrote:
> Older kernel do not implement the MTDFILEMODE ioctl. In this case
> nandwrite and nanddump should have used MEMGETOOBSEL in combination
> with MEMSETOOBSEL. Unfortunately the return value of the unsucessfull
> ioctl is not -ENOTTY, but -1 and errno contains ENOTTY. This change
> fixes this issue. I have not tested all cornercases. Would be
> good if someone could do more careful testing than I did, or maybe
> reviewing is sufficient in this case.
This looks good. Applied. Thank you.
josh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-03-15 13:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-14 13:17 [PATCH] [MTD] MTD-Utils: fix handling of ioctl return value in nand-utils Frank Haverkamp
2007-03-15 13:10 ` Josh Boyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox