[PATCH 33/44] kdbus: Improve kdbus_staging_reserve()

From: Sergei Zviagintsev
Date: Thu Oct 08 2015 - 07:34:25 EST


Allow to reserve N elements in row. This eliminates duplicated code.

Signed-off-by: Sergei Zviagintsev <sergei@xxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/