summaryrefslogtreecommitdiff
path: root/src/amdgpu_probe.c
diff options
context:
space:
mode:
authorJammy Zhou <Jammy.Zhou@amd.com>2015-10-28 21:24:29 +0800
committerMichel Dänzer <michel@daenzer.net>2015-10-30 18:25:48 +0900
commitedf72afee3a25eae9827b4de3a013b541b78e213 (patch)
tree82518851942b8149f0d69a0a6e6539289d1901bb /src/amdgpu_probe.c
parentcef725121eb0e56aa54d9c4665e36047373f4db7 (diff)
Fix crash in PCI probe path (v4)
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. v4: (md) Remove unused parameter entity_num, split out logically separate changes v3: some more cleanup v2: switch to pAMDGPUEnt->fd, and update the commit message Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v3)
Diffstat (limited to 'src/amdgpu_probe.c')
-rw-r--r--src/amdgpu_probe.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index 28430b2..444e9b6 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -147,14 +147,14 @@ 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,
+ struct pci_device *pci_dev)
{
- AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
drmSetVersion sv;
int err;
- info->dri2.drm_fd = amdgpu_kernel_open_fd(pScrn, info->PciInfo, NULL);
- if (info->dri2.drm_fd == -1)
+ pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, pci_dev, NULL);
+ if (pAMDGPUEnt->fd == -1)
return FALSE;
/* Check that what we opened was a master or a master-capable FD,
@@ -165,11 +165,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;
}
@@ -226,11 +226,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, pci_dev))
goto error_fd;
- }
pAMDGPUEnt->fd_ref = 1;