All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tee: optee: Use kmemdup() to replace kmalloc + memcpy
@ 2023-06-13  1:18 Jiapeng Chong
  2023-06-13  8:42 ` Sumit Garg
  0 siblings, 1 reply; 3+ messages in thread
From: Jiapeng Chong @ 2023-06-13  1:18 UTC (permalink / raw)
  To: jens.wiklander
  Cc: sumit.garg, op-tee, linux-kernel, Jiapeng Chong, Abaci Robot

Use kmemdup rather than duplicating its implementation.

./drivers/tee/optee/smc_abi.c:1542:12-19: WARNING opportunity for kmemdup.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5480
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
Changes in v2:
  -Add one commit message.

 drivers/tee/optee/smc_abi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
index 3861ae06d902..d5b28fd35d66 100644
--- a/drivers/tee/optee/smc_abi.c
+++ b/drivers/tee/optee/smc_abi.c
@@ -1541,12 +1541,11 @@ static int optee_load_fw(struct platform_device *pdev,
 	 * This uses the GFP_DMA flag to ensure we are allocated memory in the
 	 * 32-bit space since TF-A cannot map memory beyond the 32-bit boundary.
 	 */
-	data_buf = kmalloc(fw->size, GFP_KERNEL | GFP_DMA);
+	data_buf = kmemdup(fw->data, fw->size, GFP_KERNEL | GFP_DMA);
 	if (!data_buf) {
 		rc = -ENOMEM;
 		goto fw_err;
 	}
-	memcpy(data_buf, fw->data, fw->size);
 	data_pa = virt_to_phys(data_buf);
 	reg_pair_from_64(&data_pa_high, &data_pa_low, data_pa);
 	reg_pair_from_64(&data_size_high, &data_size_low, data_size);
-- 
2.20.1.7.g153144c


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tee: optee: Use kmemdup() to replace kmalloc + memcpy
  2023-06-13  1:18 [PATCH v2] tee: optee: Use kmemdup() to replace kmalloc + memcpy Jiapeng Chong
@ 2023-06-13  8:42 ` Sumit Garg
  2023-06-15 12:57   ` Jens Wiklander
  0 siblings, 1 reply; 3+ messages in thread
From: Sumit Garg @ 2023-06-13  8:42 UTC (permalink / raw)
  To: Jiapeng Chong; +Cc: jens.wiklander, op-tee, linux-kernel, Abaci Robot

On Tue, 13 Jun 2023 at 06:49, Jiapeng Chong
<jiapeng.chong@linux.alibaba.com> wrote:
>
> Use kmemdup rather than duplicating its implementation.
>
> ./drivers/tee/optee/smc_abi.c:1542:12-19: WARNING opportunity for kmemdup.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5480
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> Changes in v2:
>   -Add one commit message.
>
>  drivers/tee/optee/smc_abi.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>

Reviewed-by: Sumit Garg <sumit.garg@linaro.org>

-Sumit

> diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
> index 3861ae06d902..d5b28fd35d66 100644
> --- a/drivers/tee/optee/smc_abi.c
> +++ b/drivers/tee/optee/smc_abi.c
> @@ -1541,12 +1541,11 @@ static int optee_load_fw(struct platform_device *pdev,
>          * This uses the GFP_DMA flag to ensure we are allocated memory in the
>          * 32-bit space since TF-A cannot map memory beyond the 32-bit boundary.
>          */
> -       data_buf = kmalloc(fw->size, GFP_KERNEL | GFP_DMA);
> +       data_buf = kmemdup(fw->data, fw->size, GFP_KERNEL | GFP_DMA);
>         if (!data_buf) {
>                 rc = -ENOMEM;
>                 goto fw_err;
>         }
> -       memcpy(data_buf, fw->data, fw->size);
>         data_pa = virt_to_phys(data_buf);
>         reg_pair_from_64(&data_pa_high, &data_pa_low, data_pa);
>         reg_pair_from_64(&data_size_high, &data_size_low, data_size);
> --
> 2.20.1.7.g153144c
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tee: optee: Use kmemdup() to replace kmalloc + memcpy
  2023-06-13  8:42 ` Sumit Garg
@ 2023-06-15 12:57   ` Jens Wiklander
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Wiklander @ 2023-06-15 12:57 UTC (permalink / raw)
  To: Sumit Garg; +Cc: Jiapeng Chong, op-tee, linux-kernel, Abaci Robot

On Tue, Jun 13, 2023 at 10:42 AM Sumit Garg <sumit.garg@linaro.org> wrote:
>
> On Tue, 13 Jun 2023 at 06:49, Jiapeng Chong
> <jiapeng.chong@linux.alibaba.com> wrote:
> >
> > Use kmemdup rather than duplicating its implementation.
> >
> > ./drivers/tee/optee/smc_abi.c:1542:12-19: WARNING opportunity for kmemdup.
> >
> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5480
> > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> > ---
> > Changes in v2:
> >   -Add one commit message.
> >
> >  drivers/tee/optee/smc_abi.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
>
> Reviewed-by: Sumit Garg <sumit.garg@linaro.org>

I'm picking up this.

Thanks,
Jens

>
> -Sumit
>
> > diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
> > index 3861ae06d902..d5b28fd35d66 100644
> > --- a/drivers/tee/optee/smc_abi.c
> > +++ b/drivers/tee/optee/smc_abi.c
> > @@ -1541,12 +1541,11 @@ static int optee_load_fw(struct platform_device *pdev,
> >          * This uses the GFP_DMA flag to ensure we are allocated memory in the
> >          * 32-bit space since TF-A cannot map memory beyond the 32-bit boundary.
> >          */
> > -       data_buf = kmalloc(fw->size, GFP_KERNEL | GFP_DMA);
> > +       data_buf = kmemdup(fw->data, fw->size, GFP_KERNEL | GFP_DMA);
> >         if (!data_buf) {
> >                 rc = -ENOMEM;
> >                 goto fw_err;
> >         }
> > -       memcpy(data_buf, fw->data, fw->size);
> >         data_pa = virt_to_phys(data_buf);
> >         reg_pair_from_64(&data_pa_high, &data_pa_low, data_pa);
> >         reg_pair_from_64(&data_size_high, &data_size_low, data_size);
> > --
> > 2.20.1.7.g153144c
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-15 12:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-13  1:18 [PATCH v2] tee: optee: Use kmemdup() to replace kmalloc + memcpy Jiapeng Chong
2023-06-13  8:42 ` Sumit Garg
2023-06-15 12:57   ` Jens Wiklander

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.