lkml.org 
[lkml]   [2015]   [Oct]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 33/44] kdbus: Improve kdbus_staging_reserve()
Date
Allow to reserve N elements in row. This eliminates duplicated code.

Signed-off-by: Sergei Zviagintsev <sergei@s15v.net>
---
ipc/kdbus/message.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/ipc/kdbus/message.c b/ipc/kdbus/message.c
index e337b1b1024a..f2176796390d 100644
--- a/ipc/kdbus/message.c
+++ b/ipc/kdbus/message.c
@@ -647,13 +647,14 @@ static int kdbus_staging_import(struct kdbus_staging *staging)
return 0;
}

-static void kdbus_staging_reserve(struct kdbus_staging *staging)
+static void kdbus_staging_reserve(struct kdbus_staging *staging, size_t n)
{
- struct iovec *part;
+ while (n--) {
+ struct iovec *part = &staging->parts[staging->n_parts++];

- part = &staging->parts[staging->n_parts++];
- part->iov_base = (void __user *)zeros;
- part->iov_len = 0;
+ part->iov_base = (void __user *)zeros;
+ part->iov_len = 0;
+ }
}

static struct kdbus_staging *kdbus_staging_new(struct kdbus_bus *bus,
@@ -701,16 +702,9 @@ static struct kdbus_staging *kdbus_staging_new(struct kdbus_bus *bus,
* * iovec for possible padding after the items
* * iovec for metadata items
* * iovec for possible padding after the items
- *
- * Make sure to update @reserved_parts if you add more parts here.
*/

- kdbus_staging_reserve(staging); /* msg.size */
- kdbus_staging_reserve(staging); /* msg (minus msg.size) plus items */
- kdbus_staging_reserve(staging); /* msg padding */
- kdbus_staging_reserve(staging); /* meta */
- kdbus_staging_reserve(staging); /* meta padding */
-
+ kdbus_staging_reserve(staging, reserved_parts);
return staging;

error:
@@ -814,7 +808,7 @@ struct kdbus_staging *kdbus_staging_new_user(struct kdbus_bus *bus,
*/

ret = kdbus_staging_import(staging); /* payload */
- kdbus_staging_reserve(staging); /* payload padding */
+ kdbus_staging_reserve(staging, reserved_parts); /* payload padding */

if (ret < 0)
goto error;
--
1.8.3.1


\
 
 \ /
  Last update: 2015-10-08 14:01    [W:0.635 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site