message: keep track of kmsg->iov length through kmsg->iov_count
authorDaniel Mack <daniel@zonque.org>
Sat, 20 Dec 2014 22:35:37 +0000 (23:35 +0100)
committerDaniel Mack <daniel@zonque.org>
Sat, 20 Dec 2014 22:35:37 +0000 (23:35 +0100)
Count the array members of kmsg->iov in a new variable called
kmsg->iov_count.

This is necessary because res->vec_count is also used for added
memfd zero-byte alignments, and the message install logic in
queue.c expect to see KDBUS_MSG_DATA_VEC entries in res->data.

It also feel more logical to have the number of array members
stored next to the actual array.

Signed-off-by: Daniel Mack <daniel@zonque.org>
message.c
message.h
queue.c

index 6bd07a31734efc7ecc902c078b3ec3f2bbe74c0c..7cda69909a7a538e526241b03e33d4115c4b45b0 100644 (file)
--- a/message.c
+++ b/message.c
@@ -247,7 +247,7 @@ static int kdbus_msg_scan_items(struct kdbus_kmsg *kmsg,
        vec_size = 0;
        KDBUS_ITEMS_FOREACH(item, msg->items, KDBUS_ITEMS_SIZE(msg, items)) {
                size_t payload_size = KDBUS_ITEM_PAYLOAD_SIZE(item);
-               struct iovec *iov = kmsg->iov + res->vec_count;
+               struct iovec *iov = kmsg->iov + kmsg->iov_count;
 
                if (++n > KDBUS_MSG_MAX_ITEMS)
                        return -E2BIG;
@@ -280,11 +280,9 @@ static int kdbus_msg_scan_items(struct kdbus_kmsg *kmsg,
                                iov->iov_len = size % 8;
                        }
 
-                       if (iov->iov_len > 0) {
-                               kmsg->pool_size += iov->iov_len;
-                               ++res->vec_count;
-                       }
-
+                       kmsg->pool_size += iov->iov_len;
+                       ++kmsg->iov_count;
+                       ++res->vec_count;
                        ++res->data_count;
                        vec_size += size;
 
@@ -315,7 +313,7 @@ static int kdbus_msg_scan_items(struct kdbus_kmsg *kmsg,
                                iov->iov_len = size % 8;
 
                                kmsg->pool_size += iov->iov_len;
-                               ++res->vec_count;
+                               ++kmsg->iov_count;
                        }
 
                        ++res->data_count;
index 0b6f3983f6ff577abe87b57f320c93b98b3440ae..c9554e10a2915411fa69dd553a2a2195f17462c2 100644 (file)
--- a/message.h
+++ b/message.h
@@ -91,6 +91,7 @@ kdbus_msg_resources_unref(struct kdbus_msg_resources *r);
  * @bloom_generation:  Generation of bloom element set
  * @notify_entry:      List of kernel-generated notifications
  * @iov:               Array of iovec, describing the payload to copy
+ * @iov_count:         Number of array members in @iov
  * @pool_size:         Overall size of inlined data referenced by @iov
  * @meta:              Appended SCM-like metadata of the sending process
  * @res:               Message resources
@@ -109,6 +110,7 @@ struct kdbus_kmsg {
        struct list_head notify_entry;
 
        struct iovec *iov;
+       size_t iov_count;
        u64 pool_size;
 
        struct kdbus_meta *meta;
diff --git a/queue.c b/queue.c
index e62892bc72c85614ef3cd30c86e037f561dc13ae..6e344d85f689def59a49148dfaedd56c081795d9 100644 (file)
--- a/queue.c
+++ b/queue.c
@@ -214,7 +214,7 @@ struct kdbus_queue_entry *kdbus_queue_entry_alloc(struct kdbus_pool *pool,
        entry->meta = kdbus_meta_ref(kmsg->meta);
        memcpy(&entry->msg, msg, sizeof(*msg));
 
-       if (res && res->vec_count) {
+       if (kmsg->iov_count) {
                size_t pool_avail = kdbus_pool_remain(pool);
 
                /* do not give out more than half of the remaining space */
@@ -228,7 +228,7 @@ struct kdbus_queue_entry *kdbus_queue_entry_alloc(struct kdbus_pool *pool,
                entry->slice_vecs = kdbus_pool_slice_alloc(pool,
                                                           kmsg->pool_size,
                                                           NULL, kmsg->iov,
-                                                          res->vec_count);
+                                                          kmsg->iov_count);
                if (IS_ERR(entry->slice_vecs)) {
                        ret = PTR_ERR(entry->slice_vecs);
                        entry->slice_vecs = NULL;