Skip to contentSkip to conversation

Free pAMDGPUEnt memory in AMDGPUFreeRec

PATCH In review Michel Dänzer 2 participants 5 messages Oct 19, 2017 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Free pAMDGPUEnt memory in AMDGPUFreeRec

From: Michel Dänzer <[email protected]>

We were freeing it earlier but then still trying to access it in AMDGPUFreeRec.

---
 src/amdgpu_kms.c   | 2 ++
 src/amdgpu_probe.c | 8 ++------
 2 files changed, 4 insertions(+), 6 deletions(-)
src/amdgpu_kms.c +2 -0
index 3598dd23f..44a99b564 100644
@@ -138,6 +138,8 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
 		if (!pAMDGPUEnt->fd_ref) {
 			amdgpu_device_deinitialize(pAMDGPUEnt->pDev);
 			amdgpu_kernel_close_fd(pAMDGPUEnt);
+			free(pPriv->ptr);
+			pPriv->ptr = NULL;
 		}
 	}
 
src/amdgpu_probe.c +2 -6
index fb62cb811..e446539d6 100644
@@ -227,7 +227,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 
 		pAMDGPUEnt = pPriv->ptr;
 		if (!amdgpu_open_drm_master(pScrn, pAMDGPUEnt, busid))
-			goto error_fd;
+			goto error;
 
 		pAMDGPUEnt->fd_ref = 1;
 
@@ -255,8 +255,6 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 
 error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
-error_fd:
-	free(pPriv->ptr);
 error:
 	free(busid);
 	return FALSE;
@@ -352,7 +350,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 		pAMDGPUEnt->platform_dev = dev;
 		pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, busid, dev);
 		if (pAMDGPUEnt->fd < 0)
-			goto error_fd;
+			goto error;
 
 		pAMDGPUEnt->fd_ref = 1;
 
@@ -380,8 +378,6 @@ amdgpu_platform_probe(DriverPtr pDriver,
 
 error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
-error_fd:
-	free(pPriv->ptr);
 error:
 	free(busid);
 	return FALSE;
Signature · 6 lines
2.14.2

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

A message that is not in the archive (sent off-list or not yet received): 20171019160536.6569-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

#2 lore raw

PATCH 2/4 Free memory returned by xf86GetEntityInfo

From: Michel Dänzer <[email protected]>

We were leaking it.

---
 src/amdgpu_kms.c   | 19 +++++++++++++------
 src/amdgpu_probe.c |  6 ++++--
 2 files changed, 17 insertions(+), 8 deletions(-)
src/amdgpu_kms.c +13 -6
index 44a99b564..7d582095b 100644
@@ -116,16 +116,24 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
 	AMDGPUInfoPtr info;
+	EntityInfoPtr pEnt;
 
 	if (!pScrn)
 		return;
 
 	info = AMDGPUPTR(pScrn);
-	if (info && info->fbcon_pixmap)
-		pScrn->pScreen->DestroyPixmap(info->fbcon_pixmap);
+	if (info) {
+		if (info->fbcon_pixmap)
+			pScrn->pScreen->DestroyPixmap(info->fbcon_pixmap);
 
-	pPriv = xf86GetEntityPrivate(xf86GetEntityInfo(pScrn->entityList[pScrn->numEntities - 1])->index,
-				     gAMDGPUEntityIndex);
+		pEnt = info->pEnt;
+		free(pScrn->driverPrivate);
+		pScrn->driverPrivate = NULL;
+	} else {
+		pEnt = xf86GetEntityInfo(pScrn->entityList[pScrn->numEntities - 1]);
+	}
+
+	pPriv = xf86GetEntityPrivate(pEnt->index, gAMDGPUEntityIndex);
 	pAMDGPUEnt = pPriv->ptr;
 	if (pAMDGPUEnt->fd > 0) {
 		DevUnion *pPriv;
@@ -143,8 +151,7 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
 		}
 	}
 
-	free(pScrn->driverPrivate);
-	pScrn->driverPrivate = NULL;
+	free(pEnt);
 }
 
 static void *amdgpuShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset,
src/amdgpu_probe.c +4 -2
index e446539d6..021706088 100644
@@ -177,7 +177,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 {
 	ScrnInfoPtr pScrn = NULL;
 	char *busid;
-	EntityInfoPtr pEnt;
+	EntityInfoPtr pEnt = NULL;
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
 
@@ -256,6 +256,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
+	free(pEnt);
 	free(busid);
 	return FALSE;
 }
@@ -294,7 +295,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 	ScrnInfoPtr pScrn;
 	int scr_flags = 0;
 	char *busid;
-	EntityInfoPtr pEnt;
+	EntityInfoPtr pEnt = NULL;
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
 
@@ -379,6 +380,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
+	free(pEnt);
 	free(busid);
 	return FALSE;
 }
Signature · 6 lines
2.14.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#3 lore raw

PATCH 3/4 Call TimerFree for timer created in LeaveVT

In reply to a message not in the archive

From: Michel Dänzer <[email protected]>

We were leaking the memory allocated by TimerSet.

---
 src/amdgpu_kms.c | 1 +
 1 file changed, 1 insertion(+)
src/amdgpu_kms.c +1 -0
index 7d582095b..cb0fb3b57 100644
@@ -1624,6 +1624,7 @@ CARD32 cleanup_black_fb(OsTimerPtr timer, CARD32 now, pointer data)
 		drmmode_fb_reference(pAMDGPUEnt->fd, &drmmode_crtc->fb, NULL);
 	}
 
+	TimerFree(timer);
 	return 0;
 }
 
Signature · 6 lines
2.14.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#4 lore raw

PATCH 4/4 Always call drmModeFreeProperty after drmModeGetProperty

In reply to a message not in the archive

From: Michel Dänzer <[email protected]>

We were not doing so in all cases, leaking memory allocated by the latter.

---
 src/drmmode_display.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/drmmode_display.c +2 -2
index 3cbf2bd7d..2cef93cdd 100644
@@ -1891,8 +1891,8 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
 				drmModeFreeProperty(props);
 				break;
 			}
-			drmModeFreeProperty(props);
 		}
+		drmModeFreeProperty(props);
 	}
 
 	kencoders = calloc(sizeof(drmModeEncoderPtr), koutput->count_encoders);
@@ -1986,8 +1986,8 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
 				drmModeFreeProperty(props);
 				break;
 			}
-			drmModeFreeProperty(props);
 		}
+		drmModeFreeProperty(props);
 	}
 
 	if (dynamic) {
Signature · 6 lines
2.14.2

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

A message that is not in the archive (sent off-list or not yet received): 20171019160536.6569-4-michel-otUistvHUpPR7s880joybQ@public.gmane.org

Reviewed-by Alex Deucher
#6 lore raw

RE: [PATCH xf86-video-amdgpu 4/4] Always call drmModeFreeProperty after drmModeGetProperty

Quoted 8 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Michel Dänzer
Sent: Thursday, October 19, 2017 12:06 PM
To: [email protected]
Subject: [PATCH xf86-video-amdgpu 4/4] Always call drmModeFreeProperty after drmModeGetProperty

Quoted 6 lines

From: Michel Dänzer <[email protected]>

We were not doing so in all cases, leaking memory allocated by the latter.

Series is:

Quoted 34 lines
---
 src/drmmode_display.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/drmmode_display.c +0 -0
index 3cbf2bd7d..2cef93cdd 100644
@@ -1891,8 +1891,8 @@ drmmode_output_init(ScrnInfoPtr pScrn,

drmmode_ptr drmmode, drmModeResPtr mode_r

src/drmmode_display.c +1 -1
 				drmModeFreeProperty(props);
 				break;
 			}
-			drmModeFreeProperty(props);
 		}
+		drmModeFreeProperty(props);
 	}
 
 	kencoders = calloc(sizeof(drmModeEncoderPtr), koutput-
Quoted 1 line

count_encoders);

src/drmmode_display.c +0 -0
@@ -1986,8 +1986,8 @@ drmmode_output_init(ScrnInfoPtr pScrn,

drmmode_ptr drmmode, drmModeResPtr mode_r

src/drmmode_display.c +1 -2
 				drmModeFreeProperty(props);
 				break;
 			}
-			drmModeFreeProperty(props);
 		}
+		drmModeFreeProperty(props);
 	}
 
 	if (dynamic) {
--

2.14.2

Quoted 4 lines

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

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