]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/close.c
Merge: Correction for 2.6.23-git kernel - unregister_chrdev() does not return value.
[lincan.git] / lincan / src / close.c
1 /* close.c
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
8  */
9
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"
16
17 #define __NO_VERSION__
18 #include <linux/module.h>
19
20 int can_close(struct inode *inode, struct file *file)
21 {
22         struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
23         struct canque_ends_t *qends;
24         struct msgobj_t *obj;
25         can_spin_irqflags_t iflags;
26         
27         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
28                 CANMSG("can_close: bad canuser magic\n");
29                 return -ENODEV;
30         }
31         
32         obj = canuser->msgobj;
33         qends = canuser->qends;
34         
35     #ifdef CAN_ENABLE_KERN_FASYNC
36
37         can_fasync(-1, file, 0);
38
39     #endif /*CAN_ENABLE_KERN_FASYNC*/
40
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);
46
47         kfree(canuser);
48
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);
52         };
53         can_spin_unlock_irqrestore(&canuser_manipulation_lock, iflags);
54         
55     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,50))
56         MOD_DEC_USE_COUNT;
57     #endif
58         return 0;
59 }