Skip to contentSkip to conversation

drm/fsl-dcu: remove unneeded 'ret' assignment

PATCH Applied Fabio Estevam 3 participants 8 messages Dec 28, 2016 – Feb 8, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/fsl-dcu: remove unneeded 'ret' assignment

From: Fabio Estevam <[email protected]>

When devm_kzalloc() fails there is no need to assign an error code to the 'ret' variable as it will not be used after jumping to the 'err_node_put' label, so just remove the assignment.

---
 drivers/gpu/drm/fsl-dcu/fsl_tcon.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +1 -3
index 3194e54..2fbb7ee 100644
@@ -72,10 +72,8 @@ struct fsl_tcon *fsl_tcon_init(struct device *dev)
 		return NULL;
 
 	tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
-	if (!tcon) {
-		ret = -ENOMEM;
+	if (!tcon)
 		goto err_node_put;
-	}
 
 	ret = fsl_tcon_init_regmap(dev, tcon, np);
 	if (ret) {
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 drm/fsl-dcu: check for clk_prepare_enable() error

From: Fabio Estevam <[email protected]>

clk_prepare_enable() may fail, so we should better check its return value.

Also place the of_node_put() function right after clk_prepare_enable(), in order to avoid calling of_node_put() twice in case clk_prepare_enable() fails.

---
 drivers/gpu/drm/fsl-dcu/fsl_tcon.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +6 -2
index 2fbb7ee..b3d70a6 100644
@@ -87,9 +87,13 @@ struct fsl_tcon *fsl_tcon_init(struct device *dev)
 		goto err_node_put;
 	}
 
-	of_node_put(np);
-	clk_prepare_enable(tcon->ipg_clk);
+	ret = clk_prepare_enable(tcon->ipg_clk);
+	if (ret) {
+		dev_err(dev, "Couldn't enable the TCON clock\n");
+		goto err_node_put;
+	}
 
+	of_node_put(np);
 	dev_info(dev, "Using TCON in bypass mode\n");
 
 	return tcon;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [PATCH 2/2] drm/fsl-dcu: check for clk_prepare_enable() error

Quoted 19 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

clk_prepare_enable() may fail, so we should better check its return value.

Also place the of_node_put() function right after clk_prepare_enable(), in order to avoid calling of_node_put() twice in case clk_prepare_enable() fails.

---
 drivers/gpu/drm/fsl-dcu/fsl_tcon.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +0 -0
index 2fbb7ee..b3d70a6 100644

drivers/gpu/drm/fsl-dcu/fsl_tcon.c struct fsl_tcon *fsl_tcon_init(struct device *dev) · line 94

Quoted 10 lines
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +5 -2
@@ -87,9 +87,13 @@ struct fsl_tcon *fsl_tcon_init(struct device *dev)
 		goto err_node_put;
 	}
 
-	of_node_put(np);
-	clk_prepare_enable(tcon->ipg_clk);
+	ret = clk_prepare_enable(tcon->ipg_clk);
+	if (ret) {
+		dev_err(dev, "Couldn't enable the TCON clock\n");
+		goto err_node_put;
+	}

This leaks tcon if clk_prepare_enable fails.

drivers/gpu/drm/fsl-dcu/fsl_tcon.c struct fsl_tcon *fsl_tcon_init(struct device *dev) · line 99

Quoted 5 lines
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +1 -0
+	of_node_put(np);
 	dev_info(dev, "Using TCON in bypass mode\n");
 
 	return tcon;

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 1/2
#6 lore raw
In reply to Fabio Estevam
Quoted 16 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

When devm_kzalloc() fails there is no need to assign an error code to the 'ret' variable as it will not be used after jumping to the 'err_node_put' label, so just remove the assignment.

---
 drivers/gpu/drm/fsl-dcu/fsl_tcon.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +0 -0
index 3194e54..2fbb7ee 100644

drivers/gpu/drm/fsl-dcu/fsl_tcon.c struct fsl_tcon *fsl_tcon_init(struct device *dev) · line 78

Quoted 8 lines
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +1 -3
@@ -72,10 +72,8 @@ struct fsl_tcon *fsl_tcon_init(struct device *dev)
 		return NULL;
 
 	tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
-	if (!tcon) {
-		ret = -ENOMEM;
+	if (!tcon)
 		goto err_node_put;
-	}

Hi Fabio,

I'm curious if it is ok to not have a tcon even for devices that support it? If we hit -ENOMEM here, I suppose we're likely hit it too for drm_dev_alloc and give up the initialization, so either way

drivers/gpu/drm/fsl-dcu/fsl_tcon.c struct fsl_tcon *fsl_tcon_init(struct device *dev) · line 79

Quoted 3 lines
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +0 -0
 	ret = fsl_tcon_init_regmap(dev, tcon, np);
 	if (ret) {

--
Gabriel Krisman Bertazi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Re: [PATCH 2/2] drm/fsl-dcu: check for clk_prepare_enable() error

In reply to Fabio Estevam
Quoted 6 lines · Fabio Estevam
Quoted 1 line · Gabriel Krisman Bertazi

This leaks tcon if clk_prepare_enable fails.

No, it does not as tcon is allocated via devm_kzalloc().

Agreed. But I think devm_kzalloc() only drops the memory once the device is removed, which is not the case here, since failing fsl_tcon_init is not fatal and the initialization continues in this case.

--
Gabriel Krisman Bertazi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#5 lore raw

Re: [PATCH 2/2] drm/fsl-dcu: check for clk_prepare_enable() error

Quoted 5 lines · Gabriel Krisman Bertazi
Quoted 3 lines · Fabio Estevam

On Wed, Dec 28, 2016 at 4:38 PM, Gabriel Krisman Bertazi <[email protected]> wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

This leaks tcon if clk_prepare_enable fails.

No, it does not as tcon is allocated via devm_kzalloc().

Agreed. But I think devm_kzalloc() only drops the memory once the device is removed, which is not the case here, since failing fsl_tcon_init is not fatal and the initialization continues in this case.

That is probably true, but does it matter? I guess it is anyway an unlikely case, so why bother?

--
Stefan
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Applied
#7 lore raw
In reply to Fabio Estevam
Quoted 7 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

When devm_kzalloc() fails there is no need to assign an error code to the 'ret' variable as it will not be used after jumping to the 'err_node_put' label, so just remove the assignment.

Applied both to my drm-fsl-dcu tree.

--
Stefan

Quoted 11 lines
---
 drivers/gpu/drm/fsl-dcu/fsl_tcon.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +0 -0
index 3194e54..2fbb7ee 100644
@@ -72,10 +72,8 @@ struct fsl_tcon *fsl_tcon_init(struct device *dev)
 		return NULL;

drivers/gpu/drm/fsl-dcu/fsl_tcon.c struct fsl_tcon *fsl_tcon_init(struct device *dev) · line 79

Quoted 10 lines
drivers/gpu/drm/fsl-dcu/fsl_tcon.c +1 -3
 
 	tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
-	if (!tcon) {
-		ret = -ENOMEM;
+	if (!tcon)
 		goto err_node_put;
-	}
 
 	ret = fsl_tcon_init_regmap(dev, tcon, np);
 	if (ret) {

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel