From 6b7d5a1f47914b2e3917fb764b4b3fe3affe7f94 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Fri, 22 May 2015 09:52:44 -0500 Subject: [PATCH] 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: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/core.c | 6 ++++-- drivers/staging/greybus/endo.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 27062e7a5824..95d8c70cf20d 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -177,6 +177,7 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver size_t buffer_size_max) { struct greybus_host_device *hd; + struct gb_endo *endo; 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 ida_init(&hd->cport_id_map); hd->buffer_size_max = buffer_size_max; - hd->endo = gb_endo_create(hd, endo_id); - if (!hd->endo) { + endo = gb_endo_create(hd, endo_id); + if (IS_ERR(endo)) { greybus_remove_hd(hd); return NULL; } + hd->endo = endo; return hd; } diff --git a/drivers/staging/greybus/endo.c b/drivers/staging/greybus/endo.c index fb2f7c9c6dd7..5b5a3c65de8f 100644 --- a/drivers/staging/greybus/endo.c +++ b/drivers/staging/greybus/endo.c @@ -430,16 +430,19 @@ struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id) endo = kzalloc(sizeof(*endo), GFP_KERNEL); if (!endo) - return NULL; + return ERR_PTR(-ENOMEM); /* 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; + } endo->id = endo_id; /* Register Endo device */ - if (gb_endo_register(hd, endo)) + retval = gb_endo_register(hd, endo); + if (retval) goto free_endo; /* Create modules/interfaces */ @@ -453,7 +456,8 @@ struct gb_endo *gb_endo_create(struct greybus_host_device *hd, u16 endo_id) free_endo: kfree(endo); - return NULL; + + return ERR_PTR(retval); } void gb_endo_remove(struct gb_endo *endo) -- 2.39.5