diff options
author | Kay Sievers <kay@vrfy.org> | 2014-03-08 16:34:24 +0100 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2014-03-08 16:35:34 +0100 |
commit | d2e2cadf8354f4be73c5ea3a0a6b6cb5e9c1a067 (patch) | |
tree | 839786a0e9d9a4058edcfeb0dd16a19c2831ecaf | |
parent | 5f9d975515ebaa01fc68b0bd6c280e3b818dba6b (diff) | |
download | kdbus-bus-d2e2cadf8354f4be73c5ea3a0a6b6cb5e9c1a067.tar.gz kdbus-bus-d2e2cadf8354f4be73c5ea3a0a6b6cb5e9c1a067.tar.bz2 kdbus-bus-d2e2cadf8354f4be73c5ea3a0a6b6cb5e9c1a067.zip |
add KDBUS_ITEMS_FOREACH_SIZE
-rw-r--r-- | bus.c | 4 | ||||
-rw-r--r-- | connection.c | 11 | ||||
-rw-r--r-- | domain.c | 4 | ||||
-rw-r--r-- | endpoint.c | 4 | ||||
-rw-r--r-- | handle.c | 4 | ||||
-rw-r--r-- | match.c | 4 | ||||
-rw-r--r-- | message.c | 4 | ||||
-rw-r--r-- | policy.c | 5 | ||||
-rw-r--r-- | util.h | 17 |
9 files changed, 29 insertions, 28 deletions
@@ -337,7 +337,7 @@ int kdbus_bus_make_user(const struct kdbus_cmd_make *make, const struct kdbus_bloom_parameter *bl = NULL; int ret; - KDBUS_ITEM_FOREACH(item, make, items) { + KDBUS_ITEMS_FOREACH(item, make, items) { size_t payload_size; if (!KDBUS_ITEM_VALID(item, make)) @@ -375,7 +375,7 @@ int kdbus_bus_make_user(const struct kdbus_cmd_make *make, } } - if (!KDBUS_ITEM_END(item, make)) + if (!KDBUS_ITEMS_END(item, make)) return -EINVAL; if (!n) diff --git a/connection.c b/connection.c index 96321a10ec3..f60dca4ed09 100644 --- a/connection.c +++ b/connection.c @@ -251,7 +251,7 @@ static int kdbus_conn_payload_add(struct kdbus_conn *conn, return -ENOMEM; } - KDBUS_ITEM_FOREACH(item, &kmsg->msg, items) { + KDBUS_ITEMS_FOREACH(item, &kmsg->msg, items) { switch (item->type) { case KDBUS_ITEM_PAYLOAD_VEC: { char tmp[KDBUS_ITEM_HEADER_SIZE + @@ -1810,7 +1810,7 @@ int kdbus_cmd_conn_update(struct kdbus_conn *conn, bool policy_provided = false; int ret; - KDBUS_ITEM_FOREACH(item, cmd, items) { + KDBUS_ITEMS_FOREACH(item, cmd, items) { switch (item->type) { case KDBUS_ITEM_ATTACH_FLAGS: conn->attach_flags = item->data64[0]; @@ -1832,8 +1832,7 @@ int kdbus_cmd_conn_update(struct kdbus_conn *conn, } ret = kdbus_policy_set(conn->bus->policy_db, cmd->items, - cmd->size - - offsetof(struct kdbus_cmd_conn_update, items), + KDBUS_ITEMS_SIZE(cmd, items), 1, false, conn); return ret; @@ -1888,7 +1887,7 @@ int kdbus_conn_new(struct kdbus_ep *ep, (is_activator || is_policy_holder || is_monitor)) return -EPERM; - KDBUS_ITEM_FOREACH(item, hello, items) { + KDBUS_ITEMS_FOREACH(item, hello, items) { switch (item->type) { case KDBUS_ITEM_NAME: if (!is_activator) @@ -1969,7 +1968,7 @@ int kdbus_conn_new(struct kdbus_ep *ep, * are allowed to use wildcards as well. */ ret = kdbus_policy_set(bus->policy_db, hello->items, - hello->size - offsetof(struct kdbus_cmd_hello, items), + KDBUS_ITEMS_SIZE(hello, items), is_policy_holder ? 0 : 1, is_policy_holder, conn); if (ret < 0) @@ -366,7 +366,7 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name) const char *n = NULL; int ret; - KDBUS_ITEM_FOREACH(item, cmd, items) { + KDBUS_ITEMS_FOREACH(item, cmd, items) { size_t payload_size; if (!KDBUS_ITEM_VALID(item, cmd)) @@ -397,7 +397,7 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name) } } - if (!KDBUS_ITEM_END(item, cmd)) + if (!KDBUS_ITEMS_END(item, cmd)) return -EINVAL; if (!name) diff --git a/endpoint.c b/endpoint.c index f2f423ca5e4..6d38b2dffb0 100644 --- a/endpoint.c +++ b/endpoint.c @@ -272,7 +272,7 @@ int kdbus_ep_make_user(const struct kdbus_cmd_make *make, char **name) const char *n = NULL; int ret; - KDBUS_ITEM_FOREACH(item, make, items) { + KDBUS_ITEMS_FOREACH(item, make, items) { if (!KDBUS_ITEM_VALID(item, make)) return -EINVAL; @@ -300,7 +300,7 @@ int kdbus_ep_make_user(const struct kdbus_cmd_make *make, char **name) } } - if (!KDBUS_ITEM_END(item, make)) + if (!KDBUS_ITEMS_END(item, make)) return -EINVAL; if (!n) @@ -249,7 +249,7 @@ static int kdbus_handle_memfd(void __user *buf) if (ret < 0) return ret; - KDBUS_ITEM_FOREACH(item, m, items) { + KDBUS_ITEMS_FOREACH(item, m, items) { if (!KDBUS_ITEM_VALID(item, m)) { ret = -EINVAL; goto exit; @@ -287,7 +287,7 @@ static int kdbus_handle_memfd(void __user *buf) } } - if (!KDBUS_ITEM_END(item, m)) { + if (!KDBUS_ITEMS_END(item, m)) { ret = -EINVAL; goto exit; } @@ -384,7 +384,7 @@ int kdbus_match_db_add(struct kdbus_conn *conn, INIT_LIST_HEAD(&entry->rules_list); - KDBUS_ITEM_FOREACH(item, cmd, items) { + KDBUS_ITEMS_FOREACH(item, cmd, items) { struct kdbus_match_rule *rule; size_t size = item->size - offsetof(struct kdbus_item, data); @@ -492,7 +492,7 @@ int kdbus_match_db_add(struct kdbus_conn *conn, list_add_tail(&rule->rules_entry, &entry->rules_list); } - if (ret == 0 && !KDBUS_ITEM_END(item, cmd)) + if (ret == 0 && !KDBUS_ITEMS_END(item, cmd)) ret = -EINVAL; if (ret == 0) diff --git a/message.c b/message.c index 83ab57cae3b..3b9d373b100 100644 --- a/message.c +++ b/message.c @@ -88,7 +88,7 @@ static int kdbus_msg_scan_items(struct kdbus_conn *conn, bool has_name = false; bool has_fds = false; - KDBUS_ITEM_FOREACH(item, msg, items) { + KDBUS_ITEMS_FOREACH(item, msg, items) { size_t payload_size; if (!KDBUS_ITEM_VALID(item, msg)) @@ -210,7 +210,7 @@ static int kdbus_msg_scan_items(struct kdbus_conn *conn, } } - if (!KDBUS_ITEM_END(item, msg)) + if (!KDBUS_ITEMS_END(item, msg)) return -EINVAL; /* name is needed if no ID is given */ @@ -535,10 +535,7 @@ int kdbus_policy_set(struct kdbus_policy_db *db, } /* Walk the list of items and look for new policies */ - for (item = items; - (u8 *) item < (u8 *) items + items_size && - (u8 *) item >= (u8 *) items; - item = KDBUS_ITEM_NEXT(item)) { + KDBUS_ITEMS_FOREACH_SIZE(item, items, items_size) { if (item->size <= KDBUS_ITEM_HEADER_SIZE) { ret = -EINVAL; goto exit; @@ -28,16 +28,21 @@ #define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (s)) #define KDBUS_ITEM_NEXT(item) \ (typeof(item))(((u8 *)item) + KDBUS_ALIGN8((item)->size)) -#define KDBUS_ITEM_FOREACH(item, head, first) \ - for (item = (head)->first; \ - ((u8 *)(item) < (u8 *)(head) + (head)->size) && \ - ((u8 *)(item) >= (u8 *)(head)); \ - item = KDBUS_ITEM_NEXT(item)) #define KDBUS_ITEM_VALID(item, head) \ ((item)->size > KDBUS_ITEM_HEADER_SIZE && \ (u8 *)(item) + (item)->size <= (u8 *)(head) + (head)->size) && \ (u8 *)(item) >= (u8 *)(head) -#define KDBUS_ITEM_END(item, head) \ +#define KDBUS_ITEMS_SIZE(head, first) \ + (head)->size - offsetof(typeof(*head), first) +#define KDBUS_ITEMS_FOREACH_SIZE(item, items, size) \ + for (item = items; \ + ((u8 *)(item) < (u8 *)(items) + (size)) && \ + ((u8 *)(item) >= (u8 *)(items)); \ + item = KDBUS_ITEM_NEXT(item)) +#define KDBUS_ITEMS_FOREACH(item, head, first) \ + KDBUS_ITEMS_FOREACH_SIZE(item, (head)->first, \ + KDBUS_ITEMS_SIZE(head, first)) +#define KDBUS_ITEMS_END(item, head) \ ((u8 *)item == ((u8 *)(head) + KDBUS_ALIGN8((head)->size))) /** |