/* Add device into the sorted list, giving it the first available minor number.  */
static int tape_assign_minor(struct tape_device *device)
/* Add device into the sorted list, giving it the first available minor number.  */
static int tape_assign_minor(struct tape_device *device)
{
	struct tape_device *tmp;
	int minor;
	minor = 0;
	write_lock(&tape_device_lock);
	list_for_each_entry(tmp, &tape_device_list, node) {
		if (minor < tmp->first_minor)
			break;
		minor += TAPE_MINORS_PER_DEV;
	}
	if (minor >= 256) {
		write_unlock(&tape_device_lock);
		return -ENODEV;
	}
	device->first_minor = minor;
	list_add_tail(&device->node, &tmp->node);
	write_unlock(&tape_device_lock);
	return 0;
}