diff mbox

[1/2] dev/dax: fix uninitialized variable build warning

Message ID 20171018154006.15431-1-ross.zwisler@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ross Zwisler Oct. 18, 2017, 3:40 p.m. UTC
Fix this build warning:

warning: 'phys' may be used uninitialized in this function
[-Wuninitialized]

As reported here:

https://lkml.org/lkml/2017/10/16/152

This should have no functional change because you can only get into the if
statement in dax_pgoff_to_phys() that is complaining about 'phys' being
uninitialized if you broke out early in the above loop, in which case
'phys' will be set.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
---
 drivers/dax/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dan Williams Oct. 18, 2017, 3:56 p.m. UTC | #1
On Wed, Oct 18, 2017 at 8:40 AM, Ross Zwisler
<ross.zwisler@linux.intel.com> wrote:
> Fix this build warning:
>
> warning: 'phys' may be used uninitialized in this function
> [-Wuninitialized]
>
> As reported here:
>
> https://lkml.org/lkml/2017/10/16/152
>
> This should have no functional change because you can only get into the if
> statement in dax_pgoff_to_phys() that is complaining about 'phys' being
> uninitialized if you broke out early in the above loop, in which case
> 'phys' will be set.

Then the compiler is wrong.

>
> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> ---
>  drivers/dax/device.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dax/device.c b/drivers/dax/device.c
> index e9f3b3e..4aca0a2 100644
> --- a/drivers/dax/device.c
> +++ b/drivers/dax/device.c
> @@ -222,7 +222,7 @@ __weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
>                 unsigned long size)
>  {
>         struct resource *res;
> -       phys_addr_t phys;
> +       phys_addr_t phys = 0;

We have uninitialized_var() for silencing the compiler, and since the
report is bogus we might note with a comment which gcc had a problem
with this routine.
diff mbox

Patch

diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index e9f3b3e..4aca0a2 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -222,7 +222,7 @@  __weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
 		unsigned long size)
 {
 	struct resource *res;
-	phys_addr_t phys;
+	phys_addr_t phys = 0;
 	int i;
 
 	for (i = 0; i < dev_dax->num_resources; i++) {