【问题标题】:Compiler error, with 3.0.101 kernel using gcc 4.9编译器错误,3.0.101 内核使用 gcc 4.9
【发布时间】:2015-01-22 23:54:08
【问题描述】:

这是错误

fs/fat/dir.c:在函数“fat_dir_empty”中: fs/fat/dir.c:124:8:警告:“de”可能在此函数中未初始化使用 [-Wmaybe-uninitialized] 错误,禁止警告:dir.c:124

static inline int fat_get_entry(struct inode *dir, loff_t *pos,
            struct buffer_head **bh,
            struct msdos_dir_entry **de)
{
/* Fast stuff first */
if (*bh && *de &&
   (*de - (struct msdos_dir_entry *)(*bh)->b_data) <
            MSDOS_SB(dir->i_sb)->dir_per_block - 1) {
    *pos += sizeof(struct msdos_dir_entry);
    (*de)++;
    return 0;
}
return fat__get_entry(dir, pos, bh, de);
}

(*de)++;是问题

我不明白,具有相同编码的 3.4 编译就好了。对此的任何帮助将不胜感激。

更新: 看完后http://lwn.net/Articles/529954/ 我正在运行 -O3 优化,这会影响 -Wmaybe-uninitialized

更新 2: vfat 作为模块构建,没问题。只有作为内置的问题。我想知道为什么会这样?

【问题讨论】:

  • 您发布了我所看到的不在 3.0.101 中的代码的摘录。修改它的补丁是 f08b4988f229f(fs/fat:修复 dir.c 中的所有其他检查补丁问题)。此外,问题不在你提到的那一行。仔细阅读编译器告诉你的内容。
  • 是的,已编辑以尝试修复。 (*de) ++;是第 124 行,这就是错误消息指向的位置?还是我错了,这一切都是新手。
  • Applied commit fat:修复构建警告,github.com/torvalds/linux/commit/… 还有 fs/fat:修复 dir.c 中的所有其他检查补丁问题,github.com/torvalds/linux/commit/…
  • 很好的补充主题lwn.net/Articles/529954
  • 有趣的是,在当前内核树中。 fs/fat/dir.c 的第 1279 行是 struct msdos_dir_entry *uninitialized_var(de);这不是 Linus 补丁,而是由 OGAWA 更改的。 lkml.org/lkml/2011/5/19/622

标签: linux-kernel gcc-warning gcc4.9


【解决方案1】:

来自 Code Aurora 论坛的补丁修复了这个问题。

发件人:大卫·布朗 日期:2010 年 10 月 10 日星期日 23:34:20 -0700 主题:[PATCH] FAT:修复警告

fs/fat/dir.c:43: 警告:“de”可能在此函数中使用未初始化

代码流的复杂性使这似乎成为可能。初始化 将值设为 NULL 以消除编译器警告。这只是掩饰 警告,因为如果该值未被使用,仍然会有 空指针。

Change-Id: I9fc36abace09409853b63e0997328b75ce703769
Signed-off-by: David Brown <davidb@codeaurora.org>
---
 fs/fat/dir.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 65e174b..409b3ce 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -343,7 +343,7 @@ int fat_search_long(struct inode *inode, const unsigned char *name,
    struct super_block *sb = inode->i_sb;
    struct msdos_sb_info *sbi = MSDOS_SB(sb);
    struct buffer_head *bh = NULL;
-   struct msdos_dir_entry *de;
+   struct msdos_dir_entry *de = NULL;
    struct nls_table *nls_disk = sbi->nls_disk;
    unsigned char nr_slots;
    wchar_t bufuname[14];
@@ -468,7 +468,7 @@ static int __fat_readdir(struct inode *inode, struct file *filp, void *dirent,
    struct super_block *sb = inode->i_sb;
    struct msdos_sb_info *sbi = MSDOS_SB(sb);
    struct buffer_head *bh;
-   struct msdos_dir_entry *de;
+   struct msdos_dir_entry *de = NULL;
    struct nls_table *nls_disk = sbi->nls_disk;
    unsigned char nr_slots;
    wchar_t bufuname[14];
@@ -887,7 +887,7 @@ EXPORT_SYMBOL_GPL(fat_get_dotdot_entry);
 int fat_dir_empty(struct inode *dir)
 {
    struct buffer_head *bh;
-   struct msdos_dir_entry *de;
+   struct msdos_dir_entry *de = NULL;
    loff_t cpos;
    int result = 0;

@@ -913,7 +913,7 @@ EXPORT_SYMBOL_GPL(fat_dir_empty);
 int fat_subdirs(struct inode *dir)
 {
    struct buffer_head *bh;
-   struct msdos_dir_entry *de;
+   struct msdos_dir_entry *de = NULL;
    loff_t cpos;
    int count = 0;

@@ -1240,7 +1240,7 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
    struct super_block *sb = dir->i_sb;
    struct msdos_sb_info *sbi = MSDOS_SB(sb);
    struct buffer_head *bh, *prev, *bhs[3]; /* 32*slots (672bytes) */
-   struct msdos_dir_entry *uninitialized_var(de);
+   struct msdos_dir_entry *de = NULL;
    int err, free_slots, i, nr_bhs;
    loff_t pos, i_pos;

-- 
2.5.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多