t0080: mark as leak-free
[alt-git.git] / userdiff.c
blobe399543823bdf2c0c8f24fb87f7622ac4d8a366b
1 #include "git-compat-util.h"
2 #include "config.h"
3 #include "userdiff.h"
4 #include "attr.h"
5 #include "strbuf.h"
7 static struct userdiff_driver *drivers;
8 static int ndrivers;
9 static int drivers_alloc;
11 #define PATTERNS(lang, rx, wrx) { \
12 .name = lang, \
13 .binary = -1, \
14 .funcname = { \
15 .pattern = rx, \
16 .cflags = REG_EXTENDED, \
17 }, \
18 .word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
19 .word_regex_multi_byte = wrx "|[^[:space:]]", \
21 #define IPATTERN(lang, rx, wrx) { \
22 .name = lang, \
23 .binary = -1, \
24 .funcname = { \
25 .pattern = rx, \
26 .cflags = REG_EXTENDED | REG_ICASE, \
27 }, \
28 .word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
29 .word_regex_multi_byte = wrx "|[^[:space:]]", \
33 * Built-in drivers for various languages, sorted by their names
34 * (except that the "default" is left at the end).
36 * When writing or updating patterns, assume that the contents these
37 * patterns are applied to are syntactically correct. The patterns
38 * can be simple without implementing all syntactical corner cases, as
39 * long as they are sufficiently permissive.
41 static struct userdiff_driver builtin_drivers[] = {
42 IPATTERN("ada",
43 "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"
44 "!^[ \t]*with[ \t].*$\n"
45 "^[ \t]*((procedure|function)[ \t]+.*)$\n"
46 "^[ \t]*((package|protected|task)[ \t]+.*)$",
47 /* -- */
48 "[a-zA-Z][a-zA-Z0-9_]*"
49 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
50 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
51 PATTERNS("bash",
52 /* Optional leading indentation */
53 "^[ \t]*"
54 /* Start of captured text */
55 "("
56 "("
57 /* POSIX identifier with mandatory parentheses */
58 "[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))"
59 "|"
60 /* Bashism identifier with optional parentheses */
61 "(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))"
62 ")"
63 /* Optional whitespace */
64 "[ \t]*"
65 /* Compound command starting with `{`, `(`, `((` or `[[` */
66 "(\\{|\\(\\(?|\\[\\[)"
67 /* End of captured text */
68 ")",
69 /* -- */
70 /* Characters not in the default $IFS value */
71 "[^ \t]+"),
72 PATTERNS("bibtex",
73 "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
74 /* -- */
75 "[={}\"]|[^={}\" \t]+"),
76 PATTERNS("cpp",
77 /* Jump targets or access declarations */
78 "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])\n"
79 /* functions/methods, variables, and compounds at top level */
80 "^((::[[:space:]]*)?[A-Za-z_].*)$",
81 /* -- */
82 /* identifiers and keywords */
83 "[a-zA-Z_][a-zA-Z0-9_]*"
84 /* decimal and octal integers as well as floatingpoint numbers */
85 "|[0-9][0-9.]*([Ee][-+]?[0-9]+)?[fFlLuU]*"
86 /* hexadecimal and binary integers */
87 "|0[xXbB][0-9a-fA-F]+[lLuU]*"
88 /* floatingpoint numbers that begin with a decimal point */
89 "|\\.[0-9][0-9]*([Ee][-+]?[0-9]+)?[fFlL]?"
90 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->\\*?|\\.\\*|<=>"),
91 PATTERNS("csharp",
92 /* Keywords */
93 "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
94 /* Methods and constructors */
95 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe|async)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n"
96 /* Properties */
97 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n"
98 /* Type definitions */
99 "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct|record)[ \t]+.*)$\n"
100 /* Namespace */
101 "^[ \t]*(namespace[ \t]+.*)$",
102 /* -- */
103 "[a-zA-Z_][a-zA-Z0-9_]*"
104 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
105 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
106 IPATTERN("css",
107 "![:;][[:space:]]*$\n"
108 "^[:[@.#]?[_a-z0-9].*$",
109 /* -- */
111 * This regex comes from W3C CSS specs. Should theoretically also
112 * allow ISO 10646 characters U+00A0 and higher,
113 * but they are not handled in this regex.
115 "-?[_a-zA-Z][-_a-zA-Z0-9]*" /* identifiers */
116 "|-?[0-9]+|\\#[0-9a-fA-F]+" /* numbers */
118 PATTERNS("dts",
119 "!;\n"
120 "!=\n"
121 /* lines beginning with a word optionally preceded by '&' or the root */
122 "^[ \t]*((/[ \t]*\\{|&?[a-zA-Z_]).*)",
123 /* -- */
124 /* Property names and math operators */
125 "[a-zA-Z0-9,._+?#-]+"
126 "|[-+*/%&^|!~]|>>|<<|&&|\\|\\|"),
127 PATTERNS("elixir",
128 "^[ \t]*((def(macro|module|impl|protocol|p)?|test)[ \t].*)$",
129 /* -- */
130 /* Atoms, names, and module attributes */
131 "[@:]?[a-zA-Z0-9@_?!]+"
132 /* Numbers with specific base */
133 "|[-+]?0[xob][0-9a-fA-F]+"
134 /* Numbers */
135 "|[-+]?[0-9][0-9_.]*([eE][-+]?[0-9_]+)?"
136 /* Operators and atoms that represent them */
137 "|:?(\\+\\+|--|\\.\\.|~~~|<>|\\^\\^\\^|<?\\|>|<<<?|>?>>|<<?~|~>?>|<~>|<=|>=|===?|!==?|=~|&&&?|\\|\\|\\|?|=>|<-|\\\\\\\\|->)"
138 /* Not real operators, but should be grouped */
139 "|:?%[A-Za-z0-9_.]\\{\\}?"),
140 IPATTERN("fortran",
141 /* Don't match comment lines */
142 "!^([C*]|[ \t]*!)\n"
143 /* Don't match 'module procedure' lines */
144 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
145 /* Program, module, block data */
146 "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
147 /* Subroutines and functions */
148 "|([^!'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
149 /* -- */
150 "[a-zA-Z][a-zA-Z0-9_]*"
151 "|\\.([Ee][Qq]|[Nn][Ee]|[Gg][TtEe]|[Ll][TtEe]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Aa][Nn][Dd]|[Oo][Rr]|[Nn]?[Ee][Qq][Vv]|[Nn][Oo][Tt])\\."
152 /* numbers and format statements like 2E14.4, or ES12.6, 9X.
153 * Don't worry about format statements without leading digits since
154 * they would have been matched above as a variable anyway. */
155 "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?"
156 "|//|\\*\\*|::|[/<>=]="),
157 IPATTERN("fountain",
158 "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
159 /* -- */
160 "[^ \t-]+"),
161 PATTERNS("golang",
162 /* Functions */
163 "^[ \t]*(func[ \t]*.*(\\{[ \t]*)?)\n"
164 /* Structs and interfaces */
165 "^[ \t]*(type[ \t].*(struct|interface)[ \t]*(\\{[ \t]*)?)",
166 /* -- */
167 "[a-zA-Z_][a-zA-Z0-9_]*"
168 "|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?"
169 "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&\\^=?|&&|\\|\\||<-|\\.{3}"),
170 PATTERNS("html",
171 "^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
172 /* -- */
173 "[^<>= \t]+"),
174 PATTERNS("java",
175 "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
176 /* Class, enum, interface, and record declarations */
177 "^[ \t]*(([a-z-]+[ \t]+)*(class|enum|interface|record)[ \t]+.*)$\n"
178 /* Method definitions; note that constructor signatures are not */
179 /* matched because they are indistinguishable from method calls. */
180 "^[ \t]*(([A-Za-z_<>&][][?&<>.,A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",
181 /* -- */
182 "[a-zA-Z_][a-zA-Z0-9_]*"
183 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
184 "|[-+*/<>%&^|=!]="
185 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
186 PATTERNS("kotlin",
187 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
188 /* -- */
189 "[a-zA-Z_][a-zA-Z0-9_]*"
190 /* hexadecimal and binary numbers */
191 "|0[xXbB][0-9a-fA-F_]+[lLuU]*"
192 /* integers and floats */
193 "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
194 /* floating point numbers beginning with decimal point */
195 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
196 /* unary and binary operators */
197 "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
198 PATTERNS("markdown",
199 "^ {0,3}#{1,6}[ \t].*",
200 /* -- */
201 "[^<>= \t]+"),
202 PATTERNS("matlab",
204 * Octave pattern is mostly the same as matlab, except that '%%%' and
205 * '##' can also be used to begin code sections, in addition to '%%'
206 * that is understood by both.
208 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
209 /* -- */
210 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
211 PATTERNS("objc",
212 /* Negate C statements that can look like functions */
213 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
214 /* Objective-C methods */
215 "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n"
216 /* C functions */
217 "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$\n"
218 /* Objective-C class/protocol definitions */
219 "^(@(implementation|interface|protocol)[ \t].*)$",
220 /* -- */
221 "[a-zA-Z_][a-zA-Z0-9_]*"
222 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
223 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
224 PATTERNS("pascal",
225 "^(((class[ \t]+)?(procedure|function)|constructor|destructor|interface"
226 "|implementation|initialization|finalization)[ \t]*.*)$\n"
227 "^(.*=[ \t]*(class|record).*)$",
228 /* -- */
229 "[a-zA-Z_][a-zA-Z0-9_]*"
230 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
231 "|<>|<=|>=|:=|\\.\\."),
232 PATTERNS("perl",
233 "^package .*\n"
234 "^sub [[:alnum:]_':]+[ \t]*"
235 "(\\([^)]*\\)[ \t]*)?" /* prototype */
237 * Attributes. A regex can't count nested parentheses,
238 * so just slurp up whatever we see, taking care not
239 * to accept lines like "sub foo; # defined elsewhere".
241 * An attribute could contain a semicolon, but at that
242 * point it seems reasonable enough to give up.
244 "(:[^;#]*)?"
245 "(\\{[ \t]*)?" /* brace can come here or on the next line */
246 "(#.*)?$\n" /* comment */
247 "^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*"
248 "(\\{[ \t]*)?" /* brace can come here or on the next line */
249 "(#.*)?$\n"
250 "^=head[0-9] .*", /* POD */
251 /* -- */
252 "[[:alpha:]_'][[:alnum:]_']*"
253 "|0[xb]?[0-9a-fA-F_]*"
254 /* taking care not to interpret 3..5 as (3.)(.5) */
255 "|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?"
256 "|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::"
257 "|&&=|\\|\\|=|//=|\\*\\*="
258 "|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?"
259 "|[-+*/%.^&<>=!|]="
260 "|=~|!~"
261 "|<<|<>|<=>|>>"),
262 PATTERNS("php",
263 "^[\t ]*(((public|protected|private|static|abstract|final)[\t ]+)*function.*)$\n"
264 "^[\t ]*((((final|abstract)[\t ]+)?class|enum|interface|trait).*)$",
265 /* -- */
266 "[a-zA-Z_][a-zA-Z0-9_]*"
267 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
268 "|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"),
269 PATTERNS("python",
270 "^[ \t]*((class|(async[ \t]+)?def)[ \t].*)$",
271 /* -- */
272 "[a-zA-Z_][a-zA-Z0-9_]*"
273 "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
274 "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
275 /* -- */
276 PATTERNS("ruby",
277 "^[ \t]*((class|module|def)[ \t].*)$",
278 /* -- */
279 "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
280 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
281 "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
282 PATTERNS("rust",
283 "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \t]+[^;]*)$",
284 /* -- */
285 "[a-zA-Z_][a-zA-Z0-9_]*"
286 "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"
287 "|[-+*\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\|\\||->|=>|\\.{2}=|\\.{3}|::"),
288 PATTERNS("scheme",
289 "^[\t ]*(\\(((define|def(struct|syntax|class|method|rules|record|proto|alias)?)[-*/ \t]|(library|module|struct|class)[*+ \t]).*)$",
291 * R7RS valid identifiers include any sequence enclosed
292 * within vertical lines having no backslashes
294 "\\|([^\\\\]*)\\|"
295 /* All other words should be delimited by spaces or parentheses */
296 "|([^][)(}{[ \t])+"),
297 PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
298 "\\\\[a-zA-Z@]+|\\\\.|([a-zA-Z0-9]|[^\x01-\x7f])+"),
299 { "default", NULL, NULL, -1, { NULL, 0 } },
301 #undef PATTERNS
302 #undef IPATTERN
304 static struct userdiff_driver driver_true = {
305 .name = "diff=true",
306 .binary = 0,
309 static struct userdiff_driver driver_false = {
310 .name = "!diff",
311 .binary = 1,
314 struct find_by_namelen_data {
315 const char *name;
316 size_t len;
317 struct userdiff_driver *driver;
320 static int userdiff_find_by_namelen_cb(struct userdiff_driver *driver,
321 enum userdiff_driver_type type UNUSED,
322 void *priv)
324 struct find_by_namelen_data *cb_data = priv;
326 if (!strncmp(driver->name, cb_data->name, cb_data->len) &&
327 !driver->name[cb_data->len]) {
328 cb_data->driver = driver;
329 return 1; /* tell the caller to stop iterating */
331 return 0;
334 static int regexec_supports_multi_byte_chars(void)
336 static const char not_space[] = "[^[:space:]]";
337 static const char utf8_multi_byte_char[] = "\xc2\xa3";
338 regex_t re;
339 regmatch_t match;
340 static int result = -1;
342 if (result != -1)
343 return result;
344 if (regcomp(&re, not_space, REG_EXTENDED))
345 BUG("invalid regular expression: %s", not_space);
346 result = !regexec(&re, utf8_multi_byte_char, 1, &match, 0) &&
347 match.rm_so == 0 &&
348 match.rm_eo == strlen(utf8_multi_byte_char);
349 regfree(&re);
350 return result;
353 static struct userdiff_driver *userdiff_find_by_namelen(const char *name, size_t len)
355 struct find_by_namelen_data udcbdata = {
356 .name = name,
357 .len = len,
359 for_each_userdiff_driver(userdiff_find_by_namelen_cb, &udcbdata);
360 return udcbdata.driver;
363 static int parse_funcname(struct userdiff_funcname *f, const char *k,
364 const char *v, int cflags)
366 if (git_config_string(&f->pattern, k, v) < 0)
367 return -1;
368 f->cflags = cflags;
369 return 0;
372 static int parse_tristate(int *b, const char *k, const char *v)
374 if (v && !strcasecmp(v, "auto"))
375 *b = -1;
376 else
377 *b = git_config_bool(k, v);
378 return 0;
381 static int parse_bool(int *b, const char *k, const char *v)
383 *b = git_config_bool(k, v);
384 return 0;
387 int userdiff_config(const char *k, const char *v)
389 struct userdiff_driver *drv;
390 const char *name, *type;
391 size_t namelen;
393 if (parse_config_key(k, "diff", &name, &namelen, &type) || !name)
394 return 0;
396 drv = userdiff_find_by_namelen(name, namelen);
397 if (!drv) {
398 ALLOC_GROW(drivers, ndrivers+1, drivers_alloc);
399 drv = &drivers[ndrivers++];
400 memset(drv, 0, sizeof(*drv));
401 drv->name = xmemdupz(name, namelen);
402 drv->binary = -1;
405 if (!strcmp(type, "funcname"))
406 return parse_funcname(&drv->funcname, k, v, 0);
407 if (!strcmp(type, "xfuncname"))
408 return parse_funcname(&drv->funcname, k, v, REG_EXTENDED);
409 if (!strcmp(type, "binary"))
410 return parse_tristate(&drv->binary, k, v);
411 if (!strcmp(type, "command"))
412 return git_config_string(&drv->external, k, v);
413 if (!strcmp(type, "textconv"))
414 return git_config_string(&drv->textconv, k, v);
415 if (!strcmp(type, "cachetextconv"))
416 return parse_bool(&drv->textconv_want_cache, k, v);
417 if (!strcmp(type, "wordregex"))
418 return git_config_string(&drv->word_regex, k, v);
419 if (!strcmp(type, "algorithm"))
420 return git_config_string(&drv->algorithm, k, v);
422 return 0;
425 struct userdiff_driver *userdiff_find_by_name(const char *name)
427 int len = strlen(name);
428 struct userdiff_driver *driver = userdiff_find_by_namelen(name, len);
429 if (driver && driver->word_regex_multi_byte) {
430 if (regexec_supports_multi_byte_chars())
431 driver->word_regex = driver->word_regex_multi_byte;
432 driver->word_regex_multi_byte = NULL;
434 return driver;
437 struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
438 const char *path)
440 static struct attr_check *check;
442 if (!check)
443 check = attr_check_initl("diff", NULL);
444 if (!path)
445 return NULL;
446 git_check_attr(istate, path, check);
448 if (ATTR_TRUE(check->items[0].value))
449 return &driver_true;
450 if (ATTR_FALSE(check->items[0].value))
451 return &driver_false;
452 if (ATTR_UNSET(check->items[0].value))
453 return NULL;
454 return userdiff_find_by_name(check->items[0].value);
457 struct userdiff_driver *userdiff_get_textconv(struct repository *r,
458 struct userdiff_driver *driver)
460 if (!driver->textconv)
461 return NULL;
463 if (driver->textconv_want_cache && !driver->textconv_cache) {
464 struct notes_cache *c = xmalloc(sizeof(*c));
465 struct strbuf name = STRBUF_INIT;
467 strbuf_addf(&name, "textconv/%s", driver->name);
468 notes_cache_init(r, c, name.buf, driver->textconv);
469 driver->textconv_cache = c;
470 strbuf_release(&name);
473 return driver;
476 static int for_each_userdiff_driver_list(each_userdiff_driver_fn fn,
477 enum userdiff_driver_type type, void *cb_data,
478 struct userdiff_driver *drv,
479 int drv_size)
481 int i;
482 int ret;
483 for (i = 0; i < drv_size; i++) {
484 struct userdiff_driver *item = drv + i;
485 if ((ret = fn(item, type, cb_data)))
486 return ret;
488 return 0;
491 int for_each_userdiff_driver(each_userdiff_driver_fn fn, void *cb_data)
493 int ret;
495 ret = for_each_userdiff_driver_list(fn, USERDIFF_DRIVER_TYPE_CUSTOM,
496 cb_data, drivers, ndrivers);
497 if (ret)
498 return ret;
500 ret = for_each_userdiff_driver_list(fn, USERDIFF_DRIVER_TYPE_BUILTIN,
501 cb_data, builtin_drivers,
502 ARRAY_SIZE(builtin_drivers));
503 if (ret)
504 return ret;
506 return 0;