mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jingoo Han <jg1.han@samsung.com>
Cc: "'LKML'" <linux-kernel@vger.kernel.org>,
	"'Richard Purdie'" <rpurdie@rpsys.net>,
	"'Milo(Woogyom) Kim'" <milo.kim@ti.com>
Subject: Re: [PATCH v2 3/3] backlight: lp855x: remove goto err_sysfs and goto err_dev
Date: Thu, 16 Aug 2012 11:31:19 -0700	[thread overview]
Message-ID: <20120816113119.85222ba7.akpm@linux-foundation.org> (raw)
In-Reply-To: <000701cd747e$9ec822f0$dc5868d0$%han@samsung.com>

On Tue, 07 Aug 2012 18:25:44 +0900
Jingoo Han <jg1.han@samsung.com> wrote:

> This patch removes goto err_sysfs and goto err_dev, which makes code
> a bit smaller.
> 
> ...
>
> --- a/drivers/video/backlight/lp855x_bl.c
> +++ b/drivers/video/backlight/lp855x_bl.c
> @@ -272,29 +272,25 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
>  	if (ret) {
>  		dev_err(lp->dev, "i2c communication err: %d", ret);
>  		if (mode == REGISTER_BASED)
> -			goto err_dev;
> +			return ret;
>  	}
>  
>  	ret = lp855x_backlight_register(lp);
>  	if (ret) {
>  		dev_err(lp->dev,
>  			"failed to register backlight. err: %d\n", ret);
> -		goto err_dev;
> +		return ret;
>  	}
>  
>  	ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group);
>  	if (ret) {
>  		dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret);
> -		goto err_sysfs;
> +		lp855x_backlight_unregister(lp);
> +		return ret;
>  	}
>  
>  	backlight_update_status(lp->bl);
>  	return 0;
> -
> -err_sysfs:
> -	lp855x_backlight_unregister(lp);
> -err_dev:
> -	return ret;
>  }
>  
>  static int __devexit lp855x_remove(struct i2c_client *cl)

err, no.  We've learned from hard experience that having multiple return
points from a non-trivial function easily leads to resource leaks and
missed unlocks.  For this reason, kernel code frequently uses the "goto
out" technique, providing a single site where deallocation and
unlocking occurs.



      reply	other threads:[~2012-08-16 18:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07  9:25 Jingoo Han
2012-08-16 18:31 ` Andrew Morton [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=20120816113119.85222ba7.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=jg1.han@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=milo.kim@ti.com \
    --cc=rpurdie@rpsys.net \
    /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

Powered by JetHome