Search code examples
linux-kernelgcc-warninggcc4.9

Compiler error, with 3.0.101 kernel using gcc 4.9


Here is the error

fs/fat/dir.c: In function 'fat_dir_empty': fs/fat/dir.c:124:8: warning: 'de' may be used uninitialized in this function [-Wmaybe-uninitialized] error, forbidden warning: 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)++; is the issue

I don't understand, 3.4 with same coding compiles just fine. Any help with this would be appreciated.

UPDATE: After reading, http://lwn.net/Articles/529954/ I was running with -O3 optimization, which effects -Wmaybe-uninitialized

UPDATE 2: vfat builds as a module, no problem. Only have issue as a built-in. I wonder why that would be?


Solution

  • Patch from Code Aurora Forum fixes this.

    From: David Brown Date: Sun, 10 Oct 2010 23:34:20 -0700 Subject: [PATCH] FAT: Fix warning

    fs/fat/dir.c:43: warning: 'de' may be used uninitialized in this function

    The complexity of the code flow makes this seem possible. Initialize the value to NULL to eliminate the compiler warning. This only masks the warning, since if the value were unused, there would still be a NULL pointer.

    Change-Id: I9fc36abace09409853b63e0997328b75ce703769
    Signed-off-by: David Brown <[email protected]>
    ---
     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