Skip to content

Commit

Permalink
mtd: tests: incorporate error message for mtdtest_write()
Browse files Browse the repository at this point in the history
All callers of mtdtest_write() print the same error message on failure.
This incorporates the error message to mtdtest_write() and removes them
from the callers.

Signed-off-by: Akinobu Mita <[email protected]>
Signed-off-by: Artem Bityutskiy <[email protected]>
Signed-off-by: David Woodhouse <[email protected]>
  • Loading branch information
mita authored and David Woodhouse committed Aug 30, 2013
1 parent abc173a commit 8a9f4aa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 50 deletions.
2 changes: 2 additions & 0 deletions drivers/mtd/tests/mtd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ int mtdtest_write(struct mtd_info *mtd, loff_t addr, size_t size,
err = mtd_write(mtd, addr, size, &written, buf);
if (!err && written != size)
err = -EIO;
if (err)
pr_err("error: write failed at %#llx\n", addr);

return err;
}
8 changes: 1 addition & 7 deletions drivers/mtd/tests/nandbiterrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,10 @@ static uint8_t hash(unsigned offset)
/* Writes wbuffer to page */
static int write_page(int log)
{
int err;

if (log)
pr_info("write_page\n");

err = mtdtest_write(mtd, offset, mtd->writesize, wbuffer);
if (err)
pr_err("error: write failed at %#llx\n", (long long)offset);

return err;
return mtdtest_write(mtd, offset, mtd->writesize, wbuffer);
}

/* Re-writes the data area while leaving the OOB alone. */
Expand Down
23 changes: 4 additions & 19 deletions drivers/mtd/tests/pagetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,11 @@ static struct rnd_state rnd_state;

static int write_eraseblock(int ebnum)
{
int err;
loff_t addr = ebnum * mtd->erasesize;

prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
cond_resched();
err = mtdtest_write(mtd, addr, mtd->erasesize, writebuf);
if (err)
pr_err("error: write failed at %#llx\n",
(long long)addr);

return err;
return mtdtest_write(mtd, addr, mtd->erasesize, writebuf);
}

static int verify_eraseblock(int ebnum)
Expand Down Expand Up @@ -232,11 +226,8 @@ static int erasecrosstest(void)
prandom_bytes_state(&rnd_state, writebuf, pgsize);
strcpy(writebuf, "There is no data like this!");
err = mtdtest_write(mtd, addr0, pgsize, writebuf);
if (err) {
pr_info("error: write failed at %#llx\n",
(long long)addr0);
if (err)
return err;
}

pr_info("reading 1st page of block %d\n", ebnum);
memset(readbuf, 0, pgsize);
Expand All @@ -260,11 +251,8 @@ static int erasecrosstest(void)
prandom_bytes_state(&rnd_state, writebuf, pgsize);
strcpy(writebuf, "There is no data like this!");
err = mtdtest_write(mtd, addr0, pgsize, writebuf);
if (err) {
pr_err("error: write failed at %#llx\n",
(long long)addr0);
if (err)
return err;
}

pr_info("erasing block %d\n", ebnum2);
err = mtdtest_erase_eraseblock(mtd, ebnum2);
Expand Down Expand Up @@ -311,11 +299,8 @@ static int erasetest(void)
pr_info("writing 1st page of block %d\n", ebnum);
prandom_bytes_state(&rnd_state, writebuf, pgsize);
err = mtdtest_write(mtd, addr0, pgsize, writebuf);
if (err) {
pr_err("error: write failed at %#llx\n",
(long long)addr0);
if (err)
return err;
}

pr_info("erasing block %d\n", ebnum);
err = mtdtest_erase_eraseblock(mtd, ebnum);
Expand Down
24 changes: 4 additions & 20 deletions drivers/mtd/tests/speedtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,9 @@ static int multiblock_erase(int ebnum, int blocks)

static int write_eraseblock(int ebnum)
{
int err;
loff_t addr = ebnum * mtd->erasesize;

err = mtdtest_write(mtd, addr, mtd->erasesize, iobuf);
if (err)
pr_err("error: write failed at %#llx\n", addr);

return err;
return mtdtest_write(mtd, addr, mtd->erasesize, iobuf);
}

static int write_eraseblock_by_page(int ebnum)
Expand All @@ -98,11 +93,8 @@ static int write_eraseblock_by_page(int ebnum)

for (i = 0; i < pgcnt; i++) {
err = mtdtest_write(mtd, addr, pgsize, buf);
if (err) {
pr_err("error: write failed at %#llx\n",
addr);
if (err)
break;
}
addr += pgsize;
buf += pgsize;
}
Expand All @@ -119,21 +111,13 @@ static int write_eraseblock_by_2pages(int ebnum)

for (i = 0; i < n; i++) {
err = mtdtest_write(mtd, addr, sz, buf);
if (err) {
pr_err("error: write failed at %#llx\n",
addr);
if (err)
return err;
}
addr += sz;
buf += sz;
}
if (pgcnt % 2) {
if (pgcnt % 2)
err = mtdtest_write(mtd, addr, pgsize, buf);
if (err) {
pr_err("error: write failed at %#llx\n",
addr);
}
}

return err;
}
Expand Down
5 changes: 1 addition & 4 deletions drivers/mtd/tests/stresstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ static int do_write(void)
}
addr = eb * mtd->erasesize + offs;
err = mtdtest_write(mtd, addr, len, writebuf);
if (unlikely(err)) {
pr_err("error: write failed at 0x%llx\n",
(long long)addr);
if (unlikely(err))
return err;
}
offs += len;
while (offs > mtd->erasesize) {
offsets[eb++] = mtd->erasesize;
Expand Down

0 comments on commit 8a9f4aa

Please sign in to comment.