staging: vchiq_core: handle NULL result of find_service_by_handle
authorStefan Wahren <stefan.wahren@i2se.com>
Sun, 23 Jan 2022 20:02:22 +0000 (21:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Apr 2022 18:59:11 +0000 (20:59 +0200)
[ Upstream commit ca225857faf237234d2fffe5d1919467dfadd822 ]

In case of an invalid handle the function find_servive_by_handle
returns NULL. So take care of this and avoid a NULL pointer dereference.

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-18-git-send-email-stefan.wahren@i2se.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c

index 9429b8a642fbbe4030cb2db15f17838bbb1f6265..630ed0dc24c39246531890ea02ee51902a7cc178 100644 (file)
@@ -2421,6 +2421,9 @@ void vchiq_msg_queue_push(unsigned int handle, struct vchiq_header *header)
        struct vchiq_service *service = find_service_by_handle(handle);
        int pos;
 
+       if (!service)
+               return;
+
        while (service->msg_queue_write == service->msg_queue_read +
                VCHIQ_MAX_SLOTS) {
                if (wait_for_completion_interruptible(&service->msg_queue_pop))
@@ -2441,6 +2444,9 @@ struct vchiq_header *vchiq_msg_hold(unsigned int handle)
        struct vchiq_header *header;
        int pos;
 
+       if (!service)
+               return NULL;
+
        if (service->msg_queue_write == service->msg_queue_read)
                return NULL;