All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] shmem: avoid maybe-uninitialized warning
@ 2016-10-24 20:57 ` Arnd Bergmann
  0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2016-10-24 20:57 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Arnd Bergmann, Andrew Morton, Al Viro, Kirill A. Shutemov,
	Michal Hocko, Andreas Gruenbacher, Vlastimil Babka, linux-mm,
	linux-kernel

After enabling -Wmaybe-uninitialized warnings, we get a false-postive
warning for shmem:

mm/shmem.c: In function ‘shmem_getpage_gfp’:
include/linux/spinlock.h:332:21: error: ‘info’ 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.

Link: https://www.spinics.net/lists/kernel/msg2368133.html
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 mm/shmem.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index ad7813d73ea7..95c4bb690f98 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -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);
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] shmem: avoid maybe-uninitialized warning
@ 2016-10-24 20:57 ` Arnd Bergmann
  0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2016-10-24 20:57 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Arnd Bergmann, Andrew Morton, Al Viro, Kirill A. Shutemov,
	Michal Hocko, Andreas Gruenbacher, Vlastimil Babka, linux-mm,
	linux-kernel

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.

Link: https://www.spinics.net/lists/kernel/msg2368133.html
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 mm/shmem.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index ad7813d73ea7..95c4bb690f98 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -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);
-- 
2.9.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] shmem: avoid maybe-uninitialized warning
  2016-10-24 20:57 ` Arnd Bergmann
@ 2016-10-24 23:48   ` Kirill A. Shutemov
  -1 siblings, 0 replies; 6+ messages in thread
From: Kirill A. Shutemov @ 2016-10-24 23:48 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Hugh Dickins, Andrew Morton, Al Viro, Michal Hocko,
	Andreas Gruenbacher, Vlastimil Babka, linux-mm, linux-kernel

On Mon, Oct 24, 2016 at 10:57:09PM +0200, Arnd Bergmann wrote:
> After enabling -Wmaybe-uninitialized warnings, we get a false-postive
> warning for shmem:
> 
> mm/shmem.c: In function ‘shmem_getpage_gfp’:
> include/linux/spinlock.h:332:21: error: ‘info’ 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.
> 
> Link: https://www.spinics.net/lists/kernel/msg2368133.html
> Acked-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] shmem: avoid maybe-uninitialized warning
@ 2016-10-24 23:48   ` Kirill A. Shutemov
  0 siblings, 0 replies; 6+ messages in thread
From: Kirill A. Shutemov @ 2016-10-24 23:48 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Hugh Dickins, Andrew Morton, Al Viro, Michal Hocko,
	Andreas Gruenbacher, Vlastimil Babka, linux-mm, linux-kernel

On Mon, Oct 24, 2016 at 10:57:09PM +0200, Arnd Bergmann wrote:
> 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.
> 
> Link: https://www.spinics.net/lists/kernel/msg2368133.html
> Acked-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] shmem: avoid maybe-uninitialized warning
  2016-10-24 20:57 ` Arnd Bergmann
@ 2016-10-25  8:56   ` Vlastimil Babka
  -1 siblings, 0 replies; 6+ messages in thread
From: Vlastimil Babka @ 2016-10-25  8:56 UTC (permalink / raw)
  To: Arnd Bergmann, Hugh Dickins
  Cc: Andrew Morton, Al Viro, Kirill A. Shutemov, Michal Hocko,
	Andreas Gruenbacher, linux-mm, linux-kernel

On 10/24/2016 10:57 PM, Arnd Bergmann wrote:
> After enabling -Wmaybe-uninitialized warnings, we get a false-postive
> warning for shmem:
>
> mm/shmem.c: In function ‘shmem_getpage_gfp’:
> include/linux/spinlock.h:332:21: error: ‘info’ 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.
>
> Link: https://www.spinics.net/lists/kernel/msg2368133.html
> Acked-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/shmem.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index ad7813d73ea7..95c4bb690f98 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -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);
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] shmem: avoid maybe-uninitialized warning
@ 2016-10-25  8:56   ` Vlastimil Babka
  0 siblings, 0 replies; 6+ messages in thread
From: Vlastimil Babka @ 2016-10-25  8:56 UTC (permalink / raw)
  To: Arnd Bergmann, Hugh Dickins
  Cc: Andrew Morton, Al Viro, Kirill A. Shutemov, Michal Hocko,
	Andreas Gruenbacher, linux-mm, linux-kernel

On 10/24/2016 10:57 PM, Arnd Bergmann wrote:
> 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.
>
> Link: https://www.spinics.net/lists/kernel/msg2368133.html
> Acked-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/shmem.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index ad7813d73ea7..95c4bb690f98 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -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);
>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-10-25  8:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-24 20:57 [PATCH v2] shmem: avoid maybe-uninitialized warning Arnd Bergmann
2016-10-24 20:57 ` Arnd Bergmann
2016-10-24 23:48 ` Kirill A. Shutemov
2016-10-24 23:48   ` Kirill A. Shutemov
2016-10-25  8:56 ` Vlastimil Babka
2016-10-25  8:56   ` Vlastimil Babka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.