Commit 0a68a16b authored by Viresh Kumar's avatar Viresh Kumar Committed by Greg Kroah-Hartman

greybus: module: free resources properly on failures

Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 132d03ea
...@@ -85,10 +85,6 @@ struct gb_module *gb_module_create(struct greybus_host_device *hd, u8 module_id) ...@@ -85,10 +85,6 @@ struct gb_module *gb_module_create(struct greybus_host_device *hd, u8 module_id)
gmod->module_id = module_id; gmod->module_id = module_id;
INIT_LIST_HEAD(&gmod->interfaces); INIT_LIST_HEAD(&gmod->interfaces);
spin_lock_irq(&gb_modules_lock);
list_add_tail(&gmod->links, &hd->modules);
spin_unlock_irq(&gb_modules_lock);
gmod->dev.parent = hd->parent; gmod->dev.parent = hd->parent;
gmod->dev.bus = &greybus_bus_type; gmod->dev.bus = &greybus_bus_type;
gmod->dev.type = &greybus_module_type; gmod->dev.type = &greybus_module_type;
...@@ -102,9 +98,14 @@ struct gb_module *gb_module_create(struct greybus_host_device *hd, u8 module_id) ...@@ -102,9 +98,14 @@ struct gb_module *gb_module_create(struct greybus_host_device *hd, u8 module_id)
pr_err("failed to add module device for id 0x%02hhx\n", pr_err("failed to add module device for id 0x%02hhx\n",
module_id); module_id);
put_device(&gmod->dev); put_device(&gmod->dev);
kfree(gmod);
return NULL; return NULL;
} }
spin_lock_irq(&gb_modules_lock);
list_add_tail(&gmod->links, &hd->modules);
spin_unlock_irq(&gb_modules_lock);
return gmod; return gmod;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment