Skip to content

Commit a34a0a6

Browse files
Conchy-ConchyLyude
authored andcommitted
drm: fix drm_dp_mst_port refcount leaks in drm_dp_mst_allocate_vcpi
drm_dp_mst_allocate_vcpi() invokes drm_dp_mst_topology_get_port_validated(), which increases the refcount of the "port". These reference counting issues take place in two exception handling paths separately. Either when “slots” is less than 0 or when drm_dp_init_vcpi() returns a negative value, the function forgets to reduce the refcnt increased drm_dp_mst_topology_get_port_validated(), which results in a refcount leak. Fix these issues by pulling up the error handling when "slots" is less than 0, and calling drm_dp_mst_topology_put_port() before termination when drm_dp_init_vcpi() returns a negative value. Fixes: 1e797f5 ("drm/dp: Split drm_dp_mst_allocate_vcpi") Cc: <[email protected]> # v4.12+ Signed-off-by: Xiyu Yang <[email protected]> Signed-off-by: Xin Tan <[email protected]> Signed-off-by: Xin Xiong <[email protected]> Reviewed-by: Lyude Paul <[email protected]> Signed-off-by: Lyude Paul <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20200719154545.GA41231@xin-virtual-machine
1 parent d88ca7e commit a34a0a6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/gpu/drm/drm_dp_mst_topology.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,11 +4308,11 @@ bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
43084308
{
43094309
int ret;
43104310

4311-
port = drm_dp_mst_topology_get_port_validated(mgr, port);
4312-
if (!port)
4311+
if (slots < 0)
43134312
return false;
43144313

4315-
if (slots < 0)
4314+
port = drm_dp_mst_topology_get_port_validated(mgr, port);
4315+
if (!port)
43164316
return false;
43174317

43184318
if (port->vcpi.vcpi > 0) {
@@ -4328,6 +4328,7 @@ bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
43284328
if (ret) {
43294329
DRM_DEBUG_KMS("failed to init vcpi slots=%d max=63 ret=%d\n",
43304330
DIV_ROUND_UP(pbn, mgr->pbn_div), ret);
4331+
drm_dp_mst_topology_put_port(port);
43314332
goto out;
43324333
}
43334334
DRM_DEBUG_KMS("initing vcpi for pbn=%d slots=%d\n",

0 commit comments

Comments
 (0)