[PATCH xf86-video-amdgpu] Fix crash in PCI probe path (v2)
Jammy Zhou
Jammy.Zhou at amd.com
Mon Oct 26 19:23:31 PDT 2015
The crash is caused by the NULL value returned by AMDGPUPTR(pScrn),
because the driverPrivate is not allocated yet in PciProbe phase,
and it is usually done in the PreInit phase.
Use pAMDGPUEnt->fd instead of info->dri2.drm_fd to avoid AMDGPUInfoPtr
related code in amdgpu_open_drm_master, so that the crash can be fixed.
v2: switch to pAMDGPUEnt->fd, and update the commit message
Change-Id: I817c5f2324780b1b3ab51a366192c11ef4fff990
Signed-off-by: Jammy Zhou <Jammy.Zhou at amd.com>
---
src/amdgpu_probe.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index 481271b..ae78233 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -147,10 +147,10 @@ static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, struct pci_device *dev,
return fd;
}
-static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn)
+static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn,
+ AMDGPUEntPtr pAMDGPUEnt, int entity_num)
{
- AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
- AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(pScrn);
+ struct pci_device *dev;
drmSetVersion sv;
int err;
@@ -158,13 +158,13 @@ static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn)
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
" reusing fd for second head\n");
- info->drmmode.fd = info->dri2.drm_fd = pAMDGPUEnt->fd;
pAMDGPUEnt->fd_ref++;
return TRUE;
}
- info->dri2.drm_fd = amdgpu_kernel_open_fd(pScrn, info->PciInfo, NULL);
- if (info->dri2.drm_fd == -1)
+ dev = xf86GetPciInfoForEntity(entity_num);
+ pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, dev, NULL);
+ if (pAMDGPUEnt->fd == -1)
return FALSE;
/* Check that what we opened was a master or a master-capable FD,
@@ -175,11 +175,11 @@ static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn)
sv.drm_di_minor = 1;
sv.drm_dd_major = -1;
sv.drm_dd_minor = -1;
- err = drmSetInterfaceVersion(info->dri2.drm_fd, &sv);
+ err = drmSetInterfaceVersion(pAMDGPUEnt->fd, &sv);
if (err != 0) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[drm] failed to set drm interface version.\n");
- drmClose(info->dri2.drm_fd);
+ drmClose(pAMDGPUEnt->fd);
return FALSE;
}
@@ -236,11 +236,12 @@ static Bool amdgpu_get_scrninfo(int entity_num, void *pci_dev)
uint32_t minor_version;
pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
- pAMDGPUEnt = pPriv->ptr;
+ if (!pPriv->ptr)
+ return FALSE;
- if (amdgpu_open_drm_master(pScrn)) {
+ pAMDGPUEnt = pPriv->ptr;
+ if (!amdgpu_open_drm_master(pScrn, pAMDGPUEnt, entity_num))
goto error_fd;
- }
pAMDGPUEnt->fd_ref = 1;
--
1.9.1
More information about the xorg-driver-ati
mailing list