]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tee: optee: don't enumerate services if there ain't any
authorEtienne Carriere <etienne.carriere@foss.st.com>
Wed, 29 Nov 2023 12:37:53 +0000 (13:37 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 19 Dec 2023 15:07:48 +0000 (10:07 -0500)
Change optee driver service enumeration to not enumerate (and
allocate a zero sized shared memory buffer) when OP-TEE
reports that there is no service to enumerate.

This change fixes an existing issue that occurs when the such zero
sized shared memory buffer allocated from malloc() has a physical
address of offset 0 of a physical 4kB page. In such case, OP-TEE
secure world refuses to register the zero-sized shared memory
area and makes U-Boot optee service enumeration to fail.

Fixes: 94ccfb78a4d6 ("drivers: tee: optee: discover OP-TEE services")
Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
drivers/tee/optee/core.c

index 5308dd58ce973d8ea540c5e3901feae9c0614d48..47f845cffe378d78cfdb176dab17b3d0c7ca81ad 100644 (file)
@@ -139,6 +139,11 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *coun
        if (ret)
                return ret;
 
+       if (!shm_size) {
+               *count = 0;
+               return 0;
+       }
+
        ret = tee_shm_alloc(dev, shm_size, 0, shm);
        if (ret) {
                dev_err(dev, "Failed to allocated shared memory: %d\n", ret);
@@ -185,14 +190,15 @@ static int bind_service_drivers(struct udevice *dev)
 
        ret = enum_services(dev, &service_list, &service_count, tee_sess,
                            PTA_CMD_GET_DEVICES);
-       if (!ret)
+       if (!ret && service_count)
                ret = bind_service_list(dev, service_list, service_count);
 
        tee_shm_free(service_list);
+       service_list = NULL;
 
        ret2 = enum_services(dev, &service_list, &service_count, tee_sess,
                             PTA_CMD_GET_DEVICES_SUPP);
-       if (!ret2)
+       if (!ret2 && service_count)
                ret2 = bind_service_list(dev, service_list, service_count);
 
        tee_shm_free(service_list);