/* Unregister a miscellaneous device that was previously successfully registered with misc_register(). Success is indicated by a zero return, a negative errno code indicates an error.  */
int misc_deregister(struct miscdevice *misc)
/* Unregister a miscellaneous device that was previously successfully registered with misc_register(). Success is indicated by a zero return, a negative errno code indicates an error.  */
int misc_deregister(struct miscdevice *misc)
{
	int i = DYNAMIC_MINORS - misc->minor - 1;
	if (list_empty(&misc->list))
		return -EINVAL;
	mutex_lock(&misc_mtx);
	list_del(&misc->list);
	device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
	if (i < DYNAMIC_MINORS && i >= 0)
		clear_bit(i, misc_minors);
	mutex_unlock(&misc_mtx);
	return 0;
}