GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 97.9% 47 / 0 / 48
Functions: 100.0% 3 / 0 / 3
Branches: 92.3% 24 / 0 / 26

libfprint/fprint-list-udev-hwdb.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2009 Red Hat <mjg@redhat.com>
3 * Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
4 * Copyright (C) 2008 Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
5 * Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <config.h>
23
24 #include "fpi-context.h"
25 #include "fpi-device.h"
26
27 static const FpIdEntry allowlist_id_table[] = {
28 /* Currently known and unsupported devices.
29 * You can regenerate this list from the wiki page with:
30 * meson compile -C <build-dir> sync-unsupported-devices
31 */
32 /* --- BEGIN GENERATED IDS --- */
33 { .vid = 0x006b, .pid = 0x00da },
34 { .vid = 0x0413, .pid = 0x2766 },
35 { .vid = 0x045e, .pid = 0x0815 },
36 { .vid = 0x047d, .pid = 0x00f2 },
37 { .vid = 0x047d, .pid = 0x8054 },
38 { .vid = 0x047d, .pid = 0x8055 },
39 { .vid = 0x0483, .pid = 0x2016 },
40 { .vid = 0x04e8, .pid = 0x730b },
41 { .vid = 0x04f2, .pid = 0xb61e },
42 { .vid = 0x04f3, .pid = 0x036b },
43 { .vid = 0x04f3, .pid = 0x0c00 },
44 { .vid = 0x04f3, .pid = 0x0c4c },
45 { .vid = 0x04f3, .pid = 0x0c57 },
46 { .vid = 0x04f3, .pid = 0x0c5a },
47 { .vid = 0x04f3, .pid = 0x0c5e },
48 { .vid = 0x04f3, .pid = 0x0c60 },
49 { .vid = 0x04f3, .pid = 0x0c6c },
50 { .vid = 0x04f3, .pid = 0x0c70 },
51 { .vid = 0x04f3, .pid = 0x0c72 },
52 { .vid = 0x04f3, .pid = 0x0c77 },
53 { .vid = 0x04f3, .pid = 0x0c7c },
54 { .vid = 0x04f3, .pid = 0x0c7f },
55 { .vid = 0x04f3, .pid = 0x0c80 },
56 { .vid = 0x04f3, .pid = 0x0c85 },
57 { .vid = 0x04f3, .pid = 0x0c8a },
58 { .vid = 0x04f3, .pid = 0x0c8e },
59 { .vid = 0x04f3, .pid = 0x0c90 },
60 { .vid = 0x04f3, .pid = 0x0ca2 },
61 { .vid = 0x04f3, .pid = 0x24cc },
62 { .vid = 0x04f3, .pid = 0x2706 },
63 { .vid = 0x04f3, .pid = 0x3032 },
64 { .vid = 0x04f3, .pid = 0x3057 },
65 { .vid = 0x04f3, .pid = 0x3058 },
66 { .vid = 0x04f3, .pid = 0x3066 },
67 { .vid = 0x04f3, .pid = 0x3087 },
68 { .vid = 0x04f3, .pid = 0x309f },
69 { .vid = 0x04f3, .pid = 0x30c6 },
70 { .vid = 0x04f3, .pid = 0x3104 },
71 { .vid = 0x04f3, .pid = 0x310d },
72 { .vid = 0x04f3, .pid = 0x3128 },
73 { .vid = 0x04f3, .pid = 0x3195 },
74 { .vid = 0x04f3, .pid = 0x31fc },
75 { .vid = 0x04f3, .pid = 0x3201 },
76 { .vid = 0x04f3, .pid = 0x3212 },
77 { .vid = 0x05ba, .pid = 0x000e },
78 { .vid = 0x05c8, .pid = 0x03c0 },
79 { .vid = 0x06cb, .pid = 0x0051 },
80 { .vid = 0x06cb, .pid = 0x0081 },
81 { .vid = 0x06cb, .pid = 0x0088 },
82 { .vid = 0x06cb, .pid = 0x008a },
83 { .vid = 0x06cb, .pid = 0x009a },
84 { .vid = 0x06cb, .pid = 0x009b },
85 { .vid = 0x06cb, .pid = 0x00a1 },
86 { .vid = 0x06cb, .pid = 0x00a2 },
87 { .vid = 0x06cb, .pid = 0x00a8 },
88 { .vid = 0x06cb, .pid = 0x00b7 },
89 { .vid = 0x06cb, .pid = 0x00bb },
90 { .vid = 0x06cb, .pid = 0x00bc },
91 { .vid = 0x06cb, .pid = 0x00be },
92 { .vid = 0x06cb, .pid = 0x00c7 },
93 { .vid = 0x06cb, .pid = 0x00c9 },
94 { .vid = 0x06cb, .pid = 0x00cb },
95 { .vid = 0x06cb, .pid = 0x00d8 },
96 { .vid = 0x06cb, .pid = 0x00da },
97 { .vid = 0x06cb, .pid = 0x00dc },
98 { .vid = 0x06cb, .pid = 0x00e4 },
99 { .vid = 0x06cb, .pid = 0x00e7 },
100 { .vid = 0x06cb, .pid = 0x00fd },
101 { .vid = 0x06cb, .pid = 0x00ff },
102 { .vid = 0x06cb, .pid = 0x0102 },
103 { .vid = 0x06cb, .pid = 0xce67 },
104 { .vid = 0x06cb, .pid = 0xceef },
105 { .vid = 0x08ff, .pid = 0x3400 },
106 { .vid = 0x0a5c, .pid = 0x5801 },
107 { .vid = 0x0a5c, .pid = 0x5802 },
108 { .vid = 0x0a5c, .pid = 0x5805 },
109 { .vid = 0x0a5c, .pid = 0x5834 },
110 { .vid = 0x0a5c, .pid = 0x5840 },
111 { .vid = 0x0a5c, .pid = 0x5841 },
112 { .vid = 0x0a5c, .pid = 0x5842 },
113 { .vid = 0x0a5c, .pid = 0x5843 },
114 { .vid = 0x0a5c, .pid = 0x5844 },
115 { .vid = 0x0a5c, .pid = 0x5845 },
116 { .vid = 0x0a5c, .pid = 0x5860 },
117 { .vid = 0x0a5c, .pid = 0x5863 },
118 { .vid = 0x0a5c, .pid = 0x5864 },
119 { .vid = 0x0a5c, .pid = 0x5865 },
120 { .vid = 0x0a5c, .pid = 0x5866 },
121 { .vid = 0x0a5c, .pid = 0x5867 },
122 { .vid = 0x0bda, .pid = 0x0129 },
123 { .vid = 0x0bda, .pid = 0x5812 },
124 { .vid = 0x10a5, .pid = 0x0007 },
125 { .vid = 0x10a5, .pid = 0x9200 },
126 { .vid = 0x10a5, .pid = 0x9201 },
127 { .vid = 0x10a5, .pid = 0x9800 },
128 { .vid = 0x10a5, .pid = 0xa120 },
129 { .vid = 0x10a5, .pid = 0xa900 },
130 { .vid = 0x10a5, .pid = 0xa921 },
131 { .vid = 0x10a5, .pid = 0xe340 },
132 { .vid = 0x1188, .pid = 0x9545 },
133 { .vid = 0x138a, .pid = 0x0006 },
134 { .vid = 0x138a, .pid = 0x0007 },
135 { .vid = 0x138a, .pid = 0x003a },
136 { .vid = 0x138a, .pid = 0x003c },
137 { .vid = 0x138a, .pid = 0x003d },
138 { .vid = 0x138a, .pid = 0x003f },
139 { .vid = 0x138a, .pid = 0x0090 },
140 { .vid = 0x138a, .pid = 0x0092 },
141 { .vid = 0x138a, .pid = 0x0094 },
142 { .vid = 0x138a, .pid = 0x0097 },
143 { .vid = 0x138a, .pid = 0x009d },
144 { .vid = 0x138a, .pid = 0x00a6 },
145 { .vid = 0x138a, .pid = 0x00ab },
146 { .vid = 0x147e, .pid = 0x1002 },
147 { .vid = 0x1491, .pid = 0x0088 },
148 { .vid = 0x16d1, .pid = 0x1027 },
149 { .vid = 0x1c7a, .pid = 0x0300 },
150 { .vid = 0x1c7a, .pid = 0x0575 },
151 { .vid = 0x1c7a, .pid = 0x0576 },
152 { .vid = 0x1c7a, .pid = 0x0577 },
153 { .vid = 0x1c7a, .pid = 0x057e },
154 { .vid = 0x1c7a, .pid = 0x05a5 },
155 { .vid = 0x1c7a, .pid = 0x05aa },
156 { .vid = 0x1c7a, .pid = 0x0801 },
157 { .vid = 0x2541, .pid = 0x0236 },
158 { .vid = 0x2541, .pid = 0x9711 },
159 { .vid = 0x27c6, .pid = 0x5042 },
160 { .vid = 0x27c6, .pid = 0x5110 },
161 { .vid = 0x27c6, .pid = 0x5117 },
162 { .vid = 0x27c6, .pid = 0x5120 },
163 { .vid = 0x27c6, .pid = 0x5125 },
164 { .vid = 0x27c6, .pid = 0x5201 },
165 { .vid = 0x27c6, .pid = 0x521d },
166 { .vid = 0x27c6, .pid = 0x5301 },
167 { .vid = 0x27c6, .pid = 0x530c },
168 { .vid = 0x27c6, .pid = 0x532d },
169 { .vid = 0x27c6, .pid = 0x5335 },
170 { .vid = 0x27c6, .pid = 0x533c },
171 { .vid = 0x27c6, .pid = 0x5381 },
172 { .vid = 0x27c6, .pid = 0x5385 },
173 { .vid = 0x27c6, .pid = 0x538c },
174 { .vid = 0x27c6, .pid = 0x538d },
175 { .vid = 0x27c6, .pid = 0x5395 },
176 { .vid = 0x27c6, .pid = 0x5503 },
177 { .vid = 0x27c6, .pid = 0x550a },
178 { .vid = 0x27c6, .pid = 0x550c },
179 { .vid = 0x27c6, .pid = 0x5584 },
180 { .vid = 0x27c6, .pid = 0x55a2 },
181 { .vid = 0x27c6, .pid = 0x55a4 },
182 { .vid = 0x27c6, .pid = 0x55b4 },
183 { .vid = 0x27c6, .pid = 0x5740 },
184 { .vid = 0x27c6, .pid = 0x581a },
185 { .vid = 0x27c6, .pid = 0x589a },
186 { .vid = 0x27c6, .pid = 0x5e0a },
187 { .vid = 0x27c6, .pid = 0x5f10 },
188 { .vid = 0x27c6, .pid = 0x5f91 },
189 { .vid = 0x2808, .pid = 0x06fc },
190 { .vid = 0x2808, .pid = 0x6652 },
191 { .vid = 0x2808, .pid = 0x9338 },
192 { .vid = 0x2808, .pid = 0x9348 },
193 { .vid = 0x2808, .pid = 0x93a9 },
194 { .vid = 0x2808, .pid = 0xa553 },
195 { .vid = 0x2808, .pid = 0xa573 },
196 { .vid = 0x2808, .pid = 0xa658 },
197 { .vid = 0x2808, .pid = 0xc652 },
198 { .vid = 0x298d, .pid = 0x2033 },
199 { .vid = 0x2df0, .pid = 0x0003 },
200 { .vid = 0x3274, .pid = 0x9008 },
201 { .vid = 0x3274, .pid = 0xb012 },
202 { .vid = 0x33a7, .pid = 0x2388 },
203 { .vid = 0x3538, .pid = 0x0930 },
204 /* --- END GENERATED IDS --- */
205 { .vid = 0 },
206 };
207
208 static const FpIdEntry denylist_id_table[] = {
209 { .vid = 0x0483, .pid = 0x2016 },
210 /* https://bugs.freedesktop.org/show_bug.cgi?id=66659 */
211 { .vid = 0x045e, .pid = 0x00bb },
212 { .vid = 0 },
213 };
214
215 static const FpDeviceClass allowlist = {
216 .type = FP_DEVICE_TYPE_USB,
217 .id_table = allowlist_id_table,
218 .id = "allowlist",
219 .full_name = "Hardcoded allowlist"
220 };
221
222 GHashTable *printed = NULL;
223
224 static void
225 33 print_driver (const FpDeviceClass *cls)
226 {
227 33 const FpIdEntry *entry;
228 33 gint num_printed = 0;
229
230
1/2
✓ Branch 2 → 3 taken 33 times.
✗ Branch 2 → 30 not taken.
33 if (cls->type != FP_DEVICE_TYPE_USB)
231 return;
232
233
2/2
✓ Branch 26 → 7 taken 431 times.
✓ Branch 26 → 27 taken 33 times.
464 for (entry = cls->id_table; entry->vid != 0; entry++)
234 {
235 const FpIdEntry *bl_entry;
236 char *key;
237
238
2/2
✓ Branch 7 → 4 taken 860 times.
✓ Branch 7 → 8 taken 428 times.
1288 for (bl_entry = denylist_id_table; bl_entry->vid != 0; bl_entry++)
239
4/4
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 851 times.
✓ Branch 5 → 6 taken 6 times.
✓ Branch 5 → 8 taken 3 times.
860 if (entry->vid == bl_entry->vid && entry->pid == bl_entry->pid)
240 break;
241
242
2/2
✓ Branch 8 → 9 taken 3 times.
✓ Branch 8 → 10 taken 428 times.
431 if (bl_entry->vid != 0)
243 3 continue;
244
245 428 key = g_strdup_printf ("%04x:%04x", entry->vid, entry->pid);
246
247
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 18 taken 427 times.
428 if (g_hash_table_lookup (printed, key) != NULL)
248 {
249
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 1 time.
1 if (cls == &allowlist)
250 g_warning ("%s implemented by driver %s",
251 key, (const char *) g_hash_table_lookup (printed, key));
252 1 g_free (key);
253 1 continue;
254 }
255
256 427 g_hash_table_insert (printed, key, (void *) cls->id);
257
258
2/2
✓ Branch 19 → 20 taken 32 times.
✓ Branch 19 → 23 taken 395 times.
427 if (num_printed == 0)
259 {
260
2/2
✓ Branch 20 → 21 taken 31 times.
✓ Branch 20 → 22 taken 1 time.
32 if (cls != &allowlist)
261 31 g_print ("\n# Supported by libfprint driver %s\n", cls->id);
262 else
263 1 g_print ("\n# Known unsupported devices\n");
264 }
265
266 427 g_print ("usb:v%04Xp%04X*\n",
267 427 entry->vid, entry->pid);
268 427 num_printed++;
269 }
270
271
2/2
✓ Branch 27 → 28 taken 32 times.
✓ Branch 27 → 30 taken 1 time.
33 if (num_printed > 0)
272 {
273 32 g_print (" ID_AUTOSUSPEND=1\n");
274 32 g_print (" ID_PERSIST=0\n");
275 }
276 }
277
278 static int
279 138 driver_compare (gconstpointer p1, gconstpointer p2)
280 {
281 138 g_autoptr(FpDeviceClass) cls1 = g_type_class_ref (*(GType *) p1);
282 276 g_autoptr(FpDeviceClass) cls2 = g_type_class_ref (*(GType *) p2);
283
284 138 return g_strcmp0 (cls1->id, cls2->id);
285 }
286
287 int
288 1 main (int argc, char **argv)
289 {
290 1 g_autoptr(GArray) drivers = fpi_get_driver_types ();
291 1 g_autofree char *program_name = NULL;
292 1 guint i;
293
294 1 program_name = g_path_get_basename (argv[0]);
295
296 1 g_print ("# SPDX-License-Identifier: LGPL-2.1-or-later\n");
297 1 g_print ("# This file has been generated using %s with all drivers enabled\n",
298 program_name);
299
300 1 printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
301 1 g_array_sort (drivers, driver_compare);
302
303
2/2
✓ Branch 15 → 9 taken 36 times.
✓ Branch 15 → 16 taken 1 time.
38 for (i = 0; i < drivers->len; i++)
304 {
305 36 GType driver = g_array_index (drivers, GType, i);
306 72 g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver);
307
308
2/2
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 12 taken 32 times.
36 if (cls->type != FP_DEVICE_TYPE_USB)
309 4 continue;
310
311 32 print_driver (cls);
312 }
313
314 1 print_driver (&allowlist);
315
316 1 g_hash_table_destroy (printed);
317
318 1 return 0;
319 }
320