util: kdbus_str_hash() -> kdbus_strhash()
authorDavid Herrmann <dh.herrmann@gmail.com>
Fri, 19 Dec 2014 17:55:41 +0000 (18:55 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Fri, 19 Dec 2014 17:55:41 +0000 (18:55 +0100)
Lets make this function look more like strlen(), strcopy(), ... and
friends. Not that I like it in particular, but a followup will introduce
kdbus_strnhash() and those names get really weird once used with
underscore style.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
connection.c
names.c
node.c
policy.c
util.h

index e4b641f011629e15c4ed08613c9e9470665def10..141b10fa5b73c0077e5f80ef76cc61ff02d64019 100644 (file)
@@ -1898,7 +1898,7 @@ static bool kdbus_conn_policy_query_all(struct kdbus_conn *conn,
 
        list_for_each_entry(ne, &whom->names_list, conn_entry) {
                res = kdbus_policy_query_unlocked(db, conn->cred, ne->name,
-                                                 kdbus_str_hash(ne->name));
+                                                 kdbus_strhash(ne->name));
                if (res >= (int)access) {
                        pass = true;
                        break;
@@ -1922,7 +1922,7 @@ static bool kdbus_conn_policy_query_all(struct kdbus_conn *conn,
  */
 bool kdbus_conn_policy_own_name(struct kdbus_conn *conn, const char *name)
 {
-       unsigned int hash = kdbus_str_hash(name);
+       unsigned int hash = kdbus_strhash(name);
        int res;
 
        if (conn->ep->has_policy) {
@@ -1989,7 +1989,7 @@ bool kdbus_conn_policy_see_name_unlocked(struct kdbus_conn *conn,
                return true;
 
        res = kdbus_policy_query_unlocked(&conn->ep->policy_db, conn->cred,
-                                         name, kdbus_str_hash(name));
+                                         name, kdbus_strhash(name));
        return res >= KDBUS_POLICY_SEE;
 }
 
diff --git a/names.c b/names.c
index 0d53547babdc8e30e1990abe632cd6a58bfbb8ad..a9df981fcc868c0aa5a54607a5e5a0273eebb6ec 100644 (file)
--- a/names.c
+++ b/names.c
@@ -250,7 +250,7 @@ static int kdbus_name_release(struct kdbus_name_registry *reg,
        int ret = -ESRCH;
        u32 hash;
 
-       hash = kdbus_str_hash(name);
+       hash = kdbus_strhash(name);
 
        /* lock order: domain -> bus -> ep -> names -> connection */
        mutex_lock(&conn->ep->bus->lock);
@@ -350,7 +350,7 @@ struct kdbus_name_entry *kdbus_name_lock(struct kdbus_name_registry *reg,
                                         const char *name)
 {
        struct kdbus_name_entry *e = NULL;
-       u32 hash = kdbus_str_hash(name);
+       u32 hash = kdbus_strhash(name);
 
        down_read(&reg->rwlock);
        e = kdbus_name_lookup(reg, hash, name);
@@ -480,7 +480,7 @@ int kdbus_name_acquire(struct kdbus_name_registry *reg,
        mutex_lock(&conn->ep->bus->lock);
        down_write(&reg->rwlock);
 
-       hash = kdbus_str_hash(name);
+       hash = kdbus_strhash(name);
        e = kdbus_name_lookup(reg, hash, name);
        if (e) {
                /* connection already owns that name */
diff --git a/node.c b/node.c
index 9e4e431c770e76b6e0dc87d0948d7c5884f70811..4e7c32fede9818b9a69a3bfa4134f4db82164537 100644 (file)
--- a/node.c
+++ b/node.c
@@ -249,7 +249,7 @@ static unsigned int kdbus_node_name_hash(const char *name)
        unsigned int hash;
 
        /* reserve hash numbers 0, 1 and >=INT_MAX for magic directories */
-       hash = kdbus_str_hash(name) & INT_MAX;
+       hash = kdbus_strhash(name) & INT_MAX;
        if (hash < 2)
                hash += 2;
        if (hash >= INT_MAX)
index 8c4b202f94c601d5ea4b5be014b7205b052f5e11..5cd6e1704f200ad41f3a02cf89153aeba6803d44 100644 (file)
--- a/policy.c
+++ b/policy.c
@@ -103,7 +103,7 @@ kdbus_policy_lookup(struct kdbus_policy_db *db, const char *name, u32 hash)
                goto exit_free;
 
        *dot = '\0';
-       hash = kdbus_str_hash(tmp);
+       hash = kdbus_strhash(tmp);
 
        hash_for_each_possible(db->entries_hash, e, hentry, hash)
                if (e->wildcard && strcmp(e->name, tmp) == 0) {
@@ -179,7 +179,7 @@ int kdbus_policy_query_unlocked(struct kdbus_policy_db *db,
 
                switch (a->type) {
                case KDBUS_POLICY_ACCESS_USER:
-                       if (uid_eq(cred->uid, a->uid))
+                       if (uid_eq(cred->euid, a->uid))
                                highest = a->access;
                        break;
                case KDBUS_POLICY_ACCESS_GROUP:
@@ -449,7 +449,7 @@ int kdbus_policy_set(struct kdbus_policy_db *db,
 
        hlist_for_each_entry_safe(e, tmp, &entries, hentry) {
                /* prevent duplicates */
-               hash = kdbus_str_hash(e->name);
+               hash = kdbus_strhash(e->name);
                hash_for_each_possible(db->entries_hash, p, hentry, hash)
                        if (strcmp(e->name, p->name) == 0 &&
                            e->wildcard == p->wildcard) {
@@ -470,7 +470,7 @@ restore:
        hlist_for_each_entry_safe(e, tmp, &restore, hentry) {
                hlist_del(&e->hentry);
                if (ret < 0) {
-                       hash = kdbus_str_hash(e->name);
+                       hash = kdbus_strhash(e->name);
                        hash_add(db->entries_hash, &e->hentry, hash);
                } else {
                        kdbus_policy_entry_free(e);
diff --git a/util.h b/util.h
index 4f69cccca609b7a48073aed8705176eec0bad7f5..a52099ccfcb3fe078e500e6ddded5ed3046e8372 100644 (file)
--- a/util.h
+++ b/util.h
 })
 
 /**
- * kdbus_str_hash - calculate a hash
+ * kdbus_strhash - calculate a hash
  * @str:               String
  *
  * Return: hash value
  */
-static inline unsigned int kdbus_str_hash(const char *str)
+static inline unsigned int kdbus_strhash(const char *str)
 {
        unsigned long hash = init_name_hash();