* [PATCH v2 3/3] backlight: lp855x: remove goto err_sysfs and goto err_dev
@ 2012-08-07 9:25 Jingoo Han
2012-08-16 18:31 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Jingoo Han @ 2012-08-07 9:25 UTC (permalink / raw)
To: 'Andrew Morton', 'LKML'
Cc: 'Richard Purdie', 'Milo(Woogyom) Kim',
'Jingoo Han'
This patch removes goto err_sysfs and goto err_dev, which makes code
a bit smaller.
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
drivers/video/backlight/lp855x_bl.c | 12 ++++--------
1 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index aa6d4f7..f9645fe 100644
--- 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)
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 3/3] backlight: lp855x: remove goto err_sysfs and goto err_dev
2012-08-07 9:25 [PATCH v2 3/3] backlight: lp855x: remove goto err_sysfs and goto err_dev Jingoo Han
@ 2012-08-16 18:31 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2012-08-16 18:31 UTC (permalink / raw)
To: Jingoo Han
Cc: 'LKML', 'Richard Purdie', 'Milo(Woogyom) Kim'
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-16 18:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-07 9:25 [PATCH v2 3/3] backlight: lp855x: remove goto err_sysfs and goto err_dev Jingoo Han
2012-08-16 18:31 ` Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.