Commit b6147e4f authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: control: return error pointer when failing to create control device

Return an error pointer when failing to create a control device.
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 7c8eb12d
...@@ -257,23 +257,26 @@ struct device_type greybus_control_type = { ...@@ -257,23 +257,26 @@ struct device_type greybus_control_type = {
struct gb_control *gb_control_create(struct gb_interface *intf) struct gb_control *gb_control_create(struct gb_interface *intf)
{ {
struct gb_connection *connection;
struct gb_control *control; struct gb_control *control;
control = kzalloc(sizeof(*control), GFP_KERNEL); control = kzalloc(sizeof(*control), GFP_KERNEL);
if (!control) if (!control)
return NULL; return ERR_PTR(-ENOMEM);
control->intf = intf; control->intf = intf;
control->connection = gb_connection_create_control(intf); connection = gb_connection_create_control(intf);
if (IS_ERR(control->connection)) { if (IS_ERR(connection)) {
dev_err(&intf->dev, dev_err(&intf->dev,
"failed to create control connection: %ld\n", "failed to create control connection: %ld\n",
PTR_ERR(control->connection)); PTR_ERR(connection));
kfree(control); kfree(control);
return NULL; return ERR_CAST(connection);
} }
control->connection = connection;
control->dev.parent = &intf->dev; control->dev.parent = &intf->dev;
control->dev.bus = &greybus_bus_type; control->dev.bus = &greybus_bus_type;
control->dev.type = &greybus_control_type; control->dev.type = &greybus_control_type;
......
...@@ -381,6 +381,7 @@ struct device_type greybus_interface_type = { ...@@ -381,6 +381,7 @@ struct device_type greybus_interface_type = {
struct gb_interface *gb_interface_create(struct gb_host_device *hd, struct gb_interface *gb_interface_create(struct gb_host_device *hd,
u8 interface_id) u8 interface_id)
{ {
struct gb_control *control;
struct gb_interface *intf; struct gb_interface *intf;
intf = kzalloc(sizeof(*intf), GFP_KERNEL); intf = kzalloc(sizeof(*intf), GFP_KERNEL);
...@@ -403,11 +404,12 @@ struct gb_interface *gb_interface_create(struct gb_host_device *hd, ...@@ -403,11 +404,12 @@ struct gb_interface *gb_interface_create(struct gb_host_device *hd,
device_initialize(&intf->dev); device_initialize(&intf->dev);
dev_set_name(&intf->dev, "%d-%d", hd->bus_id, interface_id); dev_set_name(&intf->dev, "%d-%d", hd->bus_id, interface_id);
intf->control = gb_control_create(intf); control = gb_control_create(intf);
if (!intf->control) { if (IS_ERR(control)) {
put_device(&intf->dev); put_device(&intf->dev);
return NULL; return NULL;
} }
intf->control = control;
list_add(&intf->links, &hd->interfaces); list_add(&intf->links, &hd->interfaces);
......
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