diff options
author | Kay Sievers <kay@vrfy.org> | 2013-10-09 22:00:30 +0200 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2013-10-09 22:00:30 +0200 |
commit | f6f152851499a3437ce3234cffb5133c0bd8a119 (patch) | |
tree | c35e2afdb63f6db03dad914d02af2a881ae6f628 | |
parent | 08a1f73b9c017bc653bd170745333ecd662d9d70 (diff) | |
download | kdbus-bus-f6f152851499a3437ce3234cffb5133c0bd8a119.tar.gz kdbus-bus-f6f152851499a3437ce3234cffb5133c0bd8a119.tar.bz2 kdbus-bus-f6f152851499a3437ce3234cffb5133c0bd8a119.zip |
match: move nested loop to separate function
-rw-r--r-- | connection.c | 3 | ||||
-rw-r--r-- | match.c | 68 | ||||
-rw-r--r-- | match.h | 1 |
3 files changed, 34 insertions, 38 deletions
diff --git a/connection.c b/connection.c index 30d54ff1463..66d3c61482c 100644 --- a/connection.c +++ b/connection.c @@ -583,8 +583,7 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep, continue; if (!kdbus_match_db_match_kmsg(conn_dst->match_db, - conn_src, conn_dst, - kmsg)) + conn_src, kmsg)) continue; /* The first receiver which requests additional @@ -145,6 +145,37 @@ bool kdbus_match_db_test_src_names(const char *haystack, } static +bool kdbus_match_db_match_item(struct kdbus_match_db_entry *e, + struct kdbus_conn *conn_src, + struct kdbus_kmsg *kmsg) +{ + struct kdbus_match_db_entry_item *ei; + + list_for_each_entry(ei, &e->items_list, list_entry) { + if (kmsg->bloom && ei->type == KDBUS_MATCH_BLOOM) { + size_t n = conn_src->ep->bus->bloom_size / sizeof(u64); + + if (kdbus_match_db_test_bloom(kmsg->bloom, + ei->bloom, n)) + continue; + + return false; + } + + if (kmsg->src_names && ei->type == KDBUS_MATCH_SRC_NAME) { + if (kdbus_match_db_test_src_names(kmsg->src_names, + kmsg->src_names_len, + ei->name)) + continue; + + return false; + } + } + + return true; +} + +static bool kdbus_match_db_match_with_src(struct kdbus_match_db *db, struct kdbus_conn *conn_src, struct kdbus_kmsg *kmsg) @@ -154,40 +185,11 @@ bool kdbus_match_db_match_with_src(struct kdbus_match_db *db, mutex_lock(&db->entries_lock); list_for_each_entry(e, &db->entries, list_entry) { - struct kdbus_match_db_entry_item *ei; - if (e->src_id != KDBUS_MATCH_SRC_ID_ANY && e->src_id != conn_src->id) continue; - matched = true; - - list_for_each_entry(ei, &e->items_list, list_entry) { - if (kmsg->bloom) { - size_t bloom_num = - conn_src->ep->bus->bloom_size / sizeof(u64); - if (ei->type == KDBUS_MATCH_BLOOM) - if (!kdbus_match_db_test_bloom( - kmsg->bloom, - ei->bloom, - bloom_num)) { - matched = false; - break; - } - } - - if (kmsg->src_names) { - if (ei->type == KDBUS_MATCH_SRC_NAME) - if (!kdbus_match_db_test_src_names( - kmsg->src_names, - kmsg->src_names_len, - ei->name)) { - matched = false; - break; - } - } - } - + matched = kdbus_match_db_match_item(e, conn_src, kmsg); if (matched) break; } @@ -198,7 +200,6 @@ bool kdbus_match_db_match_with_src(struct kdbus_match_db *db, static bool kdbus_match_db_match_from_kernel(struct kdbus_match_db *db, - struct kdbus_conn *conn_dst, struct kdbus_kmsg *kmsg) { u64 type = kmsg->notification_type; @@ -213,8 +214,6 @@ bool kdbus_match_db_match_from_kernel(struct kdbus_match_db *db, e->src_id != 0) continue; - matched = false; - list_for_each_entry(ei, &e->items_list, list_entry) { if (ei->type == KDBUS_MATCH_ID_ADD && type == KDBUS_MSG_ID_ADD) { @@ -257,13 +256,12 @@ bool kdbus_match_db_match_from_kernel(struct kdbus_match_db *db, bool kdbus_match_db_match_kmsg(struct kdbus_match_db *db, struct kdbus_conn *conn_src, - struct kdbus_conn *conn_dst, struct kdbus_kmsg *kmsg) { if (conn_src) return kdbus_match_db_match_with_src(db, conn_src, kmsg); else - return kdbus_match_db_match_from_kernel(db, conn_dst, kmsg); + return kdbus_match_db_match_from_kernel(db, kmsg); } static struct kdbus_cmd_match * @@ -29,6 +29,5 @@ int kdbus_match_db_add(struct kdbus_conn *conn, void __user *buf); int kdbus_match_db_remove(struct kdbus_conn *conn, void __user *buf); bool kdbus_match_db_match_kmsg(struct kdbus_match_db *db, struct kdbus_conn *conn_src, - struct kdbus_conn *conn_dst, struct kdbus_kmsg *kmsg); #endif |