From 953f2a6ddf32b8b8f0923e5447cf0701a0ed372e Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Sat, 16 Aug 2014 10:41:09 +0200 Subject: [PATCH] metadata: rename kdbus_meta_offset_of() to kdbus_meta_find_item() Return a pointer to the item itself, so we can as well use its size. --- connection.c | 18 ++++++++++-------- metadata.c | 19 ++++++++----------- metadata.h | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/connection.c b/connection.c index 4bed84c..1533404 100644 --- a/connection.c +++ b/connection.c @@ -617,14 +617,15 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, /* append message metadata/credential items */ if (meta > 0) { + struct kdbus_item *item; + /* * If the receiver requested credential information, store the * offset to the item here, so we can patch in the namespace * translated versions later. */ - ret = kdbus_meta_offset_of(kmsg->meta, KDBUS_ITEM_CREDS, - &queue->creds_item_offset); - if (ret == 0) { + item = kdbus_meta_find_item(kmsg->meta, KDBUS_ITEM_CREDS); + if (item) { /* store kernel-view of the credentials */ queue->uid = current_uid(); queue->gid = current_gid(); @@ -632,12 +633,12 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, queue->tid = get_task_pid(current->group_leader, PIDTYPE_PID); - queue->creds_item_offset += meta; + queue->creds_item_offset = + ((u8 *) item - (u8 *) kmsg->meta->data) + meta; } - ret = kdbus_meta_offset_of(kmsg->meta, KDBUS_ITEM_AUXGROUPS, - &queue->auxgrp_item_offset); - if (ret == 0) { + item = kdbus_meta_find_item(kmsg->meta, KDBUS_ITEM_AUXGROUPS); + if (item) { struct group_info *info; int i; @@ -659,7 +660,8 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, } put_group_info(info); - queue->auxgrp_item_offset += meta; + queue->auxgrp_item_offset = + ((u8 *) item - (u8 *) kmsg->meta->data) + meta; } ret = kdbus_pool_slice_copy(queue->slice, meta, diff --git a/metadata.c b/metadata.c index fa078a2..b0ce6ec 100644 --- a/metadata.c +++ b/metadata.c @@ -58,27 +58,24 @@ int kdbus_meta_new(struct kdbus_meta **meta) } /** - * kdbus_meta_offset_of() - return the offset of a meta data element + * kdbus_meta_find_item() - return the offset of a meta data element * @meta: Metadata object * @type: The metadata type to look for (KDBUS_ITEM_*) - * @off: Return pointer for the offset, if any * * This function will iterate over the given metadata and return the - * offset of the item of type @type, if it exists. + * item of type @type, if it exists. * - * Return: 0 on success, -ENOENT if the item was not found. + * Return: the first item of the requested type, if found. NULL otherwise. */ -int kdbus_meta_offset_of(struct kdbus_meta *meta, u64 type, off_t *off) +struct kdbus_item *kdbus_meta_find_item(struct kdbus_meta *meta, u64 type) { - const struct kdbus_item *item; + struct kdbus_item *item; KDBUS_ITEMS_FOREACH(item, meta->data, meta->size) - if (item->type == type) { - *off = (u8 *) item - (u8 *) meta->data; - return 0; - } + if (item->type == type) + return item; - return -ENOENT; + return NULL; } /** diff --git a/metadata.h b/metadata.h index 82344b3..096700e 100644 --- a/metadata.h +++ b/metadata.h @@ -41,6 +41,6 @@ int kdbus_meta_append(struct kdbus_meta *meta, struct kdbus_conn *conn, u64 seq, u64 which); -int kdbus_meta_offset_of(struct kdbus_meta *meta, u64 type, off_t *off); +struct kdbus_item *kdbus_meta_find_item(struct kdbus_meta *meta, u64 type); void kdbus_meta_free(struct kdbus_meta *meta); #endif -- 2.34.1