#include <linux/slab.h>
 #include <linux/mtd/nand_ecc.h>
 
+#include "mtd_test.h"
+
 /*
  * Test the implementation for software ECC
  *
                }
                pr_info("ok - %s-%zd\n",
                        nand_ecc_test[i].name, size);
+
+               err = mtdtest_relax();
+               if (err)
+                       break;
        }
 error:
        kfree(error_data);
 
 #include <linux/mtd/mtd.h>
+#include <linux/sched.h>
+
+static inline int mtdtest_relax(void)
+{
+       cond_resched();
+       if (signal_pending(current)) {
+               pr_info("aborting test due to pending signal!\n");
+               return -EINTR;
+       }
+
+       return 0;
+}
 
 int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum);
 int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt,
 
                        break;
                }
 
+               err = mtdtest_relax();
+               if (err)
+                       break;
+
                opno++;
        }
 
 
                        return err;
                if (i % 256 == 0)
                        pr_info("written up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       return err;
        }
        pr_info("written %u eraseblocks\n", i);
        return 0;
                        return err;
                if (i % 256 == 0)
                        pr_info("verified up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       return err;
        }
        pr_info("verified %u eraseblocks\n", i);
        return 0;
                        goto out;
                if (i % 256 == 0)
                        pr_info("verified up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("verified %u eraseblocks\n", i);
 
                                goto out;
                        if (i % 256 == 0)
                                pr_info("written up to eraseblock %u\n", i);
-                       cond_resched();
+
+                       err = mtdtest_relax();
+                       if (err)
+                               goto out;
+
                        addr += mtd->writesize;
                }
        }
                }
                if (i % 256 == 0)
                        pr_info("verified up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("verified %u eraseblocks\n", i);
 
 
                        goto out;
                if (i % 256 == 0)
                        pr_info("written up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("written %u eraseblocks\n", i);
 
                        goto out;
                if (i % 256 == 0)
                        pr_info("verified up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("verified %u eraseblocks\n", i);
 
 
                        if (!err)
                                err = ret;
                }
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
 
        if (err)
 
                err = write_eraseblock(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
                err = read_eraseblock(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
                err = write_eraseblock_by_page(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
                err = read_eraseblock_by_page(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
                err = write_eraseblock_by_2pages(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
                err = read_eraseblock_by_2pages(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
                        err = multiblock_erase(i, j);
                        if (err)
                                goto out;
-                       cond_resched();
+
+                       err = mtdtest_relax();
+                       if (err)
+                               goto out;
+
                        i += j;
                }
                stop_timing();
 
                err = do_operation();
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("finished, %d operations done\n", op);
 
 
                        return err;
                if (i % 256 == 0)
                        pr_info("verified up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       return err;
        }
        pr_info("verified %u eraseblocks\n", i);
        return 0;
                        goto out;
                if (i % 256 == 0)
                        pr_info("written up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("written %u eraseblocks\n", i);
 
                        goto out;
                if (i % 256 == 0)
                        pr_info("verified up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("verified %u eraseblocks\n", i);
 
                        goto out;
                if (i % 256 == 0)
                        pr_info("written up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("written %u eraseblocks\n", i);
 
                        goto out;
                if (i % 256 == 0)
                        pr_info("verified up to eraseblock %u\n", i);
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("verified %u eraseblocks\n", i);
 
 
                                               " for 0xFF... pattern\n");
                                        goto out;
                                }
-                               cond_resched();
+
+                               err = mtdtest_relax();
+                               if (err)
+                                       goto out;
                        }
                }
 
                        err = write_pattern(i, patt);
                        if (err)
                                goto out;
-                       cond_resched();
+
+                       err = mtdtest_relax();
+                       if (err)
+                               goto out;
                }
 
                /* Verify what we wrote */
                                               "0x55AA55..." : "0xAA55AA...");
                                        goto out;
                                }
-                               cond_resched();
+
+                               err = mtdtest_relax();
+                               if (err)
+                                       goto out;
                        }
                }