device_destroy(aim_class, c->devno);
cdev_del(&c->cdev);
- kfifo_free(&c->fifo);
spin_lock_irqsave(&ch_list_lock, flags);
list_del(&c->list);
spin_unlock_irqrestore(&ch_list_lock, flags);
+}
+
+static void destroy_channel(struct aim_channel *c)
+{
ida_simple_remove(&minor_id, MINOR(c->devno));
+ kfifo_free(&c->fifo);
+ kfree(c);
}
/**
stop_channel(c);
mutex_unlock(&c->io_mutex);
} else {
- destroy_cdev(c);
mutex_unlock(&c->io_mutex);
- kfree(c);
+ destroy_channel(c);
}
return 0;
}
spin_lock(&c->unlink);
c->dev = NULL;
spin_unlock(&c->unlink);
+ destroy_cdev(c);
if (c->access_ref) {
stop_channel(c);
wake_up_interruptible(&c->wq);
mutex_unlock(&c->io_mutex);
} else {
- destroy_cdev(c);
mutex_unlock(&c->io_mutex);
- kfree(c);
+ destroy_channel(c);
}
return 0;
}
list_for_each_entry_safe(c, tmp, &channel_list, list) {
destroy_cdev(c);
- kfree(c);
+ destroy_channel(c);
}
class_destroy(aim_class);
unregister_chrdev_region(aim_devno, 1);