Structured comments updated.
[lincan.git] / lincan / src / finish.c
1 #include "../include/can.h"
2 #include "../include/can_sysdep.h"
3 #include "../include/main.h"
4 #include "../include/devcommon.h"
5 #include "../include/finish.h"
6 #include "../include/setup.h"
7
8
9 /**
10  * msgobj_done - destroys one CAN message object
11  * @obj: pointer to CAN message object structure
12  */
13 void msgobj_done(struct msgobj_t *obj)
14 {
15         int delayed=0;
16         if(obj->qends) {
17                 delayed=canqueue_ends_done_chip(obj->qends);
18                 if(delayed < 0)
19                         CANMSG("msgobj_done: problem with chip queue ends\n");
20         }
21
22         if((obj->hostchip) && (obj->object>0)) {
23                 if(obj->hostchip->msgobj[obj->object-1] == obj)
24                         obj->hostchip->msgobj[obj->object-1]=NULL;
25                 else
26                         CANMSG("msgobj_done: not registered in the chip_t\n");
27                 obj->hostchip=NULL;
28         }
29         
30         if((obj->minor>=0)) {
31                 if(objects_p[obj->minor] == obj)
32                         objects_p[obj->minor] = NULL;
33                 else
34                         CANMSG("msgobj_done: not registered as minor\n");
35         }
36         
37         del_timer_sync(&obj->tx_timeout);
38
39         if(obj->qends) {
40                 /*delayed free could be required there in the future,
41                   actual use patter cannot generate such situation*/
42                 if(!delayed) {
43                         can_checked_free(obj->qends);
44                 }
45         }
46         obj->qends=NULL;
47 }
48
49
50 /**
51  * canchip_done - destroys one CAN chip representation
52  * @chip: pointer to CAN chip structure
53  */
54 void canchip_done(struct chip_t *chip)
55 {
56
57         int i;
58         struct msgobj_t *obj;
59
60         if((chip->hostdevice) && (chip->chip_idx>=0)) {
61                 if(chip->hostdevice->chip[chip->chip_idx] == chip)
62                         chip->hostdevice->chip[chip->chip_idx] = NULL;
63                 else
64                         CANMSG("canchip_done: not registered in hostdevice\n");
65         }
66
67         can_chip_free_irq(chip);
68                 
69         can_synchronize_irq(chip->chip_irq);
70         
71         for(i=0; i<chip->max_objects; i++){
72                 if((obj=chip->msgobj[i])==NULL)
73                         continue;
74                 msgobj_done(obj);
75                 can_checked_free(obj);
76         }
77         
78         can_checked_free(chip->chipspecops);
79         chip->chipspecops=NULL;
80
81 }
82
83 /**
84  * candevice_done - destroys representation of one CAN device/board
85  * @candev: pointer to CAN device/board structure
86  */
87 void candevice_done(struct candevice_t *candev)
88 {
89         int i;
90         struct chip_t *chip;
91         
92         for(i=0; i<candev->nr_all_chips; i++){
93                 if((chip=candev->chip[i])==NULL)
94                         continue;
95                 canchip_done(chip);
96                 can_checked_free(chip);
97         
98         }
99         if(candev->flags & CANDEV_IO_RESERVED) {
100                 candev->hwspecops->release_io(candev);
101                 candev->flags &= ~CANDEV_IO_RESERVED;
102         }
103         can_checked_free(candev->hwspecops);
104         candev->hwspecops=NULL;
105 }
106
107 /**
108  * candevice_done - destroys representation of all CAN devices/boards
109  * @canhw: pointer to the root of all CAN hardware representation
110  */
111 void canhardware_done(struct canhardware_t *canhw)
112 {
113         int i;
114         struct candevice_t *candev;
115         
116         for(i=0; i<canhw->nr_boards; i++){
117                 if((candev=canhw->candevice[i])==NULL)
118                         continue;
119                 candevice_done(candev);
120                 can_checked_free(candev);
121         }
122
123 }