2 * Linux CAN-bus device driver.
3 * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4 * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
5 * email:pisa@cmp.felk.cvut.cz
6 * This software is released under the GPL-License.
7 * Version lincan-0.3 17 Jun 2004
10 #include "../include/can.h"
11 #include "../include/can_sysdep.h"
12 #include "../include/main.h"
13 #include "../include/close.h"
14 #include "../include/setup.h"
15 #include "../include/fasync.h"
17 #define __NO_VERSION__
18 #include <linux/module.h>
20 int can_close(struct inode *inode, struct file *file)
22 struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
23 struct canque_ends_t *qends;
25 can_spin_irqflags_t iflags;
27 if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
28 CANMSG("can_close: bad canuser magic\n");
32 obj = canuser->msgobj;
33 qends = canuser->qends;
35 #ifdef CAN_ENABLE_KERN_FASYNC
37 can_fasync(-1, file, 0);
39 #endif /*CAN_ENABLE_KERN_FASYNC*/
41 can_spin_lock_irqsave(&canuser_manipulation_lock, iflags);
42 list_del(&canuser->peers);
43 can_spin_unlock_irqrestore(&canuser_manipulation_lock, iflags);
44 canuser->qends = NULL;
45 canqueue_ends_dispose_kern(qends, file->f_flags & O_SYNC);
49 can_spin_lock_irqsave(&canuser_manipulation_lock, iflags);
50 if(atomic_dec_and_test(&obj->obj_used)){
51 can_msgobj_clear_fl(obj,OPENED);
53 can_spin_unlock_irqrestore(&canuser_manipulation_lock, iflags);
55 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,50))