aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/staging/vc04_services
diff options
context:
space:
mode:
authorStefan Wahren <stefan.wahren@i2se.com>2022-01-23 21:02:23 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-01-25 16:30:16 +0100
commite12592158515831e5ff6e80a36a4d05ceaf22908 (patch)
tree41c8dae9a35a52904e19216e2f390862d6c25edf /drivers/staging/vc04_services
parentstaging: vchiq_core: handle NULL result of find_service_by_handle (diff)
downloadwireguard-linux-e12592158515831e5ff6e80a36a4d05ceaf22908.tar.xz
wireguard-linux-e12592158515831e5ff6e80a36a4d05ceaf22908.zip
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>
Diffstat (limited to 'drivers/staging/vc04_services')
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c7
1 files 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 2325844b0880..b41c2a267355 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 ?