[PATCH RFC 2/4] Platform: OLPC: Fix handling of regulator registration error

From: Lubomir Rintel
Date: Tue Dec 01 2020 - 03:26:22 EST


We wouldn't reset ec_priv previously. Let's handle handle the errors in
a single spot to fix this.

Signed-off-by: Lubomir Rintel <lkundrak@xxxxx>
---
drivers/platform/olpc/olpc-ec.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index faecb73bd8430..2ad638583cc58 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -427,11 +427,8 @@ static int olpc_ec_probe(struct platform_device *pdev)

/* get the EC revision */
err = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, &ec->version, 1);
- if (err) {
- ec_priv = NULL;
- kfree(ec);
- return err;
- }
+ if (err)
+ goto error;

config.dev = pdev->dev.parent;
config.driver_data = ec;
@@ -441,12 +438,16 @@ static int olpc_ec_probe(struct platform_device *pdev)
if (IS_ERR(ec->dcon_rdev)) {
dev_err(&pdev->dev, "failed to register DCON regulator\n");
err = PTR_ERR(ec->dcon_rdev);
- kfree(ec);
- return err;
+ goto error;
}

ec->dbgfs_dir = olpc_ec_setup_debugfs();

+ return 0;
+
+error:
+ ec_priv = NULL;
+ kfree(ec);
return err;
}

--
2.28.0