From a45773904cfd063555d93a3c10c75ed9fd6df224 Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Tue, 9 Aug 2011 14:42:08 -0700 Subject: [PATCH] ion: minor clean up -- init rb nodes in ion_handle_create -- in ion_handle_destroy, check that a node belongs to a tree before removing it (safety check, does not happen right now) -- mark as static functions used only inside ion.c -- update comments to ion_share() with a relevant blurb from the implementation -- other minor updates/typo fixes to comments Signed-off-by: Iliyan Malchev --- drivers/gpu/ion/ion.c | 18 ++++++++++-------- include/linux/ion.h | 9 +++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c index 9cb5b25..37b23af 100644 --- a/drivers/gpu/ion/ion.c +++ b/drivers/gpu/ion/ion.c @@ -131,7 +131,7 @@ static void ion_buffer_add(struct ion_device *dev, } /* this function should only be called while dev->lock is held */ -struct ion_buffer *ion_buffer_create(struct ion_heap *heap, +static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, struct ion_device *dev, unsigned long len, unsigned long align, @@ -181,7 +181,7 @@ static int ion_buffer_put(struct ion_buffer *buffer) return kref_put(&buffer->ref, ion_buffer_destroy); } -struct ion_handle *ion_handle_create(struct ion_client *client, +static struct ion_handle *ion_handle_create(struct ion_client *client, struct ion_buffer *buffer) { struct ion_handle *handle; @@ -190,6 +190,7 @@ struct ion_handle *ion_handle_create(struct ion_client *client, if (!handle) return ERR_PTR(-ENOMEM); kref_init(&handle->ref); + rb_init_node(&handle->node); handle->client = client; ion_buffer_get(buffer); handle->buffer = buffer; @@ -205,7 +206,8 @@ static void ion_handle_destroy(struct kref *kref) */ ion_buffer_put(handle->buffer); mutex_lock(&handle->client->lock); - rb_erase(&handle->node, &handle->client->handles); + if (!RB_EMPTY_NODE(&handle->node)) + rb_erase(&handle->node, &handle->client->handles); mutex_unlock(&handle->client->lock); kfree(handle); } @@ -239,7 +241,7 @@ static struct ion_handle *ion_handle_lookup(struct ion_client *client, return NULL; } -bool ion_handle_validate(struct ion_client *client, struct ion_handle *handle) +static bool ion_handle_validate(struct ion_client *client, struct ion_handle *handle) { struct rb_node *n = client->handles.rb_node; @@ -351,7 +353,7 @@ void ion_free(struct ion_client *client, struct ion_handle *handle) static void ion_client_get(struct ion_client *client); static int ion_client_put(struct ion_client *client); -bool _ion_map(int *buffer_cnt, int *handle_cnt) +static bool _ion_map(int *buffer_cnt, int *handle_cnt) { bool map; @@ -367,7 +369,7 @@ bool _ion_map(int *buffer_cnt, int *handle_cnt) return map; } -bool _ion_unmap(int *buffer_cnt, int *handle_cnt) +static bool _ion_unmap(int *buffer_cnt, int *handle_cnt) { BUG_ON(*handle_cnt == 0); (*handle_cnt)--; @@ -522,7 +524,7 @@ struct ion_buffer *ion_share(struct ion_client *client, return ERR_PTR(-EINVAL); } - /* don't not take an extra refernce here, the burden is on the caller + /* do not take an extra reference here, the burden is on the caller * to make sure the buffer doesn't go away while it's passing it * to another client -- ion_free should not be called on this handle * until the buffer has been imported into the other client @@ -897,7 +899,7 @@ err1: /* drop the reference to the handle */ ion_handle_put(handle); err: - /* drop the refernce to the client */ + /* drop the reference to the client */ ion_client_put(client); return ret; } diff --git a/include/linux/ion.h b/include/linux/ion.h index 111982f..aed8349 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -186,9 +186,14 @@ void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle); * @client: the client * @handle: the handle to share * - * Given a handle, return a buffer which exists in a global name - * space and can be passed to other clients. Should be passed into ion_import + * Given a handle, return a buffer, which exists in a global name + * space, and can be passed to other clients. Should be passed into ion_import * to obtain a new handle for this buffer. + * + * NOTE: This function does do not an extra reference. The burden is on the + * caller to make sure the buffer doesn't go away while it's being passed to + * another client. That is, ion_free should not be called on this handle until + * the buffer has been imported into the other client. */ struct ion_buffer *ion_share(struct ion_client *client, struct ion_handle *handle); -- 2.7.4