Skip to contentSkip to conversation

drm/exynos: free DP if probe fails to find a panel or bridge

PATCH In review Gustavo Padovan 5 participants 9 messages Nov 20, 2014 – Nov 24, 2014

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

PATCH 1/3 drm/exynos: free DP if probe fails to find a panel or bridge

From: Gustavo Padovan <[email protected]>

DP was leaked everytime function returns EPROBE_DEFER, free it before returning.

---
 drivers/gpu/drm/exynos/exynos_dp_core.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +15 -6
index 85762cf..6fd4a46 100644
@@ -1336,8 +1336,10 @@ static int exynos_dp_probe(struct platform_device *pdev)
 	if (panel_node) {
 		dp->panel = of_drm_find_panel(panel_node);
 		of_node_put(panel_node);
-		if (!dp->panel)
-			return -EPROBE_DEFER;
+		if (!dp->panel) {
+			ret = -EPROBE_DEFER;
+			goto free_dp;
+		}
 	}
 
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
@@ -1346,10 +1348,14 @@ static int exynos_dp_probe(struct platform_device *pdev)
 		if (bridge_node) {
 			dp->bridge = of_drm_find_bridge(bridge_node);
 			of_node_put(bridge_node);
-			if (!dp->bridge)
-				return -EPROBE_DEFER;
-		} else
-			return -EPROBE_DEFER;
+			if (!dp->bridge) {
+				ret = -EPROBE_DEFER;
+				goto free_dp;
+			}
+		} else {
+			ret = -EPROBE_DEFER;
+			goto free_dp;
+		}
 	}
 
 	exynos_dp_display.ctx = dp;
@@ -1359,6 +1365,9 @@ static int exynos_dp_probe(struct platform_device *pdev)
 		exynos_drm_component_del(&pdev->dev,
 						EXYNOS_DEVICE_TYPE_CONNECTOR);
 
+free_dp:
+	devm_kfree(dev, dp);
+
 	return ret;
 }
 
Signature · 6 lines
1.9.3

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

PATCH 2/3 drm/exynos: avoid race condition when adding a drm component

From: Gustavo Padovan <[email protected]>

exynos_drm_component_add() correctly checks if a component is present on drm_component_list however it release the lock right after the check and before we add the new component to the list. That just creates room to add the same component more than once to the list.

The lock should be held for the whole journey while adding a new component.

---
 drivers/gpu/drm/exynos/exynos_drm_drv.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_drv.c +5 -11
index cb3ed9b..230573d 100644
@@ -402,10 +402,8 @@ int exynos_drm_component_add(struct device *dev,
 			 * added already just return.
 			 */
 			if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC |
-						EXYNOS_DEVICE_TYPE_CONNECTOR)) {
-				mutex_unlock(&drm_component_lock);
-				return 0;
-			}
+						EXYNOS_DEVICE_TYPE_CONNECTOR))
+				goto unlock;
 
 			if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
 				cdev->crtc_dev = dev;
@@ -417,14 +415,11 @@ int exynos_drm_component_add(struct device *dev,
 				cdev->dev_type_flag |= dev_type;
 			}
 
-			mutex_unlock(&drm_component_lock);
-			return 0;
+			goto unlock;
 		}
 	}
 
-	mutex_unlock(&drm_component_lock);
-
-	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
+	cdev = kzalloc(sizeof(*cdev), GFP_ATOMIC);
 	if (!cdev)
 		return -ENOMEM;
 
@@ -436,10 +431,9 @@ int exynos_drm_component_add(struct device *dev,
 	cdev->out_type = out_type;
 	cdev->dev_type_flag = dev_type;
 
-	mutex_lock(&drm_component_lock);
 	list_add_tail(&cdev->list, &drm_component_list);
+unlock:
 	mutex_unlock(&drm_component_lock);
-
 	return 0;
 }
 
Signature · 6 lines
1.9.3

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

Re: [PATCH 2/3] drm/exynos: avoid race condition when adding a drm component

Quoted 6 lines · Gustavo Padovan

From: Gustavo Padovan <[email protected]>

exynos_drm_component_add() correctly checks if a component is present on drm_component_list however it release the lock right after the check and before we add the new component to the list. That just creates room to add the same component more than once to the list.

A little bit strange. drm_component_list is protected from race condition with mutex_lock. How the same component can be added to the drm_component_list again? And a new cdev object cannot be same cdev object already added to the drm_component_list because the new cdev object is allocated by kzalloc(). And the only case the same kms driver can request to add a new cdev to drm_component_list again is when the probe of the driver failed. However, in this case, the driver will call exynos_drm_component_del function to remove previous cdev. So the same cdev cannot be added to the drm_component_list even in such case.

Thanks,
Inki Dae

Quoted 46 lines

The lock should be held for the whole journey while adding a new component.

---
 drivers/gpu/drm/exynos/exynos_drm_drv.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_drv.c +4 -9
index cb3ed9b..230573d 100644
@@ -402,10 +402,8 @@ int exynos_drm_component_add(struct device *dev,
 			 * added already just return.
 			 */
 			if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC |
-						EXYNOS_DEVICE_TYPE_CONNECTOR)) {
-				mutex_unlock(&drm_component_lock);
-				return 0;
-			}
+						EXYNOS_DEVICE_TYPE_CONNECTOR))
+				goto unlock;
 
 			if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
 				cdev->crtc_dev = dev;
@@ -417,14 +415,11 @@ int exynos_drm_component_add(struct device *dev,
 				cdev->dev_type_flag |= dev_type;
 			}
 
-			mutex_unlock(&drm_component_lock);
-			return 0;
+			goto unlock;
 		}
 	}
 
-	mutex_unlock(&drm_component_lock);
-
-	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
+	cdev = kzalloc(sizeof(*cdev), GFP_ATOMIC);
 	if (!cdev)
 		return -ENOMEM;
 
@@ -436,10 +431,9 @@ int exynos_drm_component_add(struct device *dev,
 	cdev->out_type = out_type;

drivers/gpu/drm/exynos/exynos_drm_drv.c int exynos_drm_component_add(struct device *dev, · line 439

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +1 -2
 	cdev->dev_type_flag = dev_type;
 
-	mutex_lock(&drm_component_lock);
 	list_add_tail(&cdev->list, &drm_component_list);
+unlock:
 	mutex_unlock(&drm_component_lock);
-
 	return 0;
 }
 

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

#3 lore raw

Re: [PATCH 2/3] drm/exynos: avoid race condition when adding a drm component

2014-11-21 Inki Dae <[email protected]>:

Quoted 8 lines · Gustavo Padovan
Quoted 6 lines

From: Gustavo Padovan <[email protected]>

exynos_drm_component_add() correctly checks if a component is present on drm_component_list however it release the lock right after the check and before we add the new component to the list. That just creates room to add the same component more than once to the list.

Quoted 9 lines

A little bit strange. drm_component_list is protected from race condition with mutex_lock. How the same component can be added to the drm_component_list again? And a new cdev object cannot be same cdev object already added to the drm_component_list because the new cdev object is allocated by kzalloc(). And the only case the same kms driver can request to add a new cdev to drm_component_list again is when the probe of the driver failed. However, in this case, the driver will call exynos_drm_component_del function to remove previous cdev. So the same cdev cannot be added to the drm_component_list even in such case.

Hmm, right. I haven't payed attention that each one of them is called just once. I did this patch in my first days working with this code so I ignored what exynos_drm_component_add() was really doing.

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

#4 lore raw

PATCH 3/3 drm/exynos: avoid leak if exynos_dpi_probe() fails

In reply to Gustavo Padovan

From: Gustavo Padovan <[email protected]>

The component must be deleted if the probe fails.

---
 drivers/gpu/drm/exynos/exynos_drm_fimd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fimd.c +4 -2
index 0673a39..173d135 100644
@@ -1202,8 +1202,10 @@ static int fimd_probe(struct platform_device *pdev)
 	fimd_manager.ctx = ctx;
 
 	ctx->display = exynos_dpi_probe(dev);
-	if (IS_ERR(ctx->display))
-		return PTR_ERR(ctx->display);
+	if (IS_ERR(ctx->display)) {
+		ret = PTR_ERR(ctx->display);
+		goto err_del_component;
+	}
 
 	pm_runtime_enable(&pdev->dev);
 
Signature · 6 lines
1.9.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
In reply to Gustavo Padovan

Hi Gustavo,

Quoted 47 lines · Gustavo Padovan

From: Gustavo Padovan <[email protected]>

DP was leaked everytime function returns EPROBE_DEFER, free it before returning.

---
 drivers/gpu/drm/exynos/exynos_dp_core.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +12 -6
index 85762cf..6fd4a46 100644
@@ -1336,8 +1336,10 @@ static int exynos_dp_probe(struct platform_device *pdev)
        if (panel_node) {
                dp->panel = of_drm_find_panel(panel_node);
                of_node_put(panel_node);
-               if (!dp->panel)
-                       return -EPROBE_DEFER;
+               if (!dp->panel) {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
@@ -1346,10 +1348,14 @@ static int exynos_dp_probe(struct platform_device *pdev)
                if (bridge_node) {
                        dp->bridge = of_drm_find_bridge(bridge_node);
                        of_node_put(bridge_node);
-                       if (!dp->bridge)
-                               return -EPROBE_DEFER;
-               } else
-                       return -EPROBE_DEFER;
+                       if (!dp->bridge) {
+                               ret = -EPROBE_DEFER;
+                               goto free_dp;
+                       }
+               } else {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        exynos_dp_display.ctx = dp;

drivers/gpu/drm/exynos/exynos_dp_core.c static int exynos_dp_probe(struct platform_device *pdev) · line 1369

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +2 -0
@@ -1359,6 +1365,9 @@ static int exynos_dp_probe(struct platform_device *pdev)
                exynos_drm_component_del(&pdev->dev,
                                                EXYNOS_DEVICE_TYPE_CONNECTOR);
 
+free_dp:
+       devm_kfree(dev, dp);

I guess the driver core takes care of freeing the devm memory when the probe fails?
Will it not happen during PROBE_DEFER?

Inki/Jingoo - Is this change really necessary?

Ajay

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +0 -1
        return ret;
 }
 
--

1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

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

#6 lore raw
Quoted 52 lines · Ajay kumar
Quoted 50 lines · Gustavo Padovan

From: Gustavo Padovan <[email protected]>

DP was leaked everytime function returns EPROBE_DEFER, free it before returning.

---
 drivers/gpu/drm/exynos/exynos_dp_core.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +12 -6
index 85762cf..6fd4a46 100644
@@ -1336,8 +1336,10 @@ static int exynos_dp_probe(struct platform_device *pdev)
        if (panel_node) {
                dp->panel = of_drm_find_panel(panel_node);
                of_node_put(panel_node);
-               if (!dp->panel)
-                       return -EPROBE_DEFER;
+               if (!dp->panel) {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
@@ -1346,10 +1348,14 @@ static int exynos_dp_probe(struct platform_device *pdev)
                if (bridge_node) {
                        dp->bridge = of_drm_find_bridge(bridge_node);
                        of_node_put(bridge_node);
-                       if (!dp->bridge)
-                               return -EPROBE_DEFER;
-               } else
-                       return -EPROBE_DEFER;
+                       if (!dp->bridge) {
+                               ret = -EPROBE_DEFER;
+                               goto free_dp;
+                       }
+               } else {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        exynos_dp_display.ctx = dp;
@@ -1359,6 +1365,9 @@ static int exynos_dp_probe(struct platform_device *pdev)
                exynos_drm_component_del(&pdev->dev,
                                                EXYNOS_DEVICE_TYPE_CONNECTOR);
 
Quoted 7 lines

drivers/gpu/drm/exynos/exynos_dp_core.c static int exynos_dp_probe(struct platform_device *pdev) · line 1369

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +2 -0
+free_dp:
+       devm_kfree(dev, dp);

I guess the driver core takes care of freeing the devm memory when the probe fails?
Will it not happen during PROBE_DEFER?

Inki/Jingoo - Is this change really necessary?

As far as I know, this devm_kfree() in unnecessary, even though PROBE_DEFER is returned.
If I am wrong, please let me know. Thanks.

Best regards,
Jingoo Han

Quoted 13 lines

Ajay

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +0 -1
        return ret;
 }
 
--

1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#7 lore raw
In reply to Gustavo Padovan

2014-11-21 8:54 GMT+09:00 Gustavo Padovan <[email protected]>:

Quoted 4 lines

From: Gustavo Padovan <[email protected]>

DP was leaked everytime function returns EPROBE_DEFER, free it before returning.

It seems that you misunderstood devm_* api.

Thanks,
Inki Dae

Quoted 59 lines
---
 drivers/gpu/drm/exynos/exynos_dp_core.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +15 -7
index 85762cf..6fd4a46 100644
@@ -1336,8 +1336,10 @@ static int exynos_dp_probe(struct platform_device *pdev)
        if (panel_node) {
                dp->panel = of_drm_find_panel(panel_node);
                of_node_put(panel_node);
-               if (!dp->panel)
-                       return -EPROBE_DEFER;
+               if (!dp->panel) {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
@@ -1346,10 +1348,14 @@ static int exynos_dp_probe(struct platform_device *pdev)
                if (bridge_node) {
                        dp->bridge = of_drm_find_bridge(bridge_node);
                        of_node_put(bridge_node);
-                       if (!dp->bridge)
-                               return -EPROBE_DEFER;
-               } else
-                       return -EPROBE_DEFER;
+                       if (!dp->bridge) {
+                               ret = -EPROBE_DEFER;
+                               goto free_dp;
+                       }
+               } else {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        exynos_dp_display.ctx = dp;
@@ -1359,6 +1365,9 @@ static int exynos_dp_probe(struct platform_device *pdev)
                exynos_drm_component_del(&pdev->dev,
                                                EXYNOS_DEVICE_TYPE_CONNECTOR);
 
+free_dp:
+       devm_kfree(dev, dp);
+
        return ret;
 }
 
--

1.9.3

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

#8 lore raw

2014-11-22 Inki Dae <[email protected]>:

Quoted 7 lines

2014-11-21 8:54 GMT+09:00 Gustavo Padovan <[email protected]>:

Quoted 4 lines

From: Gustavo Padovan <[email protected]>

DP was leaked everytime function returns EPROBE_DEFER, free it before returning.

It seems that you misunderstood devm_* api.

Yeah, I though it would only free memory at unload of the module but it also free it when the probe fails.

Quoted 56 lines

Thanks,
Inki Dae

Quoted 52 lines
---
 drivers/gpu/drm/exynos/exynos_dp_core.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +15 -6
index 85762cf..6fd4a46 100644
@@ -1336,8 +1336,10 @@ static int exynos_dp_probe(struct platform_device *pdev)
        if (panel_node) {
                dp->panel = of_drm_find_panel(panel_node);
                of_node_put(panel_node);
-               if (!dp->panel)
-                       return -EPROBE_DEFER;
+               if (!dp->panel) {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
@@ -1346,10 +1348,14 @@ static int exynos_dp_probe(struct platform_device *pdev)
                if (bridge_node) {
                        dp->bridge = of_drm_find_bridge(bridge_node);
                        of_node_put(bridge_node);
-                       if (!dp->bridge)
-                               return -EPROBE_DEFER;
-               } else
-                       return -EPROBE_DEFER;
+                       if (!dp->bridge) {
+                               ret = -EPROBE_DEFER;
+                               goto free_dp;
+                       }
+               } else {
+                       ret = -EPROBE_DEFER;
+                       goto free_dp;
+               }
        }
 
        exynos_dp_display.ctx = dp;
@@ -1359,6 +1365,9 @@ static int exynos_dp_probe(struct platform_device *pdev)
                exynos_drm_component_del(&pdev->dev,
                                                EXYNOS_DEVICE_TYPE_CONNECTOR);
 
+free_dp:
+       devm_kfree(dev, dp);
+
        return ret;
 }
 
Quoted 7 lines
Quoted 7 lines

--
1.9.3

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

Gustavo