Skip to contentSkip to conversation

Guard against pAMDGPUEnt == NULL in AMDGPUFreeRec

PATCH In review Michel Dänzer 2 participants 3 messages Feb 13, 2018 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Guard against pAMDGPUEnt == NULL in AMDGPUFreeRec

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

This can happen if PreInit fails early.

---
 src/amdgpu_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/amdgpu_kms.c +1 -1
index 7dc9e22a9..43c18d426 100644
@@ -137,7 +137,7 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
 
 	pPriv = xf86GetEntityPrivate(pEnt->index, gAMDGPUEntityIndex);
 	pAMDGPUEnt = pPriv->ptr;
-	if (pAMDGPUEnt->fd > 0) {
+	if (pAMDGPUEnt && pAMDGPUEnt->fd > 0) {
 		DevUnion *pPriv;
 		AMDGPUEntPtr pAMDGPUEnt;
 		pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
Signature · 6 lines
2.16.1

_______________________________________________
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): 20180213181239.11065-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

#2 lore raw

PATCH 2/2 Don't call AMDGPUFreeRec from AMDGPUPreInit_KMS

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

If the latter fails, Xorg will call AMDGPUFreeScreen_KMS, which calls the former.

---
 src/amdgpu_kms.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
src/amdgpu_kms.c +9 -13
index 43c18d426..f5874d3af 100644
@@ -1352,7 +1352,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 	    && info->pEnt->location.type != BUS_PLATFORM
 #endif
 	    )
-		goto fail;
+		return FALSE;
 
 	pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
 				     getAMDGPUEntityIndex());
@@ -1375,23 +1375,23 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 	pScrn->monitor = pScrn->confScreen->monitor;
 
 	if (!AMDGPUPreInitVisual(pScrn))
-		goto fail;
+		return FALSE;
 
 	xf86CollectOptions(pScrn, NULL);
 	if (!(info->Options = malloc(sizeof(AMDGPUOptions_KMS))))
-		goto fail;
+		return FALSE;
 
 	memcpy(info->Options, AMDGPUOptions_KMS, sizeof(AMDGPUOptions_KMS));
 	xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, info->Options);
 
 	if (!AMDGPUPreInitWeight(pScrn))
-		goto fail;
+		return FALSE;
 
 	memset(&gpu_info, 0, sizeof(gpu_info));
 	amdgpu_query_gpu_info(pAMDGPUEnt->pDev, &gpu_info);
 
 	if (!AMDGPUPreInitChipType_KMS(pScrn, &gpu_info))
-		goto fail;
+		return FALSE;
 
 	info->dri2.available = FALSE;
 	info->dri2.enabled = FALSE;
@@ -1399,7 +1399,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 	if (info->dri2.pKernelDRMVersion == NULL) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 			   "AMDGPUDRIGetVersion failed to get the DRM version\n");
-		goto fail;
+		return FALSE;
 	}
 
 	/* Get ScreenInit function */
@@ -1407,7 +1407,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 		return FALSE;
 
 	if (!AMDGPUPreInitAccel_KMS(pScrn))
-		goto fail;
+		return FALSE;
 
 	amdgpu_drm_queue_init();
 
@@ -1466,7 +1466,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 	    FALSE) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 			   "Kernel modesetting setup failed\n");
-		goto fail;
+		return FALSE;
 	}
 
 	AMDGPUSetupCapabilities(pScrn);
@@ -1518,14 +1518,10 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 #endif
 	    ) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
-		goto fail;
+		return FALSE;
 	}
 
 	return TRUE;
-fail:
-	AMDGPUFreeRec(pScrn);
-	return FALSE;
-
 }
 
 static Bool AMDGPUCursorInit_KMS(ScreenPtr pScreen)
Signature · 6 lines
2.16.1

_______________________________________________
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): 20180213181239.11065-2-michel-otUistvHUpPR7s880joybQ@public.gmane.org

Reviewed-by
#4 lore raw

Re: [PATCH xf86-video-amdgpu 2/2] Don't call AMDGPUFreeRec from AMDGPUPreInit_KMS

Quoted 6 lines · Michel Dänzer

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

If the latter fails, Xorg will call AMDGPUFreeScreen_KMS, which calls the former.

Series is:

Quoted 91 lines
---
 src/amdgpu_kms.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
src/amdgpu_kms.c +9 -14
index 43c18d426..f5874d3af 100644
@@ -1352,7 +1352,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
            && info->pEnt->location.type != BUS_PLATFORM
 #endif
            )
-               goto fail;
+               return FALSE;
 
        pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
                                     getAMDGPUEntityIndex());
@@ -1375,23 +1375,23 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
        pScrn->monitor = pScrn->confScreen->monitor;
 
        if (!AMDGPUPreInitVisual(pScrn))
-               goto fail;
+               return FALSE;
 
        xf86CollectOptions(pScrn, NULL);
        if (!(info->Options = malloc(sizeof(AMDGPUOptions_KMS))))
-               goto fail;
+               return FALSE;
 
        memcpy(info->Options, AMDGPUOptions_KMS, sizeof(AMDGPUOptions_KMS));
        xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, info->Options);
 
        if (!AMDGPUPreInitWeight(pScrn))
-               goto fail;
+               return FALSE;
 
        memset(&gpu_info, 0, sizeof(gpu_info));
        amdgpu_query_gpu_info(pAMDGPUEnt->pDev, &gpu_info);
 
        if (!AMDGPUPreInitChipType_KMS(pScrn, &gpu_info))
-               goto fail;
+               return FALSE;
 
        info->dri2.available = FALSE;
        info->dri2.enabled = FALSE;
@@ -1399,7 +1399,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
        if (info->dri2.pKernelDRMVersion == NULL) {
                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                           "AMDGPUDRIGetVersion failed to get the DRM version\n");
-               goto fail;
+               return FALSE;
        }
 
        /* Get ScreenInit function */
@@ -1407,7 +1407,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
                return FALSE;
 
        if (!AMDGPUPreInitAccel_KMS(pScrn))
-               goto fail;
+               return FALSE;
 
        amdgpu_drm_queue_init();
 
@@ -1466,7 +1466,7 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
            FALSE) {
                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                           "Kernel modesetting setup failed\n");
-               goto fail;
+               return FALSE;
        }
 
        AMDGPUSetupCapabilities(pScrn);
@@ -1518,14 +1518,10 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 #endif
            ) {
                xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
-               goto fail;
+               return FALSE;
        }
 
        return TRUE;
-fail:
-       AMDGPUFreeRec(pScrn);
-       return FALSE;
-
 }
 
 static Bool AMDGPUCursorInit_KMS(ScreenPtr pScreen)
--

2.16.1

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