staging: vchiq_dev: Avoid unnecessary alloc in vchiq_ioc_create_service

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.

Reviewed-by: Nicolas Saenz Julienne <nsaenz@kernel.org>
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Link: https://lore.kernel.org/r/1642968143-19281-19-git-send-email-stefan.wahren@i2se.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Stefan Wahren 2022-01-23 21:02:23 +01:00 committed by Greg Kroah-Hartman
parent ca225857fa
commit e125921585

View File

@ -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 ?