/* Free any allocated pages, and free the array of page pointers.  */
static void free_device(struct nandsim *ns)
/* Free any allocated pages, and free the array of page pointers.  */
static void free_device(struct nandsim *ns)
{
	int i;
	if (ns->cfile) {
		kfree(ns->file_buf);
		vfree(ns->pages_written);
		filp_close(ns->cfile, NULL);
		return;
	}
	if (ns->pages) {
		for (i = 0; i < ns->geom.pgnum; i++) {
			if (ns->pages[i].byte)
				kmem_cache_free(ns->nand_pages_slab,
						ns->pages[i].byte);
		}
		kmem_cache_destroy(ns->nand_pages_slab);
		vfree(ns->pages);
	}
}