官术网_书友最值得收藏!

How it works...

If we look carefully at the preceding printing functions (pr_info() and similar functions), we notice that they also depend on the pr_fmt(fmt) parameter, which can be used to add other useful information into our message. For instance, the following definition alters all messages generated by pr_info() by adding the current module and calling function names:

#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
Note that the pr_fmt() macro definition must appear at the start of the file, even before the includes, to have any effect.

If we add this line to our dummy-code.c, as shown in the following code block, the kernel messages will change as described:

/*
* Dummy code
*/

#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
#include <linux/module.h>

In fact, when the pr_info() function is executed the output message, telling us that the module has been inserted turns in the following form, where we can see the module name and the calling function name followed by the loading message:

dummy_code:dummy_code_init: dummy-code loaded

There is another set of printing functions but, before starting to talk about them, we need some information that is located in Chapter 3, Using the Device Tree, so, for the moment, we'll continue using these functions only.

主站蜘蛛池模板: 台中县| 江达县| 汾西县| 颍上县| 曲水县| 汝州市| 温泉县| 阳信县| 神木县| 都昌县| 皋兰县| 屏东市| 伊金霍洛旗| 鸡东县| 达州市| 阿克陶县| 弋阳县| 鄂州市| 自治县| 乐昌市| 屏山县| 察隅县| 区。| 高碑店市| 松溪县| 日照市| 长乐市| 故城县| 北海市| 永丰县| 辽宁省| 赞皇县| 西吉县| 雅安市| 牡丹江市| 寻甸| 清涧县| 荥阳市| 仁布县| 乐平市| 嵩明县|