This source file includes following definitions.
- devm_extcon_dev_match
- devm_extcon_dev_release
- devm_extcon_dev_unreg
- devm_extcon_dev_notifier_unreg
- devm_extcon_dev_notifier_all_unreg
- devm_extcon_dev_allocate
- devm_extcon_dev_free
- devm_extcon_dev_register
- devm_extcon_dev_unregister
- devm_extcon_register_notifier
- devm_extcon_unregister_notifier
- devm_extcon_register_notifier_all
- devm_extcon_unregister_notifier_all
1
2
3
4
5
6
7
8
9 #include "extcon.h"
10
11 static int devm_extcon_dev_match(struct device *dev, void *res, void *data)
12 {
13 struct extcon_dev **r = res;
14
15 if (WARN_ON(!r || !*r))
16 return 0;
17
18 return *r == data;
19 }
20
21 static void devm_extcon_dev_release(struct device *dev, void *res)
22 {
23 extcon_dev_free(*(struct extcon_dev **)res);
24 }
25
26
27 static void devm_extcon_dev_unreg(struct device *dev, void *res)
28 {
29 extcon_dev_unregister(*(struct extcon_dev **)res);
30 }
31
32 struct extcon_dev_notifier_devres {
33 struct extcon_dev *edev;
34 unsigned int id;
35 struct notifier_block *nb;
36 };
37
38 static void devm_extcon_dev_notifier_unreg(struct device *dev, void *res)
39 {
40 struct extcon_dev_notifier_devres *this = res;
41
42 extcon_unregister_notifier(this->edev, this->id, this->nb);
43 }
44
45 static void devm_extcon_dev_notifier_all_unreg(struct device *dev, void *res)
46 {
47 struct extcon_dev_notifier_devres *this = res;
48
49 extcon_unregister_notifier_all(this->edev, this->nb);
50 }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
66 const unsigned int *supported_cable)
67 {
68 struct extcon_dev **ptr, *edev;
69
70 ptr = devres_alloc(devm_extcon_dev_release, sizeof(*ptr), GFP_KERNEL);
71 if (!ptr)
72 return ERR_PTR(-ENOMEM);
73
74 edev = extcon_dev_allocate(supported_cable);
75 if (IS_ERR(edev)) {
76 devres_free(ptr);
77 return edev;
78 }
79
80 edev->dev.parent = dev;
81
82 *ptr = edev;
83 devres_add(dev, ptr);
84
85 return edev;
86 }
87 EXPORT_SYMBOL_GPL(devm_extcon_dev_allocate);
88
89
90
91
92
93
94
95
96
97 void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev)
98 {
99 WARN_ON(devres_release(dev, devm_extcon_dev_release,
100 devm_extcon_dev_match, edev));
101 }
102 EXPORT_SYMBOL_GPL(devm_extcon_dev_free);
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 int devm_extcon_dev_register(struct device *dev, struct extcon_dev *edev)
119 {
120 struct extcon_dev **ptr;
121 int ret;
122
123 ptr = devres_alloc(devm_extcon_dev_unreg, sizeof(*ptr), GFP_KERNEL);
124 if (!ptr)
125 return -ENOMEM;
126
127 ret = extcon_dev_register(edev);
128 if (ret) {
129 devres_free(ptr);
130 return ret;
131 }
132
133 *ptr = edev;
134 devres_add(dev, ptr);
135
136 return 0;
137 }
138 EXPORT_SYMBOL_GPL(devm_extcon_dev_register);
139
140
141
142
143
144
145
146
147
148 void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev)
149 {
150 WARN_ON(devres_release(dev, devm_extcon_dev_unreg,
151 devm_extcon_dev_match, edev));
152 }
153 EXPORT_SYMBOL_GPL(devm_extcon_dev_unregister);
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 int devm_extcon_register_notifier(struct device *dev, struct extcon_dev *edev,
173 unsigned int id, struct notifier_block *nb)
174 {
175 struct extcon_dev_notifier_devres *ptr;
176 int ret;
177
178 ptr = devres_alloc(devm_extcon_dev_notifier_unreg, sizeof(*ptr),
179 GFP_KERNEL);
180 if (!ptr)
181 return -ENOMEM;
182
183 ret = extcon_register_notifier(edev, id, nb);
184 if (ret) {
185 devres_free(ptr);
186 return ret;
187 }
188
189 ptr->edev = edev;
190 ptr->id = id;
191 ptr->nb = nb;
192 devres_add(dev, ptr);
193
194 return 0;
195 }
196 EXPORT_SYMBOL(devm_extcon_register_notifier);
197
198
199
200
201
202
203
204
205
206 void devm_extcon_unregister_notifier(struct device *dev,
207 struct extcon_dev *edev, unsigned int id,
208 struct notifier_block *nb)
209 {
210 WARN_ON(devres_release(dev, devm_extcon_dev_notifier_unreg,
211 devm_extcon_dev_match, edev));
212 }
213 EXPORT_SYMBOL(devm_extcon_unregister_notifier);
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228 int devm_extcon_register_notifier_all(struct device *dev, struct extcon_dev *edev,
229 struct notifier_block *nb)
230 {
231 struct extcon_dev_notifier_devres *ptr;
232 int ret;
233
234 ptr = devres_alloc(devm_extcon_dev_notifier_all_unreg, sizeof(*ptr),
235 GFP_KERNEL);
236 if (!ptr)
237 return -ENOMEM;
238
239 ret = extcon_register_notifier_all(edev, nb);
240 if (ret) {
241 devres_free(ptr);
242 return ret;
243 }
244
245 ptr->edev = edev;
246 ptr->nb = nb;
247 devres_add(dev, ptr);
248
249 return 0;
250 }
251 EXPORT_SYMBOL(devm_extcon_register_notifier_all);
252
253
254
255
256
257
258
259
260 void devm_extcon_unregister_notifier_all(struct device *dev,
261 struct extcon_dev *edev,
262 struct notifier_block *nb)
263 {
264 WARN_ON(devres_release(dev, devm_extcon_dev_notifier_all_unreg,
265 devm_extcon_dev_match, edev));
266 }
267 EXPORT_SYMBOL(devm_extcon_unregister_notifier_all);