Commit 6b7d5a1f authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: core: return error code when creating endo

Return a pointer-coded error from gb_endo_create() rather than just
a null pointer in the event an error occurs.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent ee3ecf80
...@@ -177,6 +177,7 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver ...@@ -177,6 +177,7 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver
size_t buffer_size_max) size_t buffer_size_max)
{ {
struct greybus_host_device *hd; struct greybus_host_device *hd;
struct gb_endo *endo;
u16 endo_id = 0x4755; // FIXME - get endo "ID" from the SVC u16 endo_id = 0x4755; // FIXME - get endo "ID" from the SVC
/* /*
...@@ -211,11 +212,12 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver ...@@ -211,11 +212,12 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver
ida_init(&hd->cport_id_map); ida_init(&hd->cport_id_map);
hd->buffer_size_max = buffer_size_max; hd->buffer_size_max = buffer_size_max;
hd->endo = gb_endo_create(hd, endo_id); endo = gb_endo_create(hd, endo_id);
if (!hd->endo) { if (IS_ERR(endo)) {
greybus_remove_hd(hd); greybus_remove_hd(hd);
return NULL; return NULL;
} }
hd->endo = endo;
return hd; return hd;
} }
......
...@@ -430,16 +430,19 @@ struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id) ...@@ -430,16 +430,19 @@ struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id)
endo = kzalloc(sizeof(*endo), GFP_KERNEL); endo = kzalloc(sizeof(*endo), GFP_KERNEL);
if (!endo) if (!endo)
return NULL; return ERR_PTR(-ENOMEM);
/* First check if the value supplied is a valid endo id */ /* First check if the value supplied is a valid endo id */
if (gb_endo_validate_id(hd, &endo->layout, endo_id)) if (gb_endo_validate_id(hd, &endo->layout, endo_id)) {
retval = -EINVAL;
goto free_endo; goto free_endo;
}
endo->id = endo_id; endo->id = endo_id;
/* Register Endo device */ /* Register Endo device */
if (gb_endo_register(hd, endo)) retval = gb_endo_register(hd, endo);
if (retval)
goto free_endo; goto free_endo;
/* Create modules/interfaces */ /* Create modules/interfaces */
...@@ -453,7 +456,8 @@ struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id) ...@@ -453,7 +456,8 @@ struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id)
free_endo: free_endo:
kfree(endo); kfree(endo);
return NULL;
return ERR_PTR(retval);
} }
void gb_endo_remove(struct gb_endo *endo) void gb_endo_remove(struct gb_endo *endo)
......
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