From: oga Date: Sun, 17 Aug 2008 20:49:52 +0000 (+0000) Subject: Check the return value of agp_enable() instead of assuming it completed. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=be899aa0ceaaf35c892c2ccdabfe3dd1df53a827;p=openbsd Check the return value of agp_enable() instead of assuming it completed. apply some knf and other formatting while i'm at it. problem originally pointed out by Tobias Ulmer, thanks! --- diff --git a/sys/dev/pci/drm/drm_agpsupport.c b/sys/dev/pci/drm/drm_agpsupport.c index 9685aca11bb..9f383fd6be1 100644 --- a/sys/dev/pci/drm/drm_agpsupport.c +++ b/sys/dev/pci/drm/drm_agpsupport.c @@ -28,7 +28,7 @@ * */ -/** @file drm_agpsupport.c +/* * Support code for tying the kernel AGP support to DRM drivers and * the DRM's AGP ioctls. */ @@ -48,7 +48,7 @@ drm_device_is_agp(struct drm_device *dev) */ ret = (*dev->driver.device_is_agp)(dev); if (ret != DRM_MIGHT_BE_AGP) - return ret; + return (ret); } return (pci_get_capability(dev->pa.pa_pc, dev->pa.pa_tag, PCI_CAP_AGP, @@ -65,10 +65,10 @@ drm_device_is_pcie(struct drm_device *dev) int drm_agp_info(struct drm_device * dev, drm_agp_info_t *info) { - struct agp_info *kern; + struct agp_info *kern; - if (!dev->agp || !dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || !dev->agp->acquired) + return (EINVAL); kern = &dev->agp->info; #ifndef DRM_NO_AGP @@ -84,110 +84,102 @@ drm_agp_info(struct drm_device * dev, drm_agp_info_t *info) info->id_vendor = kern->ai_devid & 0xffff; info->id_device = kern->ai_devid >> 16; - return 0; + return (0); } int drm_agp_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - int err; - drm_agp_info_t info; + drm_agp_info_t *info = data; - err = drm_agp_info(dev, &info); - if (err != 0) - return err; - - *(drm_agp_info_t *)data = info; - return 0; + return (drm_agp_info(dev, info)); } int drm_agp_acquire_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - return drm_agp_acquire(dev); + return (drm_agp_acquire(dev)); } int drm_agp_acquire(struct drm_device *dev) { #ifndef DRM_NO_AGP - int retcode; + int retcode; - if (!dev->agp || dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || dev->agp->acquired) + return (EINVAL); retcode = agp_acquire(dev->agp->agpdev); if (retcode) - return retcode; + return (retcode); dev->agp->acquired = 1; #endif - return 0; + return (0); } int drm_agp_release_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - return drm_agp_release(dev); + return (drm_agp_release(dev)); } int drm_agp_release(struct drm_device * dev) { #ifndef DRM_NO_AGP - if (!dev->agp || !dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || !dev->agp->acquired) + return (EINVAL); agp_release(dev->agp->agpdev); dev->agp->acquired = 0; #endif - return 0; + return (0); } int drm_agp_enable(struct drm_device *dev, drm_agp_mode_t mode) { - + int retcode = 0; #ifndef DRM_NO_AGP - if (!dev->agp || !dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || !dev->agp->acquired) + return (EINVAL); dev->agp->mode = mode.mode; - agp_enable(dev->agp->agpdev, mode.mode); - dev->agp->enabled = 1; + if ((retcode = agp_enable(dev->agp->agpdev, mode.mode)) == 0) + dev->agp->enabled = 1; #endif - return 0; + return (retcode); } int drm_agp_enable_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - drm_agp_mode_t mode; - - mode = *(drm_agp_mode_t *)data; + drm_agp_mode_t *mode = data; - return drm_agp_enable(dev, mode); + return (drm_agp_enable(dev, *mode)); } int drm_agp_alloc(struct drm_device *dev, drm_agp_buffer_t *request) { #ifndef DRM_NO_AGP - struct drm_agp_mem *entry; - void *handle; - unsigned long pages; - u_int32_t type; - struct agp_memory_info info; + struct drm_agp_mem *entry; + void *handle; + struct agp_memory_info info; + unsigned long pages; + u_int32_t type; - if (!dev->agp || !dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || !dev->agp->acquired) + return (EINVAL); entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS); if (entry == NULL) - return ENOMEM; + return (ENOMEM); pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE; type = (u_int32_t)request->type; @@ -197,7 +189,7 @@ drm_agp_alloc(struct drm_device *dev, drm_agp_buffer_t *request) DRM_LOCK(); if (handle == NULL) { drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); - return ENOMEM; + return (ENOMEM); } entry->handle = handle; @@ -211,51 +203,46 @@ drm_agp_alloc(struct drm_device *dev, drm_agp_buffer_t *request) request->physical = info.ami_physical; #endif - return 0; + return (0); } int drm_agp_alloc_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - drm_agp_buffer_t request; - int retcode; - - request = *(drm_agp_buffer_t *)data; + drm_agp_buffer_t *request = data; + int retcode; DRM_LOCK(); - retcode = drm_agp_alloc(dev, &request); + retcode = drm_agp_alloc(dev, request); DRM_UNLOCK(); - - *(drm_agp_buffer_t *)data = request; - - return retcode; + return (retcode); } struct drm_agp_mem * drm_agp_lookup_entry(struct drm_device *dev, void *handle) { - struct drm_agp_mem *entry; + struct drm_agp_mem *entry; TAILQ_FOREACH(entry, &dev->agp->memory, link) { if (entry->handle == handle) - return entry; + break; } - return NULL; + return (entry); } int drm_agp_unbind(struct drm_device *dev, drm_agp_binding_t *request) { - struct drm_agp_mem *entry; - int retcode; + struct drm_agp_mem *entry; + int retcode; - if (!dev->agp || !dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || !dev->agp->acquired) + return (EINVAL); entry = drm_agp_lookup_entry(dev, (void *)request->handle); if (entry == NULL || !entry->bound) - return EINVAL; + return (EINVAL); DRM_UNLOCK(); retcode = drm_agp_unbind_memory(entry->handle); @@ -264,40 +251,37 @@ drm_agp_unbind(struct drm_device *dev, drm_agp_binding_t *request) if (retcode == 0) entry->bound = 0; - return retcode; + return (retcode); } int drm_agp_unbind_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - drm_agp_binding_t request; - int retcode; - - request = *(drm_agp_binding_t *)data; + drm_agp_binding_t *request = data; + int retcode; DRM_LOCK(); - retcode = drm_agp_unbind(dev, &request); + retcode = drm_agp_unbind(dev, request); DRM_UNLOCK(); - return retcode; + return (retcode); } int drm_agp_bind(struct drm_device *dev, drm_agp_binding_t *request) { - struct drm_agp_mem *entry; - int retcode; - int page; + struct drm_agp_mem *entry; + int retcode, page; - if (!dev->agp || !dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || !dev->agp->acquired) + return (EINVAL); DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE); entry = drm_agp_lookup_entry(dev, (void *)request->handle); if (entry == NULL || entry->bound) - return EINVAL; + return (EINVAL); page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE; @@ -307,36 +291,34 @@ drm_agp_bind(struct drm_device *dev, drm_agp_binding_t *request) if (retcode == 0) entry->bound = dev->agp->base + (page << PAGE_SHIFT); - return retcode; + return (retcode); } int drm_agp_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - drm_agp_binding_t request; - int retcode; - - request = *(drm_agp_binding_t *)data; + drm_agp_binding_t *request = data; + int retcode; DRM_LOCK(); - retcode = drm_agp_bind(dev, &request); + retcode = drm_agp_bind(dev, request); DRM_UNLOCK(); - return retcode; + return (retcode); } int drm_agp_free(struct drm_device *dev, drm_agp_buffer_t *request) { - struct drm_agp_mem *entry; + struct drm_agp_mem *entry; - if (!dev->agp || !dev->agp->acquired) - return EINVAL; + if (dev->agp == NULL || !dev->agp->acquired) + return (EINVAL); entry = drm_agp_lookup_entry(dev, (void*)request->handle); if (entry == NULL) - return EINVAL; + return (EINVAL); TAILQ_REMOVE(&dev->agp->memory, entry, link); @@ -348,7 +330,7 @@ drm_agp_free(struct drm_device *dev, drm_agp_buffer_t *request) drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); - return 0; + return (0); } @@ -356,28 +338,26 @@ int drm_agp_free_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - drm_agp_buffer_t request; - int retcode; - - request = *(drm_agp_buffer_t *)data; + drm_agp_buffer_t *request = data; + int retcode; DRM_LOCK(); - retcode = drm_agp_free(dev, &request); + retcode = drm_agp_free(dev, request); DRM_UNLOCK(); - return retcode; + return (retcode); } drm_agp_head_t * drm_agp_init(void) { #ifndef DRM_NO_AGP - struct device *agpdev; - drm_agp_head_t *head = NULL; - int agp_available = 1; + struct device *agpdev; + drm_agp_head_t *head = NULL; + int agp_available = 1; agpdev = DRM_AGP_FIND_DEVICE(); - if (!agpdev) + if (agpdev == NULL) agp_available = 0; DRM_DEBUG("agp_available = %d\n", agp_available); @@ -385,13 +365,13 @@ drm_agp_init(void) if (agp_available) { head = drm_calloc(1, sizeof(*head), DRM_MEM_AGPLISTS); if (head == NULL) - return NULL; + return (NULL); head->agpdev = agpdev; agp_get_info(agpdev, &head->info); head->base = head->info.ai_aperture_base; TAILQ_INIT(&head->memory); } - return head; + return (head); #else return (NULL); #endif @@ -400,41 +380,41 @@ drm_agp_init(void) void * drm_agp_allocate_memory(size_t pages, u32 type) { - struct device *agpdev; + struct device *agpdev; agpdev = DRM_AGP_FIND_DEVICE(); - if (!agpdev) - return NULL; + if (agpdev == NULL) + return (NULL); - return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT); + return (agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT)); } int drm_agp_free_memory(void *handle) { - struct device *agpdev; + struct device *agpdev; agpdev = DRM_AGP_FIND_DEVICE(); - if (!agpdev || !handle) - return 0; + if (agpdev == NULL || handle == NULL) + return (0); agp_free_memory(agpdev, handle); - return 1; + return (1); } int drm_agp_bind_memory(void *handle, off_t start) { #ifndef DRM_NO_AGP - struct device *agpdev; + struct device *agpdev; agpdev = DRM_AGP_FIND_DEVICE(); - if (!agpdev || !handle) - return EINVAL; + if (agpdev == NULL || handle == NULL) + return (EINVAL); - return agp_bind_memory(agpdev, handle, start * PAGE_SIZE); + return (agp_bind_memory(agpdev, handle, start * PAGE_SIZE)); #else - return 0; + return (0); #endif } @@ -442,14 +422,14 @@ int drm_agp_unbind_memory(void *handle) { #ifndef DRM_NO_AGP - struct device *agpdev; + struct device *agpdev; agpdev = DRM_AGP_FIND_DEVICE(); - if (!agpdev || !handle) - return EINVAL; + if (agpdev == NULL || handle == NULL) + return (EINVAL); - return agp_unbind_memory(agpdev, handle); + return (agp_unbind_memory(agpdev, handle)); #else - return 0; + return (0); #endif }