aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/tests
diff options
context:
space:
mode:
authorWolfram Sang <w.sang@pengutronix.de>2011-11-29 09:34:08 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-01-09 13:12:42 -0500
commit2f4478ccff7df845dc9c0f8996a96373122c4417 (patch)
tree5100e886a3feff1c8c826f386be5821b26712baf /drivers/mtd/tests
parentf99640dee209df4730f35a28b02693affd571ad5 (diff)
mtd: tests: stresstest: bail out if device has not enough eraseblocks
stresstest needs at least two eraseblocks. Bail out gracefully if that condition is not met. Fixes the following 'division by zero' OOPS: [ 619.100000] mtd_stresstest: MTD device size 131072, eraseblock size 131072, page size 2048, count of eraseblocks 1, pages per eraseblock 64, OOB size 64 [ 619.120000] mtd_stresstest: scanning for bad eraseblocks [ 619.120000] mtd_stresstest: scanned 1 eraseblocks, 0 are bad [ 619.130000] mtd_stresstest: doing operations [ 619.130000] mtd_stresstest: 0 operations done [ 619.140000] Division by zero in kernel. ... caused by /* Read or write up 2 eraseblocks at a time - hence 'ebcnt - 1' */ eb %= (ebcnt - 1); Cc: stable@kernel.org Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/tests')
-rw-r--r--drivers/mtd/tests/mtd_stresstest.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 52ffd9120e0d..811642fea6b4 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -284,6 +284,12 @@ static int __init mtd_stresstest_init(void)
284 (unsigned long long)mtd->size, mtd->erasesize, 284 (unsigned long long)mtd->size, mtd->erasesize,
285 pgsize, ebcnt, pgcnt, mtd->oobsize); 285 pgsize, ebcnt, pgcnt, mtd->oobsize);
286 286
287 if (ebcnt < 2) {
288 printk(PRINT_PREF "error: need at least 2 eraseblocks\n");
289 err = -ENOSPC;
290 goto out_put_mtd;
291 }
292
287 /* Read or write up 2 eraseblocks at a time */ 293 /* Read or write up 2 eraseblocks at a time */
288 bufsize = mtd->erasesize * 2; 294 bufsize = mtd->erasesize * 2;
289 295
@@ -322,6 +328,7 @@ out:
322 kfree(bbt); 328 kfree(bbt);
323 vfree(writebuf); 329 vfree(writebuf);
324 vfree(readbuf); 330 vfree(readbuf);
331out_put_mtd:
325 put_mtd_device(mtd); 332 put_mtd_device(mtd);
326 if (err) 333 if (err)
327 printk(PRINT_PREF "error %d occurred\n", err); 334 printk(PRINT_PREF "error %d occurred\n", err);