Skip to contentSkip to conversation

soc: aspeed: fix probe error handling

PATCH In review Arnd Bergmann 3 participants 3 messages Jun 19, 2019 – Jun 21, 2019 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: aspeed: fix probe error handling

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]

The device cannot work without this node, so just error out here.

---
 drivers/soc/aspeed/aspeed-lpc-ctrl.c | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/aspeed/aspeed-lpc-ctrl.c +1 -0
index 239520bb207e..81109d22af6a 100644
@@ -212,6 +212,7 @@ static int aspeed_lpc_ctrl_probe(struct platform_device *pdev)
 	node = of_parse_phandle(dev->of_node, "flash", 0);
 	if (!node) {
 		dev_dbg(dev, "Didn't find host pnor flash node\n");
+		return -ENXIO;
 	} else {
 		rc = of_address_to_resource(node, 1, &resm);
 		of_node_put(node);
Signature · 1 line
2.20.0
maintainer
#1 lore raw
Quoted 10 lines · Arnd Bergmann

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]

The device cannot work without this node, so just error out here.

Thanks Arnd. This looks like it applies on top of Vijay's recent patch?

The intent of that change was to make the driver usable for systems that do not want to depend on the flash phandle. I think the fix we want looks like this:

drivers/soc/aspeed/aspeed-lpc-ctrl.c +0 -0
@@ -224,10 +224,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;

Vijay, do you agree?

Cheers,

Joel

Quoted 19 lines
---
 drivers/soc/aspeed/aspeed-lpc-ctrl.c | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/aspeed/aspeed-lpc-ctrl.c +1 -1
index 239520bb207e..81109d22af6a 100644
@@ -212,6 +212,7 @@ static int aspeed_lpc_ctrl_probe(struct platform_device *pdev)
        node = of_parse_phandle(dev->of_node, "flash", 0);
        if (!node) {
                dev_dbg(dev, "Didn't find host pnor flash node\n");
+               return -ENXIO;
        } else {
                rc = of_address_to_resource(node, 1, &resm);
                of_node_put(node);
--

2.20.0

#2 lore raw

?On 6/20/19, 1:29 AM, "Joel Stanley" <[email protected]> wrote:

On Wed, 19 Jun 2019 at 12:56, Arnd Bergmann <[email protected]> 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] >
> The device cannot work without this node, so just error out here.
>
> Signed-off-by: Arnd Bergmann <[email protected]>

Thanks Arnd. This looks like it applies on top of Vijay's recent patch?

The intent of that change was to make the driver usable for systems that do not want to depend on the flash phandle. I think the fix we want looks like this:

--- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c
+++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
@@ -224,10 +224,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;

Vijay, do you agree?
Yes Joel. Thanks for this.

    Cheers,
    
    Joel
    
    > ---
    >  drivers/soc/aspeed/aspeed-lpc-ctrl.c | 1 +
    >  1 file changed, 1 insertion(+)
    >
    > diff --git a/drivers/soc/aspeed/aspeed-lpc-ctrl.c b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
    > index 239520bb207e..81109d22af6a 100644
    > --- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c
    > +++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
    > @@ -212,6 +212,7 @@ static int aspeed_lpc_ctrl_probe(struct platform_device *pdev)
    >         node = of_parse_phandle(dev->of_node, "flash", 0);
    >         if (!node) {
    >                 dev_dbg(dev, "Didn't find host pnor flash node\n");
    > +               return -ENXIO;
    >         } else {
    >                 rc = of_address_to_resource(node, 1, &resm);
    >                 of_node_put(node);
    > --
    > 2.20.0
    >