diff mbox series

soc: aspeed: lpc-ctrl: Fix probe error handling

Message ID 20190620091738.14683-1-joel@jms.id.au
State Accepted
Commit c8a3b9b50d8331528fc8d03aadd1fec3d60362d7
Headers show
Series soc: aspeed: lpc-ctrl: Fix probe error handling | expand

Commit Message

Joel Stanley June 20, 2019, 9:17 a.m. UTC
gcc warns that a mising "flash" phandle node leads to undefined
behavior later:

drivers/soc/aspeed/aspeed-lpc-ctrl.c: In function 'aspeed_lpc_ctrl_probe':
drivers/soc/aspeed/aspeed-lpc-ctrl.c:201:18: error: '*((void *)&resm+8)' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Only set the flash base and size if we find a phandle in the device
tree.

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Joel Stanley <joel@jms.id.au>

---
 drivers/soc/aspeed/aspeed-lpc-ctrl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.20.1

Comments

Andrew Jeffery June 21, 2019, 1:56 a.m. UTC | #1
On Thu, 20 Jun 2019, at 18:47, Joel Stanley wrote:
> gcc warns that a mising "flash" phandle node leads to undefined

> behavior later:

> 

> drivers/soc/aspeed/aspeed-lpc-ctrl.c: In function 

> 'aspeed_lpc_ctrl_probe':

> drivers/soc/aspeed/aspeed-lpc-ctrl.c:201:18: error: '*((void 

> *)&resm+8)' may be used uninitialized in this function 

> [-Werror=maybe-uninitialized]

> 

> Only set the flash base and size if we find a phandle in the device

> tree.


Ugh, yeah. Not sure how I missed that. Thanks for fixing it.

Reviewed-by: Andrew Jeffery <andrew@aj.id.au>


> 

> Reported-by: Arnd Bergmann <arnd@arndb.de>

> Signed-off-by: Joel Stanley <joel@jms.id.au>

> ---

>  drivers/soc/aspeed/aspeed-lpc-ctrl.c | 5 +++--

>  1 file changed, 3 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/soc/aspeed/aspeed-lpc-ctrl.c 

> b/drivers/soc/aspeed/aspeed-lpc-ctrl.c

> index aca13779764a..eee26c2d8b52 100644

> --- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c

> +++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c

> @@ -223,10 +223,11 @@ static int aspeed_lpc_ctrl_probe(struct 

> platform_device *pdev)

>  			dev_err(dev, "Couldn't address to resource for flash\n");

>  			return rc;

>  		}

> +

> +		lpc_ctrl->pnor_size = resource_size(&resm);

> +		lpc_ctrl->pnor_base = resm.start;

>  	}

>  

> -	lpc_ctrl->pnor_size = resource_size(&resm);

> -	lpc_ctrl->pnor_base = resm.start;

>  

>  	dev_set_drvdata(&pdev->dev, lpc_ctrl);

>  

> -- 

> 2.20.1

> 

>
Vijay Khemka June 21, 2019, 4:56 p.m. UTC | #2
On 6/20/19, 2:17 AM, "joel.stan@gmail.com on behalf of Joel Stanley" <joel.stan@gmail.com on behalf of joel@jms.id.au> wrote:

    gcc warns that a mising "flash" phandle node leads to undefined
    behavior later:
    
    drivers/soc/aspeed/aspeed-lpc-ctrl.c: In function 'aspeed_lpc_ctrl_probe':
    drivers/soc/aspeed/aspeed-lpc-ctrl.c:201:18: error: '*((void *)&resm+8)' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    
    Only set the flash base and size if we find a phandle in the device
    tree.
    
Thanks for fixing this.
Reviewed-by: Vijay Khemka <vijaykhemka@fb.com>


    Reported-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Joel Stanley <joel@jms.id.au>

    ---
     drivers/soc/aspeed/aspeed-lpc-ctrl.c | 5 +++--
     1 file changed, 3 insertions(+), 2 deletions(-)
    
    diff --git a/drivers/soc/aspeed/aspeed-lpc-ctrl.c b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
    index aca13779764a..eee26c2d8b52 100644
    --- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c
    +++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
    @@ -223,10 +223,11 @@ static int aspeed_lpc_ctrl_probe(struct platform_device *pdev)
     			dev_err(dev, "Couldn't address to resource for flash\n");
     			return rc;
     		}
    +
    +		lpc_ctrl->pnor_size = resource_size(&resm);
    +		lpc_ctrl->pnor_base = resm.start;
     	}
     
    -	lpc_ctrl->pnor_size = resource_size(&resm);
    -	lpc_ctrl->pnor_base = resm.start;
     
     	dev_set_drvdata(&pdev->dev, lpc_ctrl);
     
    -- 
    2.20.1
diff mbox series

Patch

diff --git a/drivers/soc/aspeed/aspeed-lpc-ctrl.c b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
index aca13779764a..eee26c2d8b52 100644
--- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c
+++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
@@ -223,10 +223,11 @@  static int aspeed_lpc_ctrl_probe(struct platform_device *pdev)
 			dev_err(dev, "Couldn't address to resource for flash\n");
 			return rc;
 		}
+
+		lpc_ctrl->pnor_size = resource_size(&resm);
+		lpc_ctrl->pnor_base = resm.start;
 	}
 
-	lpc_ctrl->pnor_size = resource_size(&resm);
-	lpc_ctrl->pnor_base = resm.start;
 
 	dev_set_drvdata(&pdev->dev, lpc_ctrl);