2020-09-17 07:55:32

by Liu Shixin

[permalink] [raw]
Subject: [PATCH -next] 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.

Signed-off-by: Liu Shixin <[email protected]>
---
drivers/tee/optee/shm_pool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c
index d767eebf30bd..9fdc667b5df0 100644
--- a/drivers/tee/optee/shm_pool.c
+++ b/drivers/tee/optee/shm_pool.c
@@ -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;

--
2.25.1


2020-09-24 07:35:11

by Jens Wiklander

[permalink] [raw]
Subject: Re: [PATCH -next] tee: optee: fix type warning of sizeof in pool_op_alloc()

On Thu, Sep 17, 2020 at 9:52 AM Liu Shixin <[email protected]> wrote:
>
> sizeof() when applied to a pointer typed expression should gives the
> size of the pointed data, even if the data is a pointer.
>
> Signed-off-by: Liu Shixin <[email protected]>
> ---
> drivers/tee/optee/shm_pool.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c
> index d767eebf30bd..9fdc667b5df0 100644
> --- a/drivers/tee/optee/shm_pool.c
> +++ b/drivers/tee/optee/shm_pool.c
> @@ -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

> if (!pages)
> return -ENOMEM;
>
> --
> 2.25.1
>