OSDN Git Service

greybus: interface: put module->dev on failures
authorViresh Kumar <viresh.kumar@linaro.org>
Tue, 24 Mar 2015 14:44:29 +0000 (20:14 +0530)
committerGreg Kroah-Hartman <greg@kroah.com>
Tue, 24 Mar 2015 20:00:24 +0000 (21:00 +0100)
In order to decrement the reference count of module on failures, we must call
put_device(module->dev). This was missing for one of the error cases, fix it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/interface.c

index d2b2e3d..b687908 100644 (file)
@@ -132,7 +132,7 @@ static struct gb_interface *gb_interface_create(struct greybus_host_device *hd,
 
        intf = kzalloc(sizeof(*intf), GFP_KERNEL);
        if (!intf)
-               return NULL;
+               goto put_module;
 
        intf->hd = hd;          /* XXX refcount? */
        intf->module = module;
@@ -151,10 +151,7 @@ static struct gb_interface *gb_interface_create(struct greybus_host_device *hd,
        if (retval) {
                pr_err("failed to add module device for id 0x%02hhx\n",
                        module_id);
-               put_device(&intf->dev);
-               put_device(&module->dev);
-               kfree(intf);
-               return NULL;
+               goto free_intf;
        }
 
        spin_lock_irq(&gb_interfaces_lock);
@@ -162,6 +159,13 @@ static struct gb_interface *gb_interface_create(struct greybus_host_device *hd,
        spin_unlock_irq(&gb_interfaces_lock);
 
        return intf;
+
+free_intf:
+       put_device(&intf->dev);
+       kfree(intf);
+put_module:
+       put_device(&module->dev);
+       return NULL;
 }
 
 /*