linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Ben Dooks <ben-i2c-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2] i2c: stu300: use devm managed resources
Date: Fri, 13 Jul 2012 11:26:57 +0200	[thread overview]
Message-ID: <20120713092657.GJ32184@pengutronix.de> (raw)
In-Reply-To: <1341864666-29441-1-git-send-email-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 2774 bytes --]

On Mon, Jul 09, 2012 at 10:11:06PM +0200, Linus Walleij wrote:
> Allocate memory for device state using devm_kzalloc(), get the
> clock using devm_clk_get(), get the IRQ using devm_request_irq(),
> request and remap memory using devm_request_and_ioremap().
> All to simplify accounting and letting the kernel do the
> garbage-collection.
> 
> Signed-off-by: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> ChangeLog v1->v2:
> - Use more devm* stuff, at Wolfram's request.
> - Note: based on a clean v3.5-rc6, may need some patch -p1 < patch
>   to apply on the i2c tree, if you want me to rebase it, just tell
>   me where to find the baseline.

Thanks, it is here:

git://git.pengutronix.de/git/wsa/linux.git i2c-embedded/for-next


> ---
>  drivers/i2c/busses/i2c-stu300.c |   75 +++++++++-----------------------------
>  1 files changed, 18 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
> index 4d44af1..dc4c518 100644
> --- a/drivers/i2c/busses/i2c-stu300.c
> +++ b/drivers/i2c/busses/i2c-stu300.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (C) 2007-2009 ST-Ericsson AB
> + * Copyright (C) 2007-2012 ST-Ericsson AB
>   * License terms: GNU General Public License (GPL) version 2
>   * ST DDC I2C master mode driver, used in e.g. U300 series platforms.
>   * Author: Linus Walleij <linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
> @@ -873,64 +873,46 @@ stu300_probe(struct platform_device *pdev)
>  	int ret = 0;
>  	char clk_name[] = "I2C0";
>  
> -	dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL);
> +	dev = devm_kzalloc(&pdev->dev, sizeof(struct stu300_dev), GFP_KERNEL);
>  	if (!dev) {
>  		dev_err(&pdev->dev, "could not allocate device struct\n");
> -		ret = -ENOMEM;
> -		goto err_no_devmem;
> +		return -ENOMEM;
>  	}
>  
>  	bus_nr = pdev->id;
>  	clk_name[3] += (char)bus_nr;
> -	dev->clk = clk_get(&pdev->dev, clk_name);
> +	dev->clk = devm_clk_get(&pdev->dev, clk_name);
>  	if (IS_ERR(dev->clk)) {
> -		ret = PTR_ERR(dev->clk);
>  		dev_err(&pdev->dev, "could not retrieve i2c bus clock\n");
> -		goto err_no_clk;
> +		return PTR_ERR(dev->clk);
>  	}
>  
>  	dev->pdev = pdev;
> -	platform_set_drvdata(pdev, dev);
> -
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	if (!res) {
> -		ret = -ENOENT;
> -		goto err_no_resource;
> -	}
> +	if (!res)
> +		return -ENOENT;
>  
>  	dev->phybase = res->start;
>  	dev->physize = resource_size(res);

I'd think you can skip those, too?

Thanks,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

      parent reply	other threads:[~2012-07-13  9:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-09 20:11 [PATCH v2] i2c: stu300: use devm managed resources Linus Walleij
     [not found] ` <1341864666-29441-1-git-send-email-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-07-13  9:26   ` Wolfram Sang [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=20120713092657.GJ32184@pengutronix.de \
    --to=w.sang-bicnvbalz9megne8c9+irq@public.gmane.org \
    --cc=ben-i2c-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.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;
as well as URLs for NNTP newsgroup(s).