domain: slightly simplify kdbus_domain_new()
authorTom Gundersen <teg@jklm.no>
Mon, 29 Sep 2014 17:42:28 +0000 (19:42 +0200)
committerroot <root@tomegun-x240.getinternet.no>
Mon, 29 Sep 2014 19:01:45 +0000 (21:01 +0200)
No need to lock the kstrdup() call. This also merges two conditionals.

domain.c

index 06c10684332164ffa7400939aff2dd5553a67f69..06d9c228acf9bcc426109b1761fc289624993ab6 100644 (file)
--- a/domain.c
+++ b/domain.c
@@ -261,29 +261,30 @@ int kdbus_domain_new(struct kdbus_domain *parent, const char *name,
        atomic64_set(&d->msg_seq_last, 0);
        idr_init(&d->user_idr);
 
-       /* lock order: parent domain -> domain -> subsys_lock */
-       if (parent) {
-               mutex_lock(&parent->lock);
-               if (parent->disconnected) {
-                       mutex_unlock(&parent->lock);
-                       ret = -ESHUTDOWN;
-                       goto exit_free;
-               }
-       }
-
-       mutex_lock(&kdbus_subsys_lock);
-
        /* compose name and path of base directory in /dev */
        if (!parent) {
                /* initial domain */
                d->devpath = kstrdup(KBUILD_MODNAME, GFP_KERNEL);
                if (!d->devpath) {
                        ret = -ENOMEM;
-                       goto exit_unlock;
+                       goto exit_free;
                }
+
+               mutex_lock(&kdbus_subsys_lock);
+
        } else {
                struct kdbus_domain *exists;
 
+               /* lock order: parent domain -> domain -> subsys_lock */
+               mutex_lock(&parent->lock);
+               if (parent->disconnected) {
+                       mutex_unlock(&parent->lock);
+                       ret = -ESHUTDOWN;
+                       goto exit_free;
+               }
+
+               mutex_lock(&kdbus_subsys_lock);
+
                exists = kdbus_domain_find(parent, name);
                if (exists) {
                        kdbus_domain_unref(exists);