Use idr_replace trick to eliminate struct drm_ctx_sarea_list.

main
Kristian Høgsberg 2007-07-03 10:41:48 -04:00
parent 1814a829eb
commit d57b7f02d2
3 changed files with 8 additions and 40 deletions

View File

@ -570,10 +570,6 @@ typedef struct drm_ctx_list {
drm_file_t *tag; /**< associated fd private data */ drm_file_t *tag; /**< associated fd private data */
} drm_ctx_list_t; } drm_ctx_list_t;
struct drm_ctx_sarea_list {
drm_map_t *map;
};
typedef struct drm_vbl_sig { typedef struct drm_vbl_sig {
struct list_head head; struct list_head head;
unsigned int sequence; unsigned int sequence;

View File

@ -58,17 +58,9 @@
*/ */
void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle) void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle)
{ {
struct drm_ctx_sarea_list *ctx;
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
ctx = idr_find(&dev->ctx_idr, ctx_handle); idr_remove(&dev->ctx_idr, ctx_handle);
if (ctx) {
idr_remove(&dev->ctx_idr, ctx_handle);
drm_free(ctx, sizeof(struct drm_ctx_sarea_list), DRM_MEM_CTXLIST);
} else
DRM_ERROR("Attempt to free invalid context handle: %d\n", ctx_handle);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return;
} }
/** /**
@ -84,20 +76,15 @@ static int drm_ctxbitmap_next(drm_device_t * dev)
{ {
int new_id; int new_id;
int ret; int ret;
struct drm_ctx_sarea_list *new_ctx;
new_ctx = drm_calloc(1, sizeof(struct drm_ctx_sarea_list), DRM_MEM_CTXLIST);
if (!new_ctx)
return -1;
again: again:
if (idr_pre_get(&dev->ctx_idr, GFP_KERNEL) == 0) { if (idr_pre_get(&dev->ctx_idr, GFP_KERNEL) == 0) {
DRM_ERROR("Out of memory expanding drawable idr\n"); DRM_ERROR("Out of memory expanding drawable idr\n");
drm_free(new_ctx, sizeof(struct drm_ctx_sarea_list), DRM_MEM_CTXLIST);
return -ENOMEM; return -ENOMEM;
} }
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
ret = idr_get_new_above(&dev->ctx_idr, new_ctx, DRM_RESERVED_CONTEXTS, &new_id); ret = idr_get_new_above(&dev->ctx_idr, NULL,
DRM_RESERVED_CONTEXTS, &new_id);
if (ret == -EAGAIN) { if (ret == -EAGAIN) {
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
goto again; goto again;
@ -120,15 +107,6 @@ int drm_ctxbitmap_init(drm_device_t * dev)
return 0; return 0;
} }
static int drm_ctx_sarea_free(int id, void *p, void *data)
{
struct drm_ctx_sarea_list *ctx_entry = p;
drm_free(ctx_entry, sizeof(struct drm_ctx_sarea_list), DRM_MEM_CTXLIST);
return 0;
}
/** /**
* Context bitmap cleanup. * Context bitmap cleanup.
* *
@ -140,7 +118,6 @@ static int drm_ctx_sarea_free(int id, void *p, void *data)
void drm_ctxbitmap_cleanup(drm_device_t * dev) void drm_ctxbitmap_cleanup(drm_device_t * dev)
{ {
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
idr_for_each(&dev->ctx_idr, drm_ctx_sarea_free, NULL);
idr_remove_all(&dev->ctx_idr); idr_remove_all(&dev->ctx_idr);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
} }
@ -172,19 +149,17 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
drm_ctx_priv_map_t request; drm_ctx_priv_map_t request;
drm_map_t *map; drm_map_t *map;
drm_map_list_t *_entry; drm_map_list_t *_entry;
struct drm_ctx_sarea_list *ctx_sarea;
if (copy_from_user(&request, argp, sizeof(request))) if (copy_from_user(&request, argp, sizeof(request)))
return -EFAULT; return -EFAULT;
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
ctx_sarea = idr_find(&dev->ctx_idr, request.ctx_id); map = idr_find(&dev->ctx_idr, request.ctx_id);
if (!ctx_sarea) { if (!map) {
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return -EINVAL; return -EINVAL;
} }
map = ctx_sarea->map;
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
@ -224,7 +199,6 @@ int drm_setsareactx(struct inode *inode, struct file *filp,
drm_ctx_priv_map_t request; drm_ctx_priv_map_t request;
drm_map_t *map = NULL; drm_map_t *map = NULL;
drm_map_list_t *r_list = NULL; drm_map_list_t *r_list = NULL;
struct drm_ctx_sarea_list *ctx_sarea;
if (copy_from_user(&request, if (copy_from_user(&request,
(drm_ctx_priv_map_t __user *) arg, sizeof(request))) (drm_ctx_priv_map_t __user *) arg, sizeof(request)))
@ -245,12 +219,11 @@ int drm_setsareactx(struct inode *inode, struct file *filp,
if (!map) if (!map)
goto bad; goto bad;
ctx_sarea = idr_find(&dev->ctx_idr, request.ctx_id); if (IS_ERR(idr_replace(&dev->ctx_idr, map, request.ctx_id)))
if (!ctx_sarea)
goto bad; goto bad;
ctx_sarea->map = map;
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return 0; return 0;
} }

View File

@ -113,8 +113,7 @@ int drm_update_drawable_info(DRM_IOCTL_ARGS)
info = drm_calloc(1, sizeof(*info), DRM_MEM_BUFS); info = drm_calloc(1, sizeof(*info), DRM_MEM_BUFS);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
if (idr_replace(&dev->drw_idr, info, update.handle) == if (IS_ERR(idr_replace(&dev->drw_idr, info, update.handle))) {
(void*)-ENOENT) {
DRM_ERROR("No such drawable %d\n", update.handle); DRM_ERROR("No such drawable %d\n", update.handle);
drm_free(info, sizeof(*info), DRM_MEM_BUFS); drm_free(info, sizeof(*info), DRM_MEM_BUFS);
return -EINVAL; return -EINVAL;