// 指定日志级别printk(KERN_EMERG "System is unusable\n");printk(KERN_ALERT "Action must be taken immediately\n");printk(KERN_CRIT "Critical conditions\n");printk(KERN_ERR "Error conditions\n");printk(KERN_WARNING "Warning conditions\n");printk(KERN_NOTICE "Normal but significant condition\n");printk(KERN_INFO "Informational\n");printk(KERN_DEBUG "Debug-level messages\n");// 简写形式(推荐)pr_emerg("System is unusable\n");pr_alert("Action must be taken immediately\n");pr_crit("Critical conditions\n");pr_err("Error conditions\n");pr_warn("Warning conditions\n");pr_notice("Normal but significant condition\n");pr_info("Informational\n");pr_debug("Debug-level messages\n");
// 自定义调试宏#defineMY_DEBUG1#ifMY_DEBUG#definemy_debug(fmt,...)\printk(KERN_DEBUG "%s:%d: "fmt,__func__,__LINE__,##__VA_ARGS__)#else#definemy_debug(fmt,...)#endif// 错误处理包装intmy_function(void*data){if(!data){pr_err("NULL pointer passed to %s\n",__func__);return-EINVAL;}my_debug("Processing data at %p\n", data);// ... 函数逻辑return0;}