]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/close.c
CAN driver infrastructure redesign to LinCAN-0.2 version
[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.2  9 Jul 2003
8  */
9
10 #define __NO_VERSION__
11 #include <linux/module.h> 
12
13 #include <linux/autoconf.h>
14
15 #include <linux/fs.h>
16 #include <linux/version.h>
17 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
18 #include <linux/malloc.h>
19 #else
20 #include <linux/slab.h>
21 #endif
22
23 #include "../include/main.h"
24 #include "../include/close.h"
25 #include "../include/i82527.h"
26 #include "../include/setup.h"
27
28 int can_close(struct inode *inode, struct file *file)
29 {
30         struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
31         struct canque_ends_t *qends;
32         struct msgobj_t *obj;
33         
34         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
35                 CANMSG("can_close: bad canuser magic\n");
36                 return -ENODEV;
37         }
38         
39         obj = canuser->msgobj;
40         qends = canuser->qends;
41
42         list_del(&canuser->peers);
43         canqueue_ends_done_kern(qends, 1);
44         canuser->qends = NULL;
45         kfree(qends);
46
47         kfree(canuser);
48
49         if(atomic_dec_and_test(&obj->obj_used)){
50                 obj->flags &= ~OBJ_OPENED;
51                 /* FIXME: what about clearing chip HW status, stopping sending messages etc? */
52         };
53         
54 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,50))
55         MOD_DEC_USE_COUNT;
56 #endif
57         return 0;
58 }