diff mbox

[2/2] PCI: iproc: avoid maybe-uninitialized warning

Message ID 20161122141844.1655574-2-arnd@arndb.de (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Arnd Bergmann Nov. 22, 2016, 2:17 p.m. UTC
gcc notices that calling iproc_pcie_setup_ib with ib->nr_regions==0
would result in an uninitialized return value:

drivers/pci/host/pcie-iproc.c: In function 'iproc_pcie_setup_ib':
drivers/pci/host/pcie-iproc.c:894:6: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This can't really happen, but the correct behavior of the function
is probably to return -EINVAL if it ever did.

Fixes: 4213e15c364e ("PCI: iproc: Make outbound mapping code more generic")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/pci/host/pcie-iproc.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Ray Jui Nov. 22, 2016, 5:45 p.m. UTC | #1
Hi Arnd,

On 11/22/2016 6:17 AM, Arnd Bergmann wrote:
> gcc notices that calling iproc_pcie_setup_ib with ib->nr_regions==0
> would result in an uninitialized return value:
> 
> drivers/pci/host/pcie-iproc.c: In function 'iproc_pcie_setup_ib':
> drivers/pci/host/pcie-iproc.c:894:6: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> This can't really happen, but the correct behavior of the function
> is probably to return -EINVAL if it ever did.
> 
> Fixes: 4213e15c364e ("PCI: iproc: Make outbound mapping code more generic")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/pci/host/pcie-iproc.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
> index 857ff5198317..0359569c8d78 100644
> --- a/drivers/pci/host/pcie-iproc.c
> +++ b/drivers/pci/host/pcie-iproc.c
> @@ -936,6 +936,7 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
>  
>  		}
>  	}
> +	ret = -EINVAL;
>  err_ib:
>  	dev_err(dev, "unable to configure inbound mapping\n");
>  	dev_err(dev, "axi %pap, pci %pap, res size %pap\n",
> 

This change is good, but in my opinion, a further improvement for
clarity would be to initialize 'ret' to -EINVAL in the beginning of this
function when 'ret' is declared. What do you think?

Thanks,

Ray
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Arnd Bergmann Nov. 22, 2016, 9:15 p.m. UTC | #2
On Tuesday, November 22, 2016 9:45:24 AM CET Ray Jui wrote:
> > diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
> > index 857ff5198317..0359569c8d78 100644
> > --- a/drivers/pci/host/pcie-iproc.c
> > +++ b/drivers/pci/host/pcie-iproc.c
> > @@ -936,6 +936,7 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
> >  
> >               }
> >       }
> > +     ret = -EINVAL;
> >  err_ib:
> >       dev_err(dev, "unable to configure inbound mapping\n");
> >       dev_err(dev, "axi %pap, pci %pap, res size %pap\n",
> > 
> 
> This change is good, but in my opinion, a further improvement for
> clarity would be to initialize 'ret' to -EINVAL in the beginning of this
> function when 'ret' is declared. What do you think?
> 

I never do that, see https://rusty.ozlabs.org/?p=232 for a great
explanation about why.

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ray Jui Nov. 23, 2016, 3 a.m. UTC | #3
On 11/22/2016 1:15 PM, Arnd Bergmann wrote:
> On Tuesday, November 22, 2016 9:45:24 AM CET Ray Jui wrote:
>>> diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
>>> index 857ff5198317..0359569c8d78 100644
>>> --- a/drivers/pci/host/pcie-iproc.c
>>> +++ b/drivers/pci/host/pcie-iproc.c
>>> @@ -936,6 +936,7 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
>>>  
>>>               }
>>>       }
>>> +     ret = -EINVAL;
>>>  err_ib:
>>>       dev_err(dev, "unable to configure inbound mapping\n");
>>>       dev_err(dev, "axi %pap, pci %pap, res size %pap\n",
>>>
>>
>> This change is good, but in my opinion, a further improvement for
>> clarity would be to initialize 'ret' to -EINVAL in the beginning of this
>> function when 'ret' is declared. What do you think?
>>
> 
> I never do that, see https://rusty.ozlabs.org/?p=232 for a great
> explanation about why.
> 
> 	Arnd
> 

Okay got it. Thanks!

Ray
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
index 857ff5198317..0359569c8d78 100644
--- a/drivers/pci/host/pcie-iproc.c
+++ b/drivers/pci/host/pcie-iproc.c
@@ -936,6 +936,7 @@  static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 
 		}
 	}
+	ret = -EINVAL;
 err_ib:
 	dev_err(dev, "unable to configure inbound mapping\n");
 	dev_err(dev, "axi %pap, pci %pap, res size %pap\n",