/* 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();
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;
}
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,
}
/**
- * 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;
}
/**
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