shmem: avoid maybe-uninitialized warning
Subsystems (2)
PATCH v2 1/1 shmem: avoid maybe-uninitialized warning
After enabling -Wmaybe-uninitialized warnings, we get a false-postive warning for shmem:
mm/shmem.c: In function a??shmem_getpage_gfpa??:include/linux/spinlock.h:332:21: error: a??infoa?? may be used uninitialized in this function [-Werror=maybe-uninitialized]
This can be easily avoided, since the correct 'info' pointer is known at the time we first enter the function, so we can simply move the initialization up. Moving it before the first label avoids the warning and lets us remove two later initializations.
Note that the function is so hard to read that it not only confuses the compiler, but also most readers and without this patch it could\
easily break if one of the 'goto's changed.
--- mm/shmem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mm/shmem.c +1 -3
@@ -1537,7 +1537,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, struct mm_struct *fault_mm, int *fault_type) { struct address_space *mapping = inode->i_mapping; -struct shmem_inode_info *info; +struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo;struct mm_struct *charge_mm;struct mem_cgroup *memcg;
@@ -1587,7 +1587,6 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,* Fast cache lookup did not find it: * bring it back from swap or allocate. */ - info =SHMEM_I (inode); sbinfo =SHMEM_SB (inode->i_sb); charge_mm = fault_mm ? : current->mm;
@@ -1835,7 +1834,6 @@ alloc_nohuge: page = shmem_alloc_and_acct_page(gfp, info, sbinfo,put_page (page); }if (error == -ENOSPC && !once++) { - info =SHMEM_I (inode);spin_lock_irq (&info->lock);shmem_recalc_inode (inode);spin_unlock_irq (&info->lock);
Signature · 7 lines
2.9.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Arnd Bergmann
After enabling -Wmaybe-uninitialized warnings, we get a false-postive warning for shmem:
mm/shmem.c: In function a??shmem_getpage_gfpa??:include/linux/spinlock.h:332:21: error: a??infoa?? may be used uninitialized in this function [-Werror=maybe-uninitialized]This can be easily avoided, since the correct 'info' pointer is known at the time we first enter the function, so we can simply move the initialization up. Moving it before the first label avoids the warning and lets us remove two later initializations.
Quoted 7 lines
Note that the function is so hard to read that it not only confuses the compiler, but also most readers and without this patch it could\
easily break if one of the 'goto's changed.
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Arnd Bergmann
After enabling -Wmaybe-uninitialized warnings, we get a false-postive warning for shmem:
mm/shmem.c: In function a??shmem_getpage_gfpa??:include/linux/spinlock.h:332:21: error: a??infoa?? may be used uninitialized in this function [-Werror=maybe-uninitialized]This can be easily avoided, since the correct 'info' pointer is known at the time we first enter the function, so we can simply move the initialization up. Moving it before the first label avoids the warning and lets us remove two later initializations.
Quoted 7 lines
Note that the function is so hard to read that it not only confuses the compiler, but also most readers and without this patch it could\
easily break if one of the 'goto's changed.
Quoted 27 lines
--- mm/shmem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)mm/shmem.c +1
-2@@ -1537,7 +1537,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, struct mm_struct *fault_mm, int *fault_type) { struct address_space *mapping = inode->i_mapping; -struct shmem_inode_info *info; +struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo;struct mm_struct *charge_mm;struct mem_cgroup *memcg;@@ -1587,7 +1587,6 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,* Fast cache lookup did not find it: * bring it back from swap or allocate. */ - info =SHMEM_I (inode); sbinfo =SHMEM_SB (inode->i_sb); charge_mm = fault_mm ? : current->mm;
mm/shmem.c alloc_nohuge: page = shmem_alloc_and_acct_page(gfp, info, sbinfo, · line 1839
Quoted 7 lines
mm/shmem.c +0
-1@@ -1835,7 +1834,6 @@ alloc_nohuge: page = shmem_alloc_and_acct_page(gfp, info, sbinfo,put_page (page); }if (error == -ENOSPC && !once++) { - info =SHMEM_I (inode);spin_lock_irq (&info->lock);shmem_recalc_inode (inode);spin_unlock_irq (&info->lock);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>