linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Heiko Stübner" <heiko@sntech.de>
To: Rob Jones <rob.jones@codethink.co.uk>
Cc: linus.walleij@linaro.org, gnurou@gmail.com, lgirdwood@gmail.com,
	broonie@kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, ian.molton@codethink.co.uk,
	ben.dooks@codethink.co.uk
Subject: Re: [PATCH 3/3] drivers/regulator: gpio-regulator.c: use managed resources for probe.
Date: Wed, 18 Jun 2014 15:05:31 +0200	[thread overview]
Message-ID: <87697987.GOalQlOk20@diego> (raw)
In-Reply-To: <1402411308-14182-4-git-send-email-rob.jones@codethink.co.uk>

Am Dienstag, 10. Juni 2014, 15:41:48 schrieb Rob Jones:
> Use managed resource functions for all resource allocations in
> gpio_regulator_probe().
> 
> Remove gpio_regulator_remove() as it is now redundant.
> 
> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
> Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>

Reviewed-by: Heiko Stuebner <heiko@sntech.de>


> ---
>  drivers/regulator/gpio-regulator.c |   71
> ++++++++++++------------------------ 1 file changed, 24 insertions(+), 47
> deletions(-)
> 
> diff --git a/drivers/regulator/gpio-regulator.c
> b/drivers/regulator/gpio-regulator.c index 989b23b..56341c3 100644
> --- a/drivers/regulator/gpio-regulator.c
> +++ b/drivers/regulator/gpio-regulator.c
> @@ -254,30 +254,31 @@ static int gpio_regulator_probe(struct platform_device
> *pdev) if (drvdata == NULL)
>  		return -ENOMEM;
> 
> -	drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
> +	drvdata->desc.name = devm_kstrdup(&pdev->dev,
> +					  config->supply_name,
> +					  GFP_KERNEL);
>  	if (drvdata->desc.name == NULL) {
>  		dev_err(&pdev->dev, "Failed to allocate supply name\n");
> -		ret = -ENOMEM;
> -		goto err;
> +		return -ENOMEM;
>  	}
> 
> -	drvdata->gpios = kmemdup(config->gpios,
> -				 config->nr_gpios * sizeof(struct gpio),
> -				 GFP_KERNEL);
> +	drvdata->gpios = devm_kmemdup(&pdev->dev,
> +				      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;
> +		return -ENOMEM;
>  	}
> 
> -	drvdata->states = kmemdup(config->states,
> -				  config->nr_states *
> +	drvdata->states = devm_kmemdup(&pdev->dev,
> +				       config->states,
> +				       config->nr_states *
>  					 sizeof(struct gpio_regulator_state),
> -				  GFP_KERNEL);
> +				       GFP_KERNEL);
>  	if (drvdata->states == NULL) {
>  		dev_err(&pdev->dev, "Failed to allocate state data\n");
> -		ret = -ENOMEM;
> -		goto err_memgpio;
> +		return -ENOMEM;
>  	}
>  	drvdata->nr_states = config->nr_states;
> 
> @@ -297,16 +298,17 @@ static int gpio_regulator_probe(struct platform_device
> *pdev) break;
>  	default:
>  		dev_err(&pdev->dev, "No regulator type set\n");
> -		ret = -EINVAL;
> -		goto err_memgpio;
> +		return -EINVAL;
>  	}
> 
>  	drvdata->nr_gpios = config->nr_gpios;
> -	ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
> +	ret = devm_gpio_request_array(&pdev->dev,
> +				      drvdata->gpios,
> +				      drvdata->nr_gpios);
>  	if (ret) {
>  		dev_err(&pdev->dev,
>  		   "Could not obtain regulator setting GPIOs: %d\n", ret);
> -		goto err_memstate;
> +		return ret;
>  	}
> 
>  	/* build initial state from gpio init data. */
> @@ -337,43 +339,18 @@ static int gpio_regulator_probe(struct platform_device
> *pdev) cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
>  	}
> 
> -	drvdata->dev = regulator_register(&drvdata->desc, &cfg);
> +	drvdata->dev = devm_regulator_register(&pdev->dev,
> +					       &drvdata->desc,
> +					       &cfg);
>  	if (IS_ERR(drvdata->dev)) {
>  		ret = PTR_ERR(drvdata->dev);
>  		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
> -		goto err_stategpio;
> +		return ret;
>  	}
> 
>  	platform_set_drvdata(pdev, drvdata);
> 
>  	return 0;
> -
> -err_stategpio:
> -	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:
> -	return ret;
> -}
> -
> -static int gpio_regulator_remove(struct platform_device *pdev)
> -{
> -	struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev);
> -
> -	regulator_unregister(drvdata->dev);
> -
> -	gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
> -
> -	kfree(drvdata->states);
> -	kfree(drvdata->gpios);
> -
> -	kfree(drvdata->desc.name);
> -
> -	return 0;
>  }
> 
>  #if defined(CONFIG_OF)
> @@ -385,7 +362,7 @@ static const struct of_device_id
> regulator_gpio_of_match[] = {
> 
>  static struct platform_driver gpio_regulator_driver = {
>  	.probe		= gpio_regulator_probe,
> -	.remove		= gpio_regulator_remove,
> +	.remove		= NULL,
>  	.driver		= {
>  		.name		= "gpio-regulator",
>  		.owner		= THIS_MODULE,


      reply	other threads:[~2014-06-18 13:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-10 14:41 [PATCH 0/3] use managed resources for gpio-regulator probe Rob Jones
2014-06-10 14:41 ` [PATCH 1/3] drivers/gpio: devres.c: allow gpio array requests for managed devices Rob Jones
2014-06-18 13:24   ` Heiko Stübner
2014-06-18 15:56     ` Rob Jones
2014-06-10 14:41 ` [PATCH 2/3] drivers/base: devres.c: Add block copy func. " Rob Jones
2014-06-18 13:05   ` Heiko Stübner
2014-06-18 15:52     ` Rob Jones
2014-06-10 14:41 ` [PATCH 3/3] drivers/regulator: gpio-regulator.c: use managed resources for probe Rob Jones
2014-06-18 13:05   ` Heiko Stübner [this message]

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=87697987.GOalQlOk20@diego \
    --to=heiko@sntech.de \
    --cc=ben.dooks@codethink.co.uk \
    --cc=broonie@kernel.org \
    --cc=gnurou@gmail.com \
    --cc=ian.molton@codethink.co.uk \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.jones@codethink.co.uk \
    /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;
as well as URLs for NNTP newsgroup(s).