- 1. misleading-indentation
259 if (ret < 0)
260 return ret;
261
262 printk(KERN_ERR"%X\n", reg_val);
259:10: error: this ‘if’ clause does not guard... [-Werror=misleading-indentation]
if (ret < 0)
^~262:4: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
printk(KERN_ERR"%X\n", reg_val);
^~~~~~error表示if 是否也包含printk, 將prink和if對齊解決此問題。
- 2. unused-result
1011 sysfs_create_group(&client->dev.kobj, &mt5715_sysfs_group);
1012
1011:5: error: ignoring return value of ‘sysfs_create_group’, declared with attribute warn_unused_result [-Werror=unused-result]
sysfs_create_group(&client->dev.kobj, &mt5715_sysfs_group);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~報錯沒有使用返回值,修改rc = sysfs_create_group(&client->dev.kobj, &mt5715_sysfs_group);解決報錯。
- 3. 1format=
62 #define LOG_INF(fmt, args...) pr_debug(PFX "[%s] " fmt, __func__, ##args)
730 static void capture_setting(kal_uint16 currefps)
731 {
732 LOG_INF("E! currefps:%d\n");
784 static void normal_video_setting(kal_uint16 currefps)
785 {
786 LOG_INF("E! currefps:%d\n");
In function ‘capture_setting’:
kernel-4.4/include/linux/printk.h:33:23: error: format ‘%d’ expects a matching ‘int’ argument [-Werror=format=]#define KLOG_MODNAME ""
^
kernel-4.4/include/linux/printk.h:264:21: note: in definition of macro ‘pr_fmt’
#define pr_fmt(fmt) fmt^~~
kernel-4.4/include/linux/printk.h:422:2: note: in expansion of macro ‘dynamic_pr_debug’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~~~~~kernel-4.4/include/linux/printk.h:422:19: note: in expansion of macro ‘KLOG_MODNAME’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~62:31: note: in expansion of macro ‘pr_debug’
#define LOG_INF(fmt, args...) pr_debug(PFX "[%s] " fmt, __func__, ##args)
^~~~~~~~732:2: note: in expansion of macro ‘LOG_INF’
LOG_INF("E! currefps:%d\n");
^~~~~~~In function ‘normal_video_setting’:
kernel-4.4/include/linux/printk.h:33:23: error: format ‘%d’ expects a matching ‘int’ argument [-Werror=format=]
#define KLOG_MODNAME ""
^kernel-4.4/include/linux/printk.h:264:21: note: in definition of macro ‘pr_fmt’
#define pr_fmt(fmt) fmt
^~~kernel-4.4/include/linux/printk.h:422:2: note: in expansion of macro ‘dynamic_pr_debug’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~~~~~kernel-4.4/include/linux/printk.h:422:19: note: in expansion of macro ‘KLOG_MODNAME’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~62:31: note: in expansion of macro ‘pr_debug’
#define LOG_INF(fmt, args...) pr_debug(PFX "[%s] " fmt, __func__, ##args)786:2: note: in expansion of macro ‘LOG_INF’
LOG_INF("E! currefps:%d\n");^~~~~~~
第一次看到這種報錯,感覺很奇怪,printk.h也報錯。我們可以只看C文件的寫法,比如line 732, LOG_INF %d沒有帶有參數,增加打印的參數 LOG_INF("E! currefps:%d\n", currefps);解決報錯。
- 3. 2 format=
168 printk("moveAF a_u4Position=%u\n",a_u4Position); 210 LOG_INF("move [curr] %u [target] %u\n", g_u4CurrPosition, g_u4TargetPosition);
168:37: error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’ [-Werror=format=]
printk("moveAF a_u4Position=%u\n",a_u4Position);
^kernel-4.4/include/linux/printk.h:33:23: error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 4 has type ‘long unsigned int’ [-Werror=format=]
#define KLOG_MODNAME ""
^kernel-4.4/include/linux/printk.h:264:21: note: in definition of macro ‘pr_fmt’
#define pr_fmt(fmt) fmt
^~~kernel-4.4/include/linux/printk.h:422:2: note: in expansion of macro ‘dynamic_pr_debug’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~~~~~kernel-4.4/include/linux/printk.h:422:19: note: in expansion of macro ‘KLOG_MODNAME’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~kernel-4.4/drivers/misc/mediatek/lens/sub2/common/dw9718saf/DW9718SAF.c:33:34: note: in expansion of macro ‘pr_debug’
#define LOG_INF(format, args...) pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
^~~~~~~~kernel-4.4/drivers/misc/mediatek/lens/sub2/common/dw9718saf/DW9718SAF.c:210:3: note: in expansion of macro ‘LOG_INF’
LOG_INF("move [curr] %u [target] %u\n", g_u4CurrPosition, g_u4TargetPosition);
^~~~~~~kernel-4.4/include/linux/printk.h:33:23: error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 5 has type ‘long unsigned int’ [-Werror=format=]
#define KLOG_MODNAME ""
^kernel-4.4/include/linux/printk.h:264:21: note: in definition of macro ‘pr_fmt’
#define pr_fmt(fmt) fmt
^~~kernel-4.4/include/linux/printk.h:422:2: note: in expansion of macro ‘dynamic_pr_debug’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~~~~~kernel-4.4/include/linux/printk.h:422:19: note: in expansion of macro ‘KLOG_MODNAME’
dynamic_pr_debug(KLOG_MODNAME fmt, ##__VA_ARGS__)
^~~~~~~~~~~~33:34: note: in expansion of macro ‘pr_debug’
#define LOG_INF(format, args...) pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
^~~~~~~~210:3: note: in expansion of macro ‘LOG_INF’
LOG_INF("move [curr] %u [target] %u\n", g_u4CurrPosition, g_u4TargetPosition);
^~~~~~~
這裏也是報打印的格式不對, format ‘%u’ expects argument of type ‘unsigned int’, but argument 5 has type ‘long unsigned int’,也就是參數是long unsigned int,%u不匹配,修改爲%lu解決編譯報錯。
- 4. strict-prototypes
542 static unsigned int lcm_get_backlight_level()
542:21: error: function declaration isn’t a prototype [-Werror=strict-prototypes]
static unsigned int lcm_get_backlight_level()
^~~~~~~~~~~~~~~~~~~~~~~
這個錯誤是指聲明問題,但是也不知道哪裏有問題,對應看了一下 函數定義unsigned int (*backlight_level)(void);,猜測可能是函數形參沒寫導致的...,將 static unsigned int lcm_get_backlight_level()修改爲 static unsigned int lcm_get_backlight_level(void)解決報錯。