This source file includes following definitions.
- __scif_get_port
- scif_rsrv_port
- scif_get_new_port
- scif_get_port
- scif_put_port
1
2
3
4
5
6
7
8
9 #include <linux/idr.h>
10
11 #include "scif_main.h"
12
13 #define SCIF_PORT_COUNT 0x10000
14
15 struct idr scif_ports;
16
17
18
19
20
21
22
23 struct scif_port {
24 int ref_cnt;
25 };
26
27
28
29
30
31
32
33
34
35 static int __scif_get_port(int start, int end)
36 {
37 int id;
38 struct scif_port *port = kzalloc(sizeof(*port), GFP_ATOMIC);
39
40 if (!port)
41 return -ENOMEM;
42 spin_lock(&scif_info.port_lock);
43 id = idr_alloc(&scif_ports, port, start, end, GFP_ATOMIC);
44 if (id >= 0)
45 port->ref_cnt++;
46 spin_unlock(&scif_info.port_lock);
47 return id;
48 }
49
50
51
52
53
54
55
56
57 int scif_rsrv_port(u16 port)
58 {
59 return __scif_get_port(port, port + 1);
60 }
61
62
63
64
65
66
67
68
69 int scif_get_new_port(void)
70 {
71 return __scif_get_port(SCIF_PORT_RSVD + 1, SCIF_PORT_COUNT);
72 }
73
74
75
76
77
78
79
80 void scif_get_port(u16 id)
81 {
82 struct scif_port *port;
83
84 if (!id)
85 return;
86 spin_lock(&scif_info.port_lock);
87 port = idr_find(&scif_ports, id);
88 if (port)
89 port->ref_cnt++;
90 spin_unlock(&scif_info.port_lock);
91 }
92
93
94
95
96
97
98
99 void scif_put_port(u16 id)
100 {
101 struct scif_port *port;
102
103 if (!id)
104 return;
105 spin_lock(&scif_info.port_lock);
106 port = idr_find(&scif_ports, id);
107 if (port) {
108 port->ref_cnt--;
109 if (!port->ref_cnt) {
110 idr_remove(&scif_ports, id);
111 kfree(port);
112 }
113 }
114 spin_unlock(&scif_info.port_lock);
115 }