diff options
author | Dave Airlie <airlied@linux.ie> | 2007-05-25 15:01:51 -0400 |
---|---|---|
committer | Dave Airlie <airlied@linux.ie> | 2007-07-10 21:58:02 -0400 |
commit | bd1b331fae2813d9f03ceee649296f02edc0b893 (patch) | |
tree | 6139f72ebae88c332c754745f3d98cbe794ae4de /drivers/char/drm/drm_bufs.c | |
parent | 4eb6bf6bfb580afaf1e1a1d30cba17a078530cf4 (diff) |
drm: cleanup use of Linux list handling macros
This makes the drms use of the list handling macros a lot cleaner
and more along the lines of how they should be used and uses them
in some more places.
Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char/drm/drm_bufs.c')
-rw-r--r-- | drivers/char/drm/drm_bufs.c | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c index c11345856ffe..dac057879594 100644 --- a/drivers/char/drm/drm_bufs.c +++ b/drivers/char/drm/drm_bufs.c | |||
@@ -52,10 +52,8 @@ EXPORT_SYMBOL(drm_get_resource_len); | |||
52 | static drm_map_list_t *drm_find_matching_map(drm_device_t *dev, | 52 | static drm_map_list_t *drm_find_matching_map(drm_device_t *dev, |
53 | drm_local_map_t *map) | 53 | drm_local_map_t *map) |
54 | { | 54 | { |
55 | struct list_head *list; | 55 | drm_map_list_t *entry; |
56 | 56 | list_for_each_entry(entry, &dev->maplist, head) { | |
57 | list_for_each(list, &dev->maplist->head) { | ||
58 | drm_map_list_t *entry = list_entry(list, drm_map_list_t, head); | ||
59 | if (entry->map && map->type == entry->map->type && | 57 | if (entry->map && map->type == entry->map->type && |
60 | ((entry->map->offset == map->offset) || | 58 | ((entry->map->offset == map->offset) || |
61 | (map->type == _DRM_SHM && map->flags==_DRM_CONTAINS_LOCK))) { | 59 | (map->type == _DRM_SHM && map->flags==_DRM_CONTAINS_LOCK))) { |
@@ -237,14 +235,14 @@ static int drm_addmap_core(drm_device_t * dev, unsigned int offset, | |||
237 | * skipped and we double check that dev->agp->memory is | 235 | * skipped and we double check that dev->agp->memory is |
238 | * actually set as well as being invalid before EPERM'ing | 236 | * actually set as well as being invalid before EPERM'ing |
239 | */ | 237 | */ |
240 | for (entry = dev->agp->memory; entry; entry = entry->next) { | 238 | list_for_each_entry(entry, &dev->agp->memory, head) { |
241 | if ((map->offset >= entry->bound) && | 239 | if ((map->offset >= entry->bound) && |
242 | (map->offset + map->size <= entry->bound + entry->pages * PAGE_SIZE)) { | 240 | (map->offset + map->size <= entry->bound + entry->pages * PAGE_SIZE)) { |
243 | valid = 1; | 241 | valid = 1; |
244 | break; | 242 | break; |
245 | } | 243 | } |
246 | } | 244 | } |
247 | if (dev->agp->memory && !valid) { | 245 | if (!list_empty(&dev->agp->memory) && !valid) { |
248 | drm_free(map, sizeof(*map), DRM_MEM_MAPS); | 246 | drm_free(map, sizeof(*map), DRM_MEM_MAPS); |
249 | return -EPERM; | 247 | return -EPERM; |
250 | } | 248 | } |
@@ -289,7 +287,7 @@ static int drm_addmap_core(drm_device_t * dev, unsigned int offset, | |||
289 | list->map = map; | 287 | list->map = map; |
290 | 288 | ||
291 | mutex_lock(&dev->struct_mutex); | 289 | mutex_lock(&dev->struct_mutex); |
292 | list_add(&list->head, &dev->maplist->head); | 290 | list_add(&list->head, &dev->maplist); |
293 | 291 | ||
294 | /* Assign a 32-bit handle */ | 292 | /* Assign a 32-bit handle */ |
295 | /* We do it here so that dev->struct_mutex protects the increment */ | 293 | /* We do it here so that dev->struct_mutex protects the increment */ |
@@ -380,29 +378,24 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp, | |||
380 | */ | 378 | */ |
381 | int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map) | 379 | int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map) |
382 | { | 380 | { |
383 | struct list_head *list; | 381 | drm_map_list_t *r_list = NULL, *list_t; |
384 | drm_map_list_t *r_list = NULL; | ||
385 | drm_dma_handle_t dmah; | 382 | drm_dma_handle_t dmah; |
383 | int found = 0; | ||
386 | 384 | ||
387 | /* Find the list entry for the map and remove it */ | 385 | /* Find the list entry for the map and remove it */ |
388 | list_for_each(list, &dev->maplist->head) { | 386 | list_for_each_entry_safe(r_list, list_t, &dev->maplist, head) { |
389 | r_list = list_entry(list, drm_map_list_t, head); | ||
390 | |||
391 | if (r_list->map == map) { | 387 | if (r_list->map == map) { |
392 | list_del(list); | 388 | list_del(&r_list->head); |
393 | drm_ht_remove_key(&dev->map_hash, | 389 | drm_ht_remove_key(&dev->map_hash, |
394 | r_list->user_token >> PAGE_SHIFT); | 390 | r_list->user_token >> PAGE_SHIFT); |
395 | drm_free(list, sizeof(*list), DRM_MEM_MAPS); | 391 | drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS); |
392 | found = 1; | ||
396 | break; | 393 | break; |
397 | } | 394 | } |
398 | } | 395 | } |
399 | 396 | ||
400 | /* List has wrapped around to the head pointer, or it's empty and we | 397 | if (!found) |
401 | * didn't find anything. | ||
402 | */ | ||
403 | if (list == (&dev->maplist->head)) { | ||
404 | return -EINVAL; | 398 | return -EINVAL; |
405 | } | ||
406 | 399 | ||
407 | switch (map->type) { | 400 | switch (map->type) { |
408 | case _DRM_REGISTERS: | 401 | case _DRM_REGISTERS: |
@@ -460,7 +453,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp, | |||
460 | drm_device_t *dev = priv->head->dev; | 453 | drm_device_t *dev = priv->head->dev; |
461 | drm_map_t request; | 454 | drm_map_t request; |
462 | drm_local_map_t *map = NULL; | 455 | drm_local_map_t *map = NULL; |
463 | struct list_head *list; | 456 | drm_map_list_t *r_list; |
464 | int ret; | 457 | int ret; |
465 | 458 | ||
466 | if (copy_from_user(&request, (drm_map_t __user *) arg, sizeof(request))) { | 459 | if (copy_from_user(&request, (drm_map_t __user *) arg, sizeof(request))) { |
@@ -468,9 +461,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp, | |||
468 | } | 461 | } |
469 | 462 | ||
470 | mutex_lock(&dev->struct_mutex); | 463 | mutex_lock(&dev->struct_mutex); |
471 | list_for_each(list, &dev->maplist->head) { | 464 | list_for_each_entry(r_list, &dev->maplist, head) { |
472 | drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head); | ||
473 | |||
474 | if (r_list->map && | 465 | if (r_list->map && |
475 | r_list->user_token == (unsigned long)request.handle && | 466 | r_list->user_token == (unsigned long)request.handle && |
476 | r_list->map->flags & _DRM_REMOVABLE) { | 467 | r_list->map->flags & _DRM_REMOVABLE) { |
@@ -482,7 +473,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp, | |||
482 | /* List has wrapped around to the head pointer, or its empty we didn't | 473 | /* List has wrapped around to the head pointer, or its empty we didn't |
483 | * find anything. | 474 | * find anything. |
484 | */ | 475 | */ |
485 | if (list == (&dev->maplist->head)) { | 476 | if (list_empty(&dev->maplist) || !map) { |
486 | mutex_unlock(&dev->struct_mutex); | 477 | mutex_unlock(&dev->struct_mutex); |
487 | return -EINVAL; | 478 | return -EINVAL; |
488 | } | 479 | } |
@@ -606,14 +597,14 @@ int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request) | |||
606 | 597 | ||
607 | /* Make sure buffers are located in AGP memory that we own */ | 598 | /* Make sure buffers are located in AGP memory that we own */ |
608 | valid = 0; | 599 | valid = 0; |
609 | for (agp_entry = dev->agp->memory; agp_entry; agp_entry = agp_entry->next) { | 600 | list_for_each_entry(agp_entry, &dev->agp->memory, head) { |
610 | if ((agp_offset >= agp_entry->bound) && | 601 | if ((agp_offset >= agp_entry->bound) && |
611 | (agp_offset + total * count <= agp_entry->bound + agp_entry->pages * PAGE_SIZE)) { | 602 | (agp_offset + total * count <= agp_entry->bound + agp_entry->pages * PAGE_SIZE)) { |
612 | valid = 1; | 603 | valid = 1; |
613 | break; | 604 | break; |
614 | } | 605 | } |
615 | } | 606 | } |
616 | if (dev->agp->memory && !valid) { | 607 | if (!list_empty(&dev->agp->memory) && !valid) { |
617 | DRM_DEBUG("zone invalid\n"); | 608 | DRM_DEBUG("zone invalid\n"); |
618 | return -EINVAL; | 609 | return -EINVAL; |
619 | } | 610 | } |