metadata: rename kdbus_meta_offset_of() to kdbus_meta_find_item()
authorDaniel Mack <zonque@gmail.com>
Sat, 16 Aug 2014 08:41:09 +0000 (10:41 +0200)
committerDaniel Mack <zonque@gmail.com>
Sat, 16 Aug 2014 08:56:06 +0000 (10:56 +0200)
Return a pointer to the item itself, so we can as well use its size.

connection.c
metadata.c
metadata.h

index 4bed84c385a73c3fdeb1c6b05400b671cacb5e70..1533404699a8bd96c1062bc3e2c97d12a5837a5a 100644 (file)
@@ -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,
index fa078a265c414a4fd992113f865fcec31450db1e..b0ce6eca6de4bea9502c621fca4bbe3f2ad43c88 100644 (file)
@@ -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;
 }
 
 /**
index 82344b302ef03c58511b221b686a140602cba33b..096700edc5f07192b200500b93b710e8904d3479 100644 (file)
@@ -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