Skip to contentSkip to conversation

tee: optee: fix type warning of sizeof in pool_op_alloc()

PATCH In review Liu Shixin 2 participants 2 messages Sep 17, 2020 – Sep 24, 2020

Subsystems (2)
lore
Share & tools
lore

Liu Shixin

author
#0 lore raw

PATCH 1/1 tee: optee: fix type warning of sizeof in pool_op_alloc()

sizeof() when applied to a pointer typed expression should gives the size of the pointed data, even if the data is a pointer.

---
 drivers/tee/optee/shm_pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/optee/shm_pool.c +1 -1
index d767eebf30bd..9fdc667b5df0 100644
@@ -31,7 +31,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
 		unsigned int nr_pages = 1 << order, i;
 		struct page **pages;
 
-		pages = kcalloc(nr_pages, sizeof(pages), GFP_KERNEL);
+		pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
 		if (!pages)
 			return -ENOMEM;
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 14 lines · Liu Shixin

sizeof() when applied to a pointer typed expression should gives the size of the pointed data, even if the data is a pointer.

---
 drivers/tee/optee/shm_pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/optee/shm_pool.c +0 -0
index d767eebf30bd..9fdc667b5df0 100644

drivers/tee/optee/shm_pool.c static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, · line 34

Quoted 5 lines
drivers/tee/optee/shm_pool.c +1 -1
@@ -31,7 +31,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
                unsigned int nr_pages = 1 << order, i;
                struct page **pages;
 
-               pages = kcalloc(nr_pages, sizeof(pages), GFP_KERNEL);
+               pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);

In this case we want an array of pointers as you also can see in the type of "pages".

Thanks,
Jens

Quoted 6 lines
drivers/tee/optee/shm_pool.c +0 -1
                if (!pages)
                        return -ENOMEM;
 
--

2.25.1