/* This function solves a real-life problem observed on NOR flashes when an PEB erase operation starts, then the system is rebooted before the erase is finishes, and the boot loader gets confused and dies. So we prefer to finish the ongoing operation before rebooting.  */
static int ubi_reboot_notifier(struct notifier_block *n, unsigned long state, void *cmd)
/* This function solves a real-life problem observed on NOR flashes when an PEB erase operation starts, then the system is rebooted before the erase is finishes, and the boot loader gets confused and dies. So we prefer to finish the ongoing operation before rebooting.  */
static int ubi_reboot_notifier(struct notifier_block *n, unsigned long state, void *cmd)
{
	struct ubi_device *ubi;
	ubi = container_of(n, struct ubi_device, reboot_notifier);
	if (ubi->bgt_thread)
		kthread_stop(ubi->bgt_thread);
	ubi_sync(ubi->ubi_num);
	return NOTIFY_DONE;
}