dax: initialize variable pfn before using it
Subsystems (2)
PATCH 1/1 dax: initialize variable pfn before using it
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 <[email protected]>
--- fs/dax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dax.c +1 -1
@@ -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 )
Signature · 1 line
2.14.1
Quoted 23 lines · 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); ^~~
Quoted 1 line
Signed-off-by Nicolas Iooss <[email protected]>
Yep this looks good. Thanks for the fix.
Reviewed-by Ross Zwisler <[email protected]>
Quoted 20 lines
--- fs/dax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/dax.c +1
-1@@ -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 )Signature · 1 line
2.14.1