From 8c420c9181b5162829719564261683de0a4473fc Mon Sep 17 00:00:00 2001 From: rnoland Date: Fri, 30 Oct 2009 16:06:32 +0000 Subject: [PATCH] MFC r196464 Clean up the locking in drm_alloc_resource() git-svn-id: svn://svn.freebsd.org/base/stable/8@198679 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/drm/drm_bufs.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/sys/dev/drm/drm_bufs.c b/sys/dev/drm/drm_bufs.c index 647dee963..bd31b0ae3 100644 --- a/sys/dev/drm/drm_bufs.c +++ b/sys/dev/drm/drm_bufs.c @@ -45,27 +45,35 @@ __FBSDID("$FreeBSD$"); */ static int drm_alloc_resource(struct drm_device *dev, int resource) { + struct resource *res; + int rid; + + DRM_SPINLOCK_ASSERT(&dev->dev_lock); + if (resource >= DRM_MAX_PCI_RESOURCE) { DRM_ERROR("Resource %d too large\n", resource); return 1; } - DRM_UNLOCK(); if (dev->pcir[resource] != NULL) { - DRM_LOCK(); return 0; } - dev->pcirid[resource] = PCIR_BAR(resource); - dev->pcir[resource] = bus_alloc_resource_any(dev->device, - SYS_RES_MEMORY, &dev->pcirid[resource], RF_SHAREABLE); + DRM_UNLOCK(); + rid = PCIR_BAR(resource); + res = bus_alloc_resource_any(dev->device, SYS_RES_MEMORY, &rid, + RF_SHAREABLE); DRM_LOCK(); - - if (dev->pcir[resource] == NULL) { + if (res == NULL) { DRM_ERROR("Couldn't find resource 0x%x\n", resource); return 1; } + if (dev->pcir[resource] == NULL) { + dev->pcirid[resource] = rid; + dev->pcir[resource] = res; + } + return 0; } -- 2.45.0