mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harald Geyer <harald@ccbib.org>
To: Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Heiko Stuebner <heiko@sntech.de>
Cc: linux-kernel@vger.kernel.org, Harald Geyer <harald@ccbib.org>
Subject: [PATCH 1/2] regulator: gpio: Avoid unnecessarily copying data structures in probe()
Date: Thu, 28 Jan 2016 19:55:17 +0000	[thread overview]
Message-ID: <1454010918-29369-2-git-send-email-harald@ccbib.org> (raw)
In-Reply-To: <1454010918-29369-1-git-send-email-harald@ccbib.org>

The data structures either have been copied in
of_get_gpio_regulator_config() already or are part of platform data,
which we keep a pointer to for the life time of the device anyway.

As a side effect this fixes the cleanup pathes if probe() fails.

Signed-off-by: Harald Geyer <harald@ccbib.org>
---
 drivers/regulator/gpio-regulator.c | 34 ++++++----------------------------
 1 file changed, 6 insertions(+), 28 deletions(-)

diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 7bba8b7..5e2e14d 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -271,33 +271,18 @@ static int gpio_regulator_probe(struct platform_device *pdev)
 	}
 
 	if (config->nr_gpios != 0) {
-		drvdata->gpios = kmemdup(config->gpios,
-					 config->nr_gpios * sizeof(struct gpio),
-					 GFP_KERNEL);
-		if (drvdata->gpios == NULL) {
-			dev_err(&pdev->dev, "Failed to allocate gpio data\n");
-			ret = -ENOMEM;
-			goto err_name;
-		}
+		drvdata->gpios = config->gpios;
 
 		drvdata->nr_gpios = config->nr_gpios;
 		ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
 		if (ret) {
 			dev_err(&pdev->dev,
 			"Could not obtain regulator setting GPIOs: %d\n", ret);
-			goto err_memstate;
+			goto err_name;
 		}
 	}
 
-	drvdata->states = kmemdup(config->states,
-				  config->nr_states *
-					 sizeof(struct gpio_regulator_state),
-				  GFP_KERNEL);
-	if (drvdata->states == NULL) {
-		dev_err(&pdev->dev, "Failed to allocate state data\n");
-		ret = -ENOMEM;
-		goto err_memgpio;
-	}
+	drvdata->states = config->states;
 	drvdata->nr_states = config->nr_states;
 
 	drvdata->desc.owner = THIS_MODULE;
@@ -317,7 +302,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
 	default:
 		dev_err(&pdev->dev, "No regulator type set\n");
 		ret = -EINVAL;
-		goto err_memgpio;
+		goto err_gpio;
 	}
 
 	/* build initial state from gpio init data. */
@@ -354,19 +339,15 @@ static int gpio_regulator_probe(struct platform_device *pdev)
 	if (IS_ERR(drvdata->dev)) {
 		ret = PTR_ERR(drvdata->dev);
 		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
-		goto err_stategpio;
+		goto err_gpio;
 	}
 
 	platform_set_drvdata(pdev, drvdata);
 
 	return 0;
 
-err_stategpio:
+err_gpio:
 	gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
-err_memstate:
-	kfree(drvdata->states);
-err_memgpio:
-	kfree(drvdata->gpios);
 err_name:
 	kfree(drvdata->desc.name);
 err:
@@ -381,9 +362,6 @@ static int gpio_regulator_remove(struct platform_device *pdev)
 
 	gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
 
-	kfree(drvdata->states);
-	kfree(drvdata->gpios);
-
 	kfree(drvdata->desc.name);
 
 	return 0;
-- 
2.1.4

  reply	other threads:[~2016-01-28 20:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-28 19:55 [PATCH 0/2] regulator: gpio: fix error paths " Harald Geyer
2016-01-28 19:55 ` Harald Geyer [this message]
2016-01-28 23:09   ` [PATCH 1/2] regulator: gpio: Avoid unnecessarily copying data structures " Mark Brown
2016-01-29 16:25     ` Harald Geyer
2016-02-03 17:20       ` Mark Brown
2016-01-28 19:55 ` [PATCH 2/2] regulator: gpio: Move last remaining memory allocation to devres Harald Geyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454010918-29369-2-git-send-email-harald@ccbib.org \
    --to=harald@ccbib.org \
    --cc=broonie@kernel.org \
    --cc=heiko@sntech.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®