/* If provided device exists it's partitions are deleted, device is removed from device list and device memory is freed. */
static int device_del(struct mtd_device *dev)
/* If provided device exists it's partitions are deleted, device is removed from device list and device memory is freed. */
static int device_del(struct mtd_device *dev)
{
	part_delall(&dev->parts);
	list_del(&dev->link);
	free(dev);
	if (dev == current_mtd_dev) {
		if (list_empty(&devices)) {
			current_mtd_dev = NULL;
		} else {
			current_mtd_dev = list_entry(devices.next, struct mtd_device, link);
			current_mtd_partnum = 0;
		}
		current_save();
		return 0;
	}
	index_partitions();
	return 0;
}