There is no need to allocate the user service in case there is a VCHIQ connection required, but not available. So simply check the error conditions before doing an expensive memory allocation. Signed-off-by: Stefan Wahren <stefan.wahren@xxxxxxxx> --- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c index 2325844..b41c2a2 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c @@ -146,15 +146,14 @@ static int vchiq_ioc_create_service(struct vchiq_instance *instance, struct vchiq_service_params_kernel params; int srvstate; + if (args->is_open && !instance->connected) + return -ENOTCONN; + user_service = kmalloc(sizeof(*user_service), GFP_KERNEL); if (!user_service) return -ENOMEM; if (args->is_open) { - if (!instance->connected) { - kfree(user_service); - return -ENOTCONN; - } srvstate = VCHIQ_SRVSTATE_OPENING; } else { srvstate = instance->connected ? -- 2.7.4