linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] dax: initialize variable pfn before using it
@ 2017-09-03  8:30 Nicolas Iooss
  2017-09-05 18:37 ` Ross Zwisler
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Iooss @ 2017-09-03  8:30 UTC (permalink / raw)
  To: Matthew Wilcox, Ross Zwisler; +Cc: linux-fsdevel, linux-kernel, Nicolas Iooss

Function dax_pmd_insert_mapping() contains the following code:

        pfn_t pfn;
        if (bdev_dax_pgoff(bdev, sector, size, &pgoff) != 0)
            goto fallback;
        /* ... */
    fallback:
      trace_dax_pmd_insert_mapping_fallback(inode, vmf, length, pfn, ret);

When the condition in the if statement fails, the function calls
trace_dax_pmd_insert_mapping_fallback() with an uninitialized pfn value.

This issue has been found while building the kernel with clang. The
compiler reported:

    fs/dax.c:1280:6: error: variable 'pfn' is used uninitialized
    whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
        if (bdev_dax_pgoff(bdev, sector, size, &pgoff) != 0)
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fs/dax.c:1310:60: note: uninitialized use occurs here
      trace_dax_pmd_insert_mapping_fallback(inode, vmf, length, pfn, ret);
                                                                     ^~~

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
---
 fs/dax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/dax.c b/fs/dax.c
index ab925dc6647a..20e6d76d6fff 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1283,7 +1283,7 @@ static int dax_pmd_insert_mapping(struct vm_fault *vmf, struct iomap *iomap,
 	void *ret = NULL, *kaddr;
 	long length = 0;
 	pgoff_t pgoff;
-	pfn_t pfn;
+	pfn_t pfn = {};
 	int id;
 
 	if (bdev_dax_pgoff(bdev, sector, size, &pgoff) != 0)
-- 
2.14.1

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

* Re: [PATCH 1/1] dax: initialize variable pfn before using it
  2017-09-03  8:30 [PATCH 1/1] dax: initialize variable pfn before using it Nicolas Iooss
@ 2017-09-05 18:37 ` Ross Zwisler
  0 siblings, 0 replies; 2+ messages in thread
From: Ross Zwisler @ 2017-09-05 18:37 UTC (permalink / raw)
  To: Nicolas Iooss, Andrew Morton
  Cc: Matthew Wilcox, Ross Zwisler, linux-fsdevel, linux-kernel

On Sun, Sep 03, 2017 at 10:30:00AM +0200, Nicolas Iooss wrote:
> Function dax_pmd_insert_mapping() contains the following code:
> 
>         pfn_t pfn;
>         if (bdev_dax_pgoff(bdev, sector, size, &pgoff) != 0)
>             goto fallback;
>         /* ... */
>     fallback:
>       trace_dax_pmd_insert_mapping_fallback(inode, vmf, length, pfn, ret);
> 
> When the condition in the if statement fails, the function calls
> trace_dax_pmd_insert_mapping_fallback() with an uninitialized pfn value.
> 
> This issue has been found while building the kernel with clang. The
> compiler reported:
> 
>     fs/dax.c:1280:6: error: variable 'pfn' is used uninitialized
>     whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>         if (bdev_dax_pgoff(bdev, sector, size, &pgoff) != 0)
>             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     fs/dax.c:1310:60: note: uninitialized use occurs here
>       trace_dax_pmd_insert_mapping_fallback(inode, vmf, length, pfn, ret);
>                                                                      ^~~
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>

Yep this looks good.  Thanks for the fix.

Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>

> ---
>  fs/dax.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/dax.c b/fs/dax.c
> index ab925dc6647a..20e6d76d6fff 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -1283,7 +1283,7 @@ static int dax_pmd_insert_mapping(struct vm_fault *vmf, struct iomap *iomap,
>  	void *ret = NULL, *kaddr;
>  	long length = 0;
>  	pgoff_t pgoff;
> -	pfn_t pfn;
> +	pfn_t pfn = {};
>  	int id;
>  
>  	if (bdev_dax_pgoff(bdev, sector, size, &pgoff) != 0)
> -- 
> 2.14.1
> 

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

end of thread, other threads:[~2017-09-05 18:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-03  8:30 [PATCH 1/1] dax: initialize variable pfn before using it Nicolas Iooss
2017-09-05 18:37 ` Ross Zwisler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).