handle: allocate handle after domain lookup
authorDaniel Mack <daniel@zonque.org>
Mon, 20 Oct 2014 15:28:55 +0000 (17:28 +0200)
committerDaniel Mack <daniel@zonque.org>
Mon, 20 Oct 2014 15:30:56 +0000 (17:30 +0200)
Just a small cleanup that orders memory allocation after the domain
has been looked up. That saves us an extra kfree() in the error path.

Signed-off-by: Daniel Mack <daniel@zonque.org>
handle.c

index 25e1cee3936421c3ac15f70112451b38a822c212..8ebf0df203f403258b44781bdf374bc7ba51fecd 100644 (file)
--- a/handle.c
+++ b/handle.c
@@ -98,16 +98,15 @@ static int kdbus_handle_open(struct inode *inode, struct file *file)
        struct kdbus_ep *ep;
        int ret;
 
+       /* find and reference domain */
+       domain = kdbus_domain_find_by_major(MAJOR(inode->i_rdev));
+       if (!domain || domain->disconnected)
+               return -ESHUTDOWN;
+
        handle = kzalloc(sizeof(*handle), GFP_KERNEL);
        if (!handle)
                return -ENOMEM;
 
-       /* find and reference domain */
-       domain = kdbus_domain_find_by_major(MAJOR(inode->i_rdev));
-       if (!domain || domain->disconnected) {
-               kfree(handle);
-               return -ESHUTDOWN;
-       }
        handle->domain = domain;
        file->private_data = handle;