Bug Summary

File:eeze_udev_find.c
Location:line 285, column 23
Description:Although the value stored to 'test' is used in the enclosing expression, the value is never actually read from 'test'

Annotated Source Code

1#ifdef HAVE_CONFIG_H1
2#include "config.h"
3#endif
4
5#include <Eeze.h>
6#include "eeze_udev_private.h"
7
8/**
9 * @addtogroup find Find
10 *
11 * These are functions which find/supplement lists of devices.
12 *
13 * @ingroup udev
14 *
15 * @{
16 */
17
18/**
19 * Returns a stringshared list of all syspaths that are (or should be) the same
20 * device as the device pointed at by @p syspath.
21 *
22 * @param syspath The syspath of the device to find matches for
23 * @return All devices which are the same as the one passed
24 */
25EAPI__attribute__ ((visibility("default"))) Eina_List *
26eeze_udev_find_similar_from_syspath(const char *syspath)
27{
28 _udev_device *device;
29 _udev_list_entry *devs, *cur;
30 _udev_enumerate *en;
31 Eina_List *l, *ret = NULL((void*)0);
32 const char *vendor, *model, *revision, *devname, *dev;
33
34 if (!syspath)
35 return NULL((void*)0);
36
37 en = udev_enumerate_new((udev));
38
39 if (!en)
40 return NULL((void*)0);
41
42 if (!(device = _new_device(syspath)))
43 return NULL((void*)0);
44
45 vendor = udev_device_get_property_value(device, "ID_VENDOR_ID");
46
47 if (vendor)
48 udev_enumerate_add_match_property(en, "ID_VENDOR_ID", vendor);
49
50 model = udev_device_get_property_value(device, "ID_MODEL_ID");
51
52 if (model)
53 udev_enumerate_add_match_property(en, "ID_MODEL_ID", model);
54
55 revision = udev_device_get_property_value(device, "ID_REVISION");
56
57 if (revision)
58 udev_enumerate_add_match_property(en, "ID_REVISION", revision);
59
60 udev_enumerate_scan_devices(en);
61 udev_device_unref(device);
62 devs = udev_enumerate_get_list_entry(en);
63 udev_list_entry_foreach(cur, devs)for (cur = devs; cur != ((void*)0); cur = udev_list_entry_get_next
(cur))
64 {
65 devname = udev_list_entry_get_name(cur);
66 /* verify unlisted device */
67
68 EINA_LIST_FOREACH(ret, l, dev)for (l = ret, dev = eina_list_data_get(l); l; l = eina_list_next
(l), dev = eina_list_data_get(l))
69 if (!strcmp(dev, devname))
70 continue;
71
72 ret = eina_list_prepend(ret, eina_stringshare_add(devname));
73 device = udev_device_new_from_syspath(udev, devname);
74
75 /* only device roots have this sysattr,
76 * and we only need to check parents of the roots
77 */
78 if (udev_device_get_sysattr_value(device, "idVendor"))
79 ret = _get_unlisted_parents(ret, device);
80
81 udev_device_unref(device);
82 }
83 udev_enumerate_unref(en);
84 return ret;
85}
86
87/**
88 * Updates a list of all syspaths that are (or should be) the same
89 * device.
90 *
91 * @param list The list of devices to update
92 * @return The updated list
93 *
94 * This function will update @p list to include all devices matching
95 * devices with syspaths currently stored in @p list. All strings are
96 * stringshared.
97 */
98EAPI__attribute__ ((visibility("default"))) Eina_List *
99eeze_udev_find_unlisted_similar(Eina_List * list)
100{
101 _udev_device *device;
102 _udev_list_entry *devs, *cur;
103 _udev_enumerate *en;
104 Eina_List *l;
105 const char *vendor, *model, *revision, *devname, *dev;
106
107 if (!list)
108 return NULL((void*)0);
109
110 EINA_LIST_FOREACH(list, l, dev)for (l = list, dev = eina_list_data_get(l); l; l = eina_list_next
(l), dev = eina_list_data_get(l))
111 {
112 en = udev_enumerate_new((udev));
113
114 if (!en)
115 return NULL((void*)0);
116
117 device = _new_device(dev);
118 if (!device) continue;
119
120 if ((vendor = udev_device_get_property_value(device, "ID_VENDOR_ID")))
121 udev_enumerate_add_match_property(en, "ID_VENDOR_ID", vendor);
122 else
123 if ((vendor = udev_device_get_property_value(device, "ID_VENDOR")))
124 udev_enumerate_add_match_property(en, "ID_VENDOR", vendor);
125
126 if ((model = udev_device_get_property_value(device, "ID_MODEL_ID")))
127 udev_enumerate_add_match_property(en, "ID_MODEL_ID", model);
128 else
129 if ((model = udev_device_get_property_value(device, "ID_MODEL")))
130 udev_enumerate_add_match_property(en, "ID_MODEL", model);
131
132 if ((revision = udev_device_get_property_value(device, "ID_REVISION")))
133 udev_enumerate_add_match_property(en, "ID_REVISION", revision);
134
135 udev_enumerate_scan_devices(en);
136 udev_device_unref(device);
137 devs = udev_enumerate_get_list_entry(en);
138 udev_list_entry_foreach(cur, devs)for (cur = devs; cur != ((void*)0); cur = udev_list_entry_get_next
(cur))
139 {
140 devname = udev_list_entry_get_name(cur);
141 device = udev_device_new_from_syspath(udev, devname);
142
143 /* only device roots have this sysattr,
144 * and we only need to check parents of the roots
145 */
146 if (udev_device_get_sysattr_value(device, "idVendor"))
147 list = _get_unlisted_parents(list, device);
148
149 udev_device_unref(device);
150 }
151 udev_enumerate_unref(en);
152 }
153 return list;
154}
155
156/**
157 * Find devices using an #Eeze_Udev_Type and/or a name.
158 *
159 * @param etype An #Eeze_Udev_Type or 0
160 * @param name A filter for the device name or #NULL
161 * @return A stringshared Eina_List of matched devices or #NULL on failure
162 *
163 * Return a list of syspaths (/sys/$syspath) for matching udev devices.
164 */
165EAPI__attribute__ ((visibility("default"))) Eina_List *
166eeze_udev_find_by_type(Eeze_Udev_Type etype, const char *name)
167{
168 _udev_enumerate *en;
169 _udev_list_entry *devs, *cur;
170 _udev_device *device, *parent;
171 const char *devname, *test;
172 Eina_List *ret = NULL((void*)0);
173
174 if ((!etype) && (!name))
175 return NULL((void*)0);
176
177 en = udev_enumerate_new((udev));
178
179 if (!en)
180 return NULL((void*)0);
181
182 switch (etype)
183 {
184 case EEZE_UDEV_TYPE_NONE:
185 break;
186 case EEZE_UDEV_TYPE_KEYBOARD:
187 udev_enumerate_add_match_subsystem(en, "input");
188#ifndef OLD_UDEV_RRRRRRRRRRRRRR
189 udev_enumerate_add_match_property(en, "ID_INPUT_KEYBOARD", "1");
190#else
191 udev_enumerate_add_match_property(en, "ID_CLASS", "kbd");
192#endif
193 break;
194 case EEZE_UDEV_TYPE_MOUSE:
195 udev_enumerate_add_match_subsystem(en, "input");
196#ifndef OLD_UDEV_RRRRRRRRRRRRRR
197 udev_enumerate_add_match_property(en, "ID_INPUT_MOUSE", "1");
198#else
199 udev_enumerate_add_match_property(en, "ID_CLASS", "mouse");
200#endif
201 break;
202 case EEZE_UDEV_TYPE_TOUCHPAD:
203 udev_enumerate_add_match_subsystem(en, "input");
204#ifndef OLD_UDEV_RRRRRRRRRRRRRR
205 udev_enumerate_add_match_property(en, "ID_INPUT_TOUCHPAD", "1");
206#endif
207 break;
208 case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
209 udev_enumerate_add_match_subsystem(en, "block");
210 udev_enumerate_add_match_property(en, "ID_FS_USAGE", "filesystem");
211 udev_enumerate_add_nomatch_sysattr(en, "capability", "52");
212 /* parent node */
213 udev_enumerate_add_nomatch_sysattr(en, "capability", "50");
214 break;
215 case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
216 udev_enumerate_add_match_subsystem(en, "block");
217 udev_enumerate_add_match_property(en, "ID_TYPE", "disk");
218 udev_enumerate_add_match_property(en, "ID_BUS", "ata");
219 udev_enumerate_add_match_sysattr(en, "removable", "0");
220 break;
221 case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
222 udev_enumerate_add_match_subsystem(en, "block");
223 udev_enumerate_add_match_property(en, "ID_TYPE", "disk");
224 break;
225 case EEZE_UDEV_TYPE_DRIVE_CDROM:
226 udev_enumerate_add_match_subsystem(en, "block");
227 udev_enumerate_add_match_property(en, "ID_CDROM", "1");
228 break;
229 case EEZE_UDEV_TYPE_POWER_AC:
230 udev_enumerate_add_match_subsystem(en, "power_supply");
231 udev_enumerate_add_match_sysattr(en, "type", "Mains");
232 break;
233 case EEZE_UDEV_TYPE_POWER_BAT:
234 udev_enumerate_add_match_subsystem(en, "power_supply");
235 udev_enumerate_add_match_sysattr(en, "type", "Battery");
236 break;
237 case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
238 udev_enumerate_add_match_subsystem(en, "hwmon");
239 break;
240 /*
241 case EEZE_UDEV_TYPE_ANDROID:
242 udev_enumerate_add_match_subsystem(en, "block");
243 udev_enumerate_add_match_property(en, "ID_MODEL", "Android_*");
244 break;
245 */
246 default:
247 break;
248 }
249
250 udev_enumerate_scan_devices(en);
251 devs = udev_enumerate_get_list_entry(en);
252 udev_list_entry_foreach(cur, devs)for (cur = devs; cur != ((void*)0); cur = udev_list_entry_get_next
(cur))
253 {
254 devname = udev_list_entry_get_name(cur);
255 device = udev_device_new_from_syspath(udev, devname);
256
257 if (etype == EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR)
258 { /* ensure that temp input exists somewhere in this device chain */
259 if (!_walk_parents_test_attr(device, "temp1_input", NULL((void*)0)))
260 goto out;
261
262 /* if device is not the one which has the temp input, we must go up the chain */
263 if (!(test = udev_device_get_sysattr_value(device, "temp1_input")))
264 {
265 devname = NULL((void*)0);
266
267 for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent)) /*check for parent */
268 if (((test = udev_device_get_sysattr_value(parent, "temp1_input"))))
269 {
270 devname = udev_device_get_syspath(parent);
271 break;
272 }
273
274 if (!devname)
275 goto out;
276 }
277 }
278 else if (etype == EEZE_UDEV_TYPE_DRIVE_INTERNAL)
279 {
280 if (udev_device_get_property_value(device, "ID_USB_DRIVER"))
281 goto out;
282 }
283 else if (etype == EEZE_UDEV_TYPE_DRIVE_REMOVABLE)
284 {
285 if (!(test = udev_device_get_property_value(device, "ID_USB_DRIVER")))
Although the value stored to 'test' is used in the enclosing expression, the value is never actually read from 'test'
286 goto out;
287 }
288
289 if (name && (!strstr(devname, name)))
290 goto out;
291
292 ret = eina_list_append(ret, eina_stringshare_add(devname));
293out:
294 udev_device_unref(device);
295 }
296 udev_enumerate_unref(en);
297 return ret;
298}
299
300/**
301 * A more advanced find, allows finds using udev properties.
302 *
303 * @param subsystem The udev subsystem to filter by, or NULL
304 * @param type "ID_INPUT_KEY", "ID_INPUT_MOUSE", "ID_INPUT_TOUCHPAD", NULL, etc
305 * @param name A filter for the device name, or NULL
306 * @return A stringshared Eina_List* of matched devices or NULL on failure
307 *
308 * Return a list of syspaths (/sys/$syspath) for matching udev devices.
309 * Requires at least one filter.
310 */
311EAPI__attribute__ ((visibility("default"))) Eina_List *
312eeze_udev_find_by_filter(const char *subsystem, const char *type,
313 const char *name)
314{
315 _udev_enumerate *en;
316 _udev_list_entry *devs, *cur;
317 _udev_device *device;
318 const char *devname;
319 Eina_List *ret = NULL((void*)0);
320
321 if ((!subsystem) && (!type) && (!name))
322 return NULL((void*)0);
323
324 en = udev_enumerate_new((udev));
325
326 if (!en)
327 return NULL((void*)0);
328
329 if (subsystem)
330 udev_enumerate_add_match_subsystem(en, subsystem);
331
332 udev_enumerate_add_match_property(en, type, "1");
333 udev_enumerate_scan_devices(en);
334 devs = udev_enumerate_get_list_entry(en);
335 udev_list_entry_foreach(cur, devs)for (cur = devs; cur != ((void*)0); cur = udev_list_entry_get_next
(cur))
336 {
337 devname = udev_list_entry_get_name(cur);
338 device = udev_device_new_from_syspath(udev, devname);
339
340 if (name)
341 if (!strstr(devname, name))
342 goto out;
343
344 ret = eina_list_append(ret, eina_stringshare_add(devname));
345out:
346 udev_device_unref(device);
347 }
348 udev_enumerate_unref(en);
349 return ret;
350}
351
352/**
353 * Find a list of devices by a sysattr (and, optionally, a value of that sysattr).
354 *
355 * @param sysattr The attribute to find
356 * @param value Optional: the value that the attribute should have
357 *
358 * @return A stringshared list of the devices found with the attribute
359 *
360 * @ingroup find
361 */
362EAPI__attribute__ ((visibility("default"))) Eina_List *
363eeze_udev_find_by_sysattr(const char *sysattr, const char *value)
364{
365 _udev_enumerate *en;
366 _udev_list_entry *devs, *cur;
367 _udev_device *device;
368 const char *devname;
369 Eina_List *ret = NULL((void*)0);
370
371 if (!sysattr)
372 return NULL((void*)0);
373
374 en = udev_enumerate_new((udev));
375
376 if (!en)
377 return NULL((void*)0);
378
379 udev_enumerate_add_match_sysattr(en, sysattr, value);
380 udev_enumerate_scan_devices(en);
381 devs = udev_enumerate_get_list_entry(en);
382 udev_list_entry_foreach(cur, devs)for (cur = devs; cur != ((void*)0); cur = udev_list_entry_get_next
(cur))
383 {
384 devname = udev_list_entry_get_name(cur);
385 device = udev_device_new_from_syspath(udev, devname);
386 ret = eina_list_append(ret, eina_stringshare_add(devname));
387 udev_device_unref(device);
388 }
389 udev_enumerate_unref(en);
390 return ret;
391}
392
393/** @} */