static inline __printf(2, 3)
int dev_err(const struct device *dev, const char *fmt, ...)
{ return 0; }
Everything there is pretty much standard (variable argument processing) except for the __printf(2,3)
This modifier to the function (similar to the static or inline modifiers) tells the compiler that it should check the format string at argument 2 (fmt
) against the actual parameters starting at argument 3, using the printf
style format specifiers.
In other words, calling it with:
dev_err (pDev, "%d", 1.0);
would flag a warning because the format string and actual arguments don’t match.
The...
simply indicates that there are a variable number of arguments coming after the format string, similar to the way printf itself is implemented. C has long had the capability to process variable argument lists, the __printf()
modifier simply gives the compiler a bit of extra information so that it can validate your use of the function.
Linux defines __printf(a, b)
as __attribute__((format(printf, a, b)))
and gcc allows that second format to specify the varargs-checking attribute as per here (paraphrased below):
format (archetype, string-index, first-to-check):
The format attribute specifies that a function takes printf, scanf, strftime or strfmon style arguments which should be type-checked against a format string. For example, the declaration:
extern int my_printf (void *my_object, const char *my_format, ...)
__attribute__ ((format (printf, 2, 3)));
causes the compiler to check the arguments in calls to my_printf for consistency with the printf style format string argument my_format.
In the example above, the format string (my_format) is the second argument of the function my_print, and the arguments to check start with the third argument, so the correct parameters for the format attribute are 2 and 3.
The format attribute allows you to identify your own functions which take format strings as arguments, so that GCC can check the calls to these functions for errors.
As to what the function itself does, not a lot other than returning zero :-)
It’s almost certainly a placeholder should you ever wish to actually implement a real dev_err() function.